Generate covariance matrix from correlation matrix

前端 未结 4 1575
孤独总比滥情好
孤独总比滥情好 2021-02-05 20:36

I have a correlation matrix:

a <- matrix(c(1, .8, .8, .8, 1, .8, .8, .8, 1), 3)

##      [,1] [,2] [,3]
## [1,]  1.0  0.8  0.8
## [2,]  0.8  1.0  0.8
## [3,]          


        
4条回答
  •  情书的邮戳
    2021-02-05 21:17

    The answer marked as correct is wrong.

    The correct solution seems to be the one provided by MBESS package, so see the post from dayne.

    > a
         [,1] [,2] [,3]
    [1,]  1.0  0.8  0.8
    [2,]  0.8  1.0  0.8
    [3,]  0.8  0.8  1.0
    > b <- c(3,10,3)
    > b %*% t(b)
         [,1] [,2] [,3]
    [1,]    9   30    9
    [2,]   30  100   30
    [3,]    9   30    9
    > c <- b %*% t(b)
    > c %*% a
          [,1]  [,2]  [,3]
    [1,]  40.2  44.4  40.2
    [2,] 134.0 148.0 134.0
    [3,]  40.2  44.4  40.2
    > cor2cov(cor.mat=a, b )
         [,1] [,2] [,3]
    [1,]  9.0   24  7.2
    [2,] 24.0  100 24.0
    [3,]  7.2   24  9.0
    > a %*% c
         [,1] [,2] [,3]
    [1,] 40.2  134 40.2
    [2,] 44.4  148 44.4
    [3,] 40.2  134 40.2
    > 
    

提交回复
热议问题