rmvn {mgcv}R Documentation

Generate multivariate normal deviates

Description

Generates multivariate normal random deviates.

Usage

rmvn(n,mu,V)

Arguments

n

number of simulated vectors required.

mu

the mean of the vectors: either a single vector of length p=ncol(V) or an n by p matrix.

V

A positive semi definite covariance matrix.

Details

Uses a ‘square root’ of V to transform standard normal deviates to multivariate normal with the correct covariance matrix.

Value

An n row matrix, with each row being a draw from a multivariate normal density with covariance matrix V and mean vector mu. Alternatively each row may have a different mean vector if mu is a vector.

Author(s)

Simon N. Wood simon.wood@r-project.org

See Also

ldTweedie, Tweedie

Examples

library(mgcv)
V <- matrix(c(2,1,1,2),2,2) 
mu <- c(1,3)
n <- 1000
z <- rmvn(n,mu,V)
crossprod(sweep(z,2,colMeans(z)))/n ## observed covariance matrix
colMeans(z) ## observed mu 

[Package mgcv version 1.8-28 Index]