[R] Converting variance covariance matrix to correlation matrix
Peter Dalgaard
P.Dalgaard at biostat.ku.dk
Mon May 19 10:22:21 CEST 2008
Peter Dalgaard wrote:
> 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,
Doh. Edited code, but not text... Vector of standard deviations, of course.
>
> 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
More information about the R-help
mailing list