View source: R/rmvnorm_eclairs.R
rmvnorm_eclairs | R Documentation |
Draw from multivariate normal and t distributions using eclairs decomposition
rmvnorm_eclairs(n, mu, ecl, v = Inf, seed = NULL)
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 |
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)
.
matrix where rows are samples from multivariate normal or t distribution where columns have covariance specified by ecl
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))
# compare covariance to the covariance matrix used to simulated the data
range(cov(X.draw1) - getCov(ecl))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.