rmvnorm {spam}R Documentation

Draw Multivariate Normals

Description

Fast ways to draw multivariate normals when the variance or precision matrix is sparse.

Usage

rmvnorm.spam(n,mu=rep(0, nrow(Sigma)), Sigma,...) 
rmvnorm.prec(n,mu=rep(0, nrow(Q)), Q, ...) 
rmvnorm.canonical(n, b, Q, ...) 

Arguments

n number of observations.
mu mean vector.
Sigma covariance matrix of class spam.
Q precision matrix.
b vector determining the mean.
... arguments passed to chol.

Note

There is intentionally no S3 distinction between the classes spam and spam.chol.method.

Author(s)

Reinhard Furrer, based on Ng and Peyton (1993) Fortran routines

References

See references in chol.

See Also

chol and ordering.

Examples

# Generate multivariate form a covariance inverse:
# (usefull for GRMF)
set.seed(13)
n <- 25    # dimension
N <- 1000  # sample size
Sigmainv <- .25^abs(outer(1:n,1:n,"-"))
Sigmainv <- as.spam( Sigmainv, eps=1e-4)

Sigma <- solve( Sigmainv)  # for verification 
iidsample <- array(rnorm(N*n),c(n,N))

mvsample <- backsolve( chol(Sigmainv), iidsample)
norm( var(t(mvsample)) - Sigma, type="HS")

# compare with:
mvsample <- backsolve( chol(as.matrix( Sigmainv)), iidsample)
norm( var(t(mvsample)) - Sigma, type="HS")


# 'solve' step by step:
b <- rnorm( n)
R <- chol(Sigmainv)
norm( backsolve( R, forwardsolve( R, b))-
      solve( Sigmainv, b),type="HS") 
norm( backsolve( R, forwardsolve( R, diag(n)))- Sigma,type="HS") 


[Package spam version 0.15-5 Index]