mCorrCov {stats4teaching} | R Documentation |
Correlation & Covariance matrices.
Description
Given a correlation matrix and vector of standard deviations (or vector of means and vector of variation coefficients) returns a covariance matrix.
Usage
mCorrCov(mcorr, sigma = 1, mu = NULL, coefvar = NULL)
Arguments
mcorr |
a (non-empty) numeric correlation matrix. |
sigma |
an optional vector of standard deviations. |
mu |
an optional vector of means. |
coefvar |
an optional vector of coefficients of variation. |
Details
coefvar
= sigma
/mu
.
If sigma
, mu
or coefvar
are not specified, it´s assumed that default values for standard error's are 1. Length of standard error's is created using number of rows of correlation matrix.
It's necessary to provide sigma
or mu
and coefvar
(both) in order to obtain a desired covariance matrix.
Length of vectors is taken using rep
. Pay attention if vectors don't have same length!
Value
mCorrCov
gives the covariance matrix for a specified correlation matrix.
Examples
A <- matrix(c(1,2,2,1), nrow = 2, byrow = TRUE)
mCorrCov(A)
B <- matrix(c(1,0.8,0.7,0.8,1,0.55,0.7,0.55,1), nrow = 3, byrow = TRUE)
mCorrCov(B,mu = c(2,3.5,1), coefvar = c(0.3,0.5,0.7))