rmatrixt: Matrix t sampler

Description Usage Arguments Value Note Examples

View source: R/student.R

Description

Samples the matrix t-distribution.

Usage

1
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 nrow(M)

V

rows covariance matrix, a positive semidefinite matrix of order equal to ncol(M)

checkSymmetry

logical, whether to check the symmetry of U and V

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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]

stla/matrixsampling documentation built on Aug. 27, 2019, 3:03 a.m.