[R] Converting variance covariance matrix to correlation matrix

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Mon May 19 09:07:00 CEST 2008


check the following:

# covariance matrix
V <- var(matrix(rnorm(10*4), 10, 4))
cov2cor(V)

# correlation matrix
R <- cov2cor(V)
# vector of std. dev.
sds <- rnorm(4)^2
R * sds * rep(sds, each = nrow(R))


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Arun Kumar Saha" <arun.kumar.saha at gmail.com>
To: "r-help at stat.math.ethz.ch" <R-help at stat.math.ethz.ch>
Sent: Monday, May 19, 2008 8:32 AM
Subject: [R] Converting variance covariance matrix to correlation 
matrix


> Suppose I have a Variance-covariance matrix A. Is there any fast way 
> to
> calculate correlation matrix from 'A' and vice-versa without 
> emplying any
> 'for' loop?
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm



More information about the R-help mailing list