scaleMatrix {CPTtools} | R Documentation |
Creates a correlation matrix from a covariance matrix by scaling rows and columns to have a unit diagonal. Also can be used to create a partial correlation matrix from an inverse covariance/correlation matrix.
scaleMatrix(X)
X |
A square, positive definite matrix (covariance matrix). |
Divides rows and columns by square root of the diagonal elements.
A matrix of the same size and shape as the original with a unit diagonal.
Russell Almond
data(MathGrades) ## Create a correlation matrix from a covariance matrix. round(scaleMatrix(MathGrades$var),2) == MathGrades$cor ## Create a partial correlation matrix from a correlation matrix round(scaleMatrix(solve(MathGrades$cor)),2) == MathGrades$pcor ##Note: Some of these tests may return false due to machine precision ##issues.