HI,
library(MBESS)
Cor.mat <- matrix(c(1,0.5,0.5,1),nrow=2)
?Sd<- c(0.07,0.05)
?Covmat<-cor2cov(Cor.mat,Sd)
?Covmat
#??????? [,1]??? [,2]
#[1,] 0.00490 0.00175
#[2,] 0.00175 0.00250
cov2cor(Covmat)
#???? [,1] [,2]
#[1,]? 1.0? 0.5
#[2,]? 0.5? 1.0
Cor.mat2<-matrix(c(1,0.2,0.8,0.2,1,0.6,0.8,0.6,1),nrow=3)
?Sd2<- c(0.7,0.5,0.3)
?Covmat2<- cor2cov(Cor.mat2,Sd2)
?Covmat2
?# ?? [,1] [,2]? [,3]
#[1,] 0.490 0.07 0.168
#[2,] 0.070 0.25 0.090
#[3,] 0.168 0.09 0.090
?cov2cor(Covmat2)
#???? [,1] [,2] [,3]
#[1,]? 1.0? 0.2? 0.8
#[2,]? 0.2? 1.0? 0.6
#[3,]? 0.8? 0.6? 1.0
?identical(Cor.mat2,cov2cor(Covmat2))
#[1] TRUE
A.K.
>Hello,
>I am totally new to R.
>I am trying to convert a corr. matrix to a covar. one but keep getting the
same error.
>> Cor.mat <- matrix(c(1,0.5,0.5,1),nrow=2)
>> Sd <- matrix(c(0.07,0.05),nrow=1,ncol=2)
>> cor2cov(Cor.mat,Sd)
>Error in diag(sd) %*% cor.mat : non-conformable arguments
>
>I?ve tried all possible combinations for st.dev vector Sd
(nrow=1,ncol=2;nrow=2,ncol=1) but to no avail.
>Your help will be very appreciated.
>
>Regards,
>Artur