rmatrixt {matrixsampling} | R Documentation |
Matrix t sampler
Description
Samples the matrix t-distribution.
Usage
rmatrixt(n, nu, M, U, V, checkSymmetry = TRUE, keep = TRUE)
Arguments
n |
sample size, a positive integer |
nu |
degrees of freedom, a positive number |
M |
mean matrix, without constraints |
U |
columns covariance matrix, a positive semidefinite matrix of order equal
to |
V |
rows covariance matrix, a positive semidefinite matrix of order equal
to |
checkSymmetry |
logical, whether to check the symmetry of |
keep |
logical, whether to return an array with class keep |
Value
A numeric three-dimensional array; simulations are stacked along the third dimension (see example).
Note
When p=1
and V=nu
or when m=1
and U=nu
, the
distribution is the multivariate t-distribution.
Examples
nu <- 4
m <- 2
p <- 3
M <- matrix(1, m, p)
U <- toeplitz(m:1)
V <- toeplitz(p:1)
Tsims <- rmatrixt(10000, nu, M, U, V)
dim(Tsims) # 2 3 10000
apply(Tsims, 1:2, mean) # approximates M
vecTsims <- t(apply(Tsims, 3, function(X) c(t(X))))
round(cov(vecTsims), 1) # approximates 1/(nu-2) * kronecker(U,V)
## the `keep` class is nice when m=1 or p=1:
Tsims <- rmatrixt(2, nu, M=1:3, U=diag(3), V=1)
Tsims[,,1] # dimensions 3 1
# without `keep`, dimensions are lost:
rmatrixt(2, nu, M=1:3, U=diag(3), V=1, keep=FALSE)[,,1]
[Package matrixsampling version 2.0.0 Index]