Re: [R] Converting variance covariance matrix to correlation matrix

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Mon, 19 May 2008 09:02:09 +0200

Arun Kumar Saha wrote:
> 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?
>

C <- cov2cor(A)

The other way around is ill-defined, but if d is the vector of variances,

d <- sqrt(diag(A))
A <- outer(d, d)*C.

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)              FAX: (+45) 35327907

______________________________________________
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.
Received on Mon 19 May 2008 - 07:07:04 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 19 May 2008 - 09:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive