rmvnorm_eclairs: Draw from multivariate normal and t distributions

View source: R/rmvnorm_eclairs.R

rmvnorm_eclairsR Documentation

Draw from multivariate normal and t distributions

Description

Draw from multivariate normal and t distributions using eclairs decomposition

Usage

rmvnorm_eclairs(n, mu, ecl, v = Inf, seed = NULL)

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

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).

Value

matrix where rows are samples from multivariate normal or t distribution where columns have covariance specified by ecl

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))

# compare covariance to the covariance matrix used to simulated the data
range(cov(X.draw1) - getCov(ecl))


decorrelate documentation built on Aug. 8, 2025, 7:55 p.m.