1

I have a correlation table with both positively and negatively correlated values:

cor.table <- matrix(rep(c(-0.1, 0.1), each=1250),50,50)
diag(cor.table) <- 1

I would like to create a covariance matrix from this using:

cov.mat<-cor2cov(cor.table,c(rep(20,50)))

However I get the following error:

Error in cor2cov(cor.table, c(rep(100, 50))) : 
  The object 'cor.mat' should be either a symmetric or a triangular matrix

How can I create a symmetric correlation matrix where values are either positively (0.1) or negatively (-0.1) correlated?

4

1 回答 1

0
set.seed(1)
cor.table <- matrix(sample(c(0.1,-0.1),50^2,replace=TRUE),50,50)

> isSymmetric(cor.table)
[1] FALSE

ind <- lower.tri(cor.table)
cor.table[ind] <- t(cor.table)[ind]
diag(cor.table) <- 1

> isSymmetric(cor.table)
[1] TRUE

您的问题是您没有创建对称矩阵。它现在应该可以工作了。

于 2013-09-12T12:21:20.887 回答