# r2cov: Convert correlation matrix into covariance matrix In rpsychi: Statistics for psychiatric research

## Description

`r2cov` converts correlation matrix and sample/unbiased standard deviation into sample/unbiased covariance matrix.

## Usage

 `1` ``` r2cov(sd, R) ```

## Arguments

 `sd` a numeric vector contains the sample/unbiased standard deviations `R` a matrix or data frame contains the correlation matrix

## Details

This function converts correlation matrix and sample/unbiased standard deviation into sample/unbiased covariance matrix using the following equation: S = D^{1/2} R D^{1/2}, where S is a sample/unbiased covariance matrix, R is a correlation matrix, and D^{1/2} is a square matrix with `sd` on the main diagonal and 0's elsewhere. The length of `sd` should be equal to the number of rows and columns in `R`.

## Value

Return a matrix containing the sample/unbiased covariance matrix.

## Author(s)

Yasuyuki Okumura
Department of Social Psychiatry,
National Institute of Mental Health,
National Center of Neurology and Psychiatry
yokumura@blue.zero.jp

## References

Toyoda H (1998) Introduction to structural equation modeling (in Japanese) Tokyo: Asakura Publishing.

`svar`, `ssd`, `svar`, `ssd2sd`, `lower2R`
 ``` 1 2 3 4 5 6 7 8 9 10``` ``` ##data(iris) x <- iris[,1:4] cov(x) r2cov(apply(x, 2, sd), cor(x)) ##Toyoda (1998) p.34 r2cov(sd = sqrt(c(.862, 1.089, 0.606)), R = lower2R(c(.505, -0.077, -.233))) ```