simCorrVars: [+] Simulate correlated continuous data from standard normal...

Description Usage Arguments Details Value Author(s) Source See Also Examples

View source: R/simCorrVars.R

Description

Simulate correlated continuaous data from standard normal distribution by using Choleski factorization of correlation matrix.

Usage

1
simCorrVars(corrMat, N = 100)

Arguments

corrMat

A symmetricmatrix of correlation coefficients. Determinant of corrMat must be positive. If corrMat is a vector, it is passed to function corr_vec2mat to construct a correlation matrix.
Default corrMat = corr_vec2mat(c(.8,.2,.7)).

N

A number of observations. Default is 100.

Details

Number of variables is determined by the size of correlation matrix corrMat.

Value

A dataframe with correlated variables.

Author(s)

Vilmantas Gegzna

Source

http://www.r-bloggers.com/simulating-random-multivariate-correlated-data-continuous-variables/

See Also

corr_vec2mat, mvrnorm, chol

Other simmulation functions in spMisc: corr_vec2mat()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# ------------------------------------------------------------
simCorrVars()
simCorrVars(N = 10)

# ------------------------------------------------------------
# Generate 2 correlated variables with 10 observations:
# A. Imput is a matrix

corrMat <- matrix(c(1, .5, .5, 1), 2)
print(corrMat)
simCorrVars(corrMat, N = 10)

# B. Imput is a vector
simCorrVars(.5, N = 10)
simCorrVars(c(.1,.5,.8), N = 10)

# ------------------------------------------------------------

GegznaV/spMisc documentation built on April 26, 2020, 5:59 p.m.