Learn R Programming

metaSEM (version 2.0)

rCor: Generate (Nested) Sample/Population Correlation/Covariance Matrices

Description

Variable names and data column names must not contain periods. Rename them consistently, for example x.1 to x_1, and check that the new names are unique. Study, group, and cluster values may contain periods.

It generates (nested) random sample or population correlation or covariance matrices. rCor() is a wrapper to call rCorPop() and then rCorSam().

Usage

rCor(
  Sigma,
  V,
  n,
  corr = TRUE,
  raw.data = FALSE,
  nonPD.pop = c("replace", "nearPD", "accept"),
  nonPD.sam = c("stop", "nearPD")
)

rCorPop(Sigma, V, k, corr = TRUE, nonPD.pop = c("replace", "nearPD", "accept"))

rCorSam( Sigma, n, corr = TRUE, raw.data = FALSE, nonPD.sam = c("stop", "nearPD") )

rCor3L( Sigma, V.B, V.W, n, cluster, corr = TRUE, raw.data = FALSE, nonPD.pop = c("replace", "nearPD", "accept"), nonPD.sam = c("stop", "nearPD") )

Value

An object of the generated population/sample correlation/covariance matrices.

Arguments

Sigma

A list of population correlation/covariance matrices or a single matrix

V

A variance-covariance matrix of Sigma.

n

A vector or a single sample sizes. For rCorSam(), Sigma and n must have equal lengths, or either may have length one and be reused for each element of the other.

corr

Logical. Whether to generate correlation or covariance matrices.

raw.data

Logical. Whether correlation/covariance matrices are generated via raw.data or directly from a Wishart distribution.

nonPD.pop

If it is replace, generated non-positive definite matrices are replaced by generated new ones which are positive definite. If it is nearPD, they are replaced by nearly positive definite matrices by calling Matrix::nearPD(). If it is accept, they are accepted.

nonPD.sam

If it is stop, the program stops when the inputs in the rCorSam are non-positive definite. If it is nearPD, they are replaced by nearly positive definite matrices by calling Matrix::nearPD().

k

A vector or a single number of studies.

V.B

A variance-covariance matrix of between-study Sigma.

V.W

A variance-covariance matrix of within-study Sigma

cluster

A vector of number of studies in clusters.

Author

Mike W.-L. Cheung <[email protected]>

Examples

Run this code

Sigma <- matrix(c(1, .2, .3,
                  .2, 1, .4,
                  .3, .4, 1), ncol=3, nrow=3)
V <- diag(c(.1, .1, .1))

## Generate two population correlation matrices
Pop.corr <- rCorPop(Sigma, V, k=2)
Pop.corr
                  
summary(Pop.corr)
                  
## Generate two sample correlation matrices
rCorSam(Sigma=Pop.corr, n=c(10, 10))
                 
## The above code is the same as the following one
rCor(Sigma, V, n=c(10, 10))                  

Run the code above in your browser using DataLab