# rCor: Generate Sample/Population Correlation/Covariance Matrices In metaSEM: Meta-Analysis using Structural Equation Modeling

## Description

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

## Usage

 ```1 2 3 4 5 6 7``` ```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")) ```

## 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. `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.

## Value

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

## Author(s)

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

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16``` ```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)) ```

metaSEM documentation built on Oct. 18, 2018, 9:03 a.m.