Draw from multivariate normal and t distributions using eclairs decomposition
Arguments
- n
sample size
- mu
mean vector
- ecl
covariance matrix as an eclairs object
- v
degrees of freedom, defaults to Inf. If finite, uses a multivariate t distribution
- seed
If you want the same to be generated again use a seed for the generator, an integer number
Value
matrix where rows are samples from multivariate normal or t distribution where columns have covariance specified by ecl
Details
Draw from multivariate normal and t distributions using eclairs decomposition. If the (implied) covariance matrix is \(p \times p\), the standard approach is \(O(p^3)\). Taking advantage of the previously computed eclairs decomposition of rank \(k\), this can be done in \(O(pk^2)\).
Examples
library(Rfast)
n <- 800 # number of samples
p <- 200 # number of features
# create correlation matrix
Sigma <- autocorr.mat(p, .9)
# draw data from correlation matrix Sigma
Y <- rmvnorm(n, rep(0, p), sigma = Sigma, seed = 1)
# perform eclairs decomposition
ecl <- eclairs(Y)
# draw from multivariate normal
n <- 10000
mu <- rep(0, ncol(Y))
# using eclairs decomposition
X.draw1 <- rmvnorm_eclairs(n, mu, ecl)
# using full covariance matrix implied by eclairs model
X.draw2 <- rmvnorm(n, mu, getCov(ecl))
# assess difference betweeen covariances from two methods
range(cov(X.draw1) - cov(X.draw2))
#> [1] -0.07761519 0.08804192
# compare covariance to the covariance matrix used to simulated the data
range(cov(X.draw1) - getCov(ecl))
#> [1] -0.05744341 0.06452279