【发布时间】:2014-10-14 16:15:17
【问题描述】:
是否可以使用 cholesky 分解技术设置correlation = 1?
set.seed(88)
mu<- 0
sigma<-1
x<-rnorm(10000, mu, sigma)
y<-rnorm(10000, mu, sigma)
MAT<-cbind(x,y)
cor(MAT[,1],MAT[,2])
#this doesn't work because 1 makes it NOT positive-definite. any number 0 to .99 works
correlationMAT<- matrix(1,nrow = 2,ncol = 2)
U<-chol(correlationMAT)
newMAT<- MAT %*% U
cor(newMAT[,1], newMAT[,2]) #.....but I want to make this cor = 1
有什么想法吗?
【问题讨论】:
-
如果你想用
cor1 创建变量,这很容易...x <- rnorm(10000),y <- constant * x其中constant是你想要的大于0的任何东西。但是如果有噪音,则相关性将小于 1。 -
@Gregor - 但我想转换为使用 chol 或类似的东西。
-
@user3022875 为什么重要的是你怎么做的? 1是一个病态的案例,但它是一个微不足道的案例。
-
如果你想使用矩阵乘法,你可以使用
MAT %*% M其中M <- matrix(c(1, 0, constant, 0), 2),constant> 0。但是,再一次,@ 的第二列是什么并不重要987654330@ 是...如果您的答案取决于第二列,则相关性不会为 1。
标签: r