rmv: Multivariate random number generation

Description Usage Arguments Details Value Examples

View source: R/rmv.R

Description

Generates correlated random variables by the matrix square-root method.

Usage

1
rmv(n, covmat, rfunc = rnorm, method = c("chol", "eigen"), ...)

Arguments

n

Number of random multivariate draws.

covmat

The covariance matrix with which to obtain correlations.

rfunc

Function that returns a vector of random draws from a particular distribution. The first argument of rfunc must give the number of random draws to make.

method

The method for taking the matrix square-root. Currently only 'chol' and 'eigen' are allowed for the Cholesky and eigen decomposition methods. See msr.

...

Further arguments to pass to rfunc.

Details

The number, m, of variables generated per each of the n observations is equal to the number of rows (or columns) of covmat. rfunc is used to fill an n by m matrix of uncorrelated observations. This matrix is multiplied by the matrix square-root (msr) to obtain a matrix of m correlated random variables.

Value

A matrix with rows giving observations and columns giving correlated variables.

Examples

1
2
3
4
5
set.seed(1)
cm <- cor(matrix(rnorm(12), 6, 2))
x <- rmv(100, cm, rbinom, size = 100, prob = 0.7)
pairs(x)
cm

rmv documentation built on May 31, 2017, 5:05 a.m.

Related to rmv in rmv...