rStudent: Random Number Generator for the Multivariate Student t...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/student.R

Description

Generate vectors of random variates from the multivariate Student t distribution.

Usage

1
rStudent(n, df, loc = rep(0, d), scale, factor = factorize(scale))

Arguments

n

sample size n (positive integer).

loc

location vector of dimension d.

scale

covariance matrix of dimension (d, d).

df

degrees of freedom (positive real number or Inf in which case samples from the multivariate normal distribution with mean vector loc and covariance matrix scale are drawn).

factor

factorization matrix of the covariance matrix scale. A matrix R with d rows such that R^T R equals scale. R is internally multiplied from the right to an (n, d)-matrix of independent standard normals to obtain a sample from a multivariate normal with zero mean vector and covariance matrix scale.

Details

Internally used is factor, so scale is not required to be provided if factor is given.

The default factorization used to obtain factor is the Cholesky decomposition. To this end, scale needs to have full rank. See factorize() for other options.

The number of rows of factor are the dimension d of the sample. Typically (but not necessarily), factor is square.

Value

rStudent() returns an (n, d)-matrix containing n samples of the d-dimensional Student t distribution with df degrees of freedom, location vector loc and scale matrix scale (a covariance matrix).

Author(s)

Marius Hofert

References

McNeil, A. J., Frey, R., and Embrechts, P. (2015). Quantitative Risk Management: Concepts, Techniques, Tools. Princeton University Press.

See Also

dStudent(), pStudent(), factorize()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Generate a random correlation matrix in three dimensions
d <- 3
set.seed(271)
A <- matrix(runif(d * d), ncol = d)
P <- cov2cor(A %*% t(A))
## Draw random variates and compare
df <- 3.5
n <- 1000
set.seed(157)
X <- rStudent(n, df = df, scale = P) # providing scale
set.seed(157)
X. <- rStudent(n, df = df, factor = chol(P)) # providing directly the factor
stopifnot(all.equal(X, X.))

## Univariate case
set.seed(157)
X.1d <- rStudent(n, df = df, factor = 1/2)
set.seed(157)
X.1d. <- rStudent(n, df = df, factor = 1)/2 # manual scaling
stopifnot(all.equal(X.1d, X.1d.))

student documentation built on May 2, 2019, 6:48 p.m.