Hi R-users,
Â
I have this code below and use some code from sn package for multivariate
skew t (rmst) to generate a set of random numbers.  I try to do a looping to
produce ârandâ for different values of degrees of freedom (degf).Â
Actually, Iâm not sure how to specify the attribute for the rand. As we
know, rand will give us a set of results + all the parameters used, so just
wonder whether we can do the same for this iteration.
Â
rand_skewt <- function(dt,degf,n)
{ t1Â Â Â <- length(degf)
 rand <- matrix(dt,nrow=n)
 xi   <- colMeans(dt)
 Omega <- var(dt)
 alpha <- skew(dt,na.rm = TRUE)
 for (i in 1:t1)
{Â rand[i] <- rmst(n,xi, Omega, alpha, df=degf[i])[1:n,1:2] }
  rand
}
Â
dt <- yypos[1:10,]; degf <- c(4,4.5,5,6); n <- 5
> yypos[1:10,]
      [,1] [,2]
 [1,] 49.7 23.4
 [2,] 141.6 136.8
 [3,] 119.7 141.5
 [4,] 27.2 47.2
 [5,] 56.0 20.6
 [6,] 58.1 62.4
 [7,] 59.2 28.2
 [8,] 22.8 22.4
 [9,] 28.0 48.6
[10,]Â 69.9Â 85.2
Â
rand_skewt(dt,degf,n)
Â
this is the output I got, but I think something is incorrectâ¦By right every
rand will have n by 2 matrixâ¦I only have thisâ¦
Â
> rand_skewt(dt,degf,n)
         [,1] [,2] [,3] [,4]
[1,]Â 97.53849 58.1Â 23.4 62.4
[2,]Â 96.79773 59.2 136.8 28.2
[3,] 155.26630 22.8 141.5 22.4
[4,]Â 57.34792 28.0Â 47.2 48.6
[5,]Â 56.00000 69.9Â 20.6 85.2
Warning messages:
1: In rand[i] <- rmst(n, xi, Omega, alpha, df = degf[i])[1:n, 1:2] :
 number of items to replace is not a multiple of replacement length
2: In rand[i] <- rmst(n, xi, Omega, alpha, df = degf[i])[1:n, 1:2] :
 number of items to replace is not a multiple of replacement length
3: In rand[i] <- rmst(n, xi, Omega, alpha, df = degf[i])[1:n, 1:2] :
 number of items to replace is not a multiple of replacement length
4: In rand[i] <- rmst(n, xi, Omega, alpha, df = degf[i])[1:n, 1:2] :
 number of items to replace is not a multiple of replacement length
Â
Â
Thank you so much for any help given.
Â
Regards.
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.