These functions will create a multivariate t-distributed random matrix of a specified mean and covariance structure.
mvrt(n, mu, S, df = 1L) mvrt2(n, mu, S, df = 1L, max_norm = 2, max_iterations = 1000L)
n | Number of observations. |
---|---|
mu | Vector of sample means. |
S | Covariance matrix. |
df | Degrees of freedom. |
max_norm | Maximum matrix norm in difference between target correlation matrix and the correlation matrix resulting from randomly generated data. The greatest possible norm is 2. Use care with extemely small values, as several iterations may be required to obtain such a matrix. |
max_iterations | Maximum number of iterations for the loop to search
for a matrix meeting |
The mvrt2
fuction differs from mvrt
in that it will ensure that the
resulting random data has a correlation matrix within a specified criterion.
No element of the resulting correlation matrix will deviate from the
corresponding element of the correlation matrix generated from
specifications by more than the absolute value of max_norm
. This
checking comes at the expense of computational speed.
S <- convert_R2S(make_cor_mat(.9),2:3) x <- mvrt( 30, 4:5, S, 29) y <- mvrt2(30, 4:5, S, 29, .01) cor(x)#> [,1] [,2] #> [1,] 1.0000000 0.8827111 #> [2,] 0.8827111 1.0000000cor(y)#> [,1] [,2] #> [1,] 1.0000000 0.8963103 #> [2,] 0.8963103 1.0000000