Generate covariance matrix from correlation matrix

前端 未结 4 1577
孤独总比滥情好
孤独总比滥情好 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:22

    If you know the standard deviations of your individual variables, you can:

    stdevs <- c(e1.sd, e2.sd, e3.sd)
    #stdevs is the vector that contains the standard deviations of your variables
    b <- stdevs %*% t(stdevs)  
    # b is an n*n matrix whose generic term is stdev[i]*stdev[j] (n is your number of variables)
    a_covariance <- b * a  #your covariance matrix
    

    On the other hand, if you don't know the standard deviations, it's impossible.

提交回复
热议问题