[英]Can I generate bivariate normal random variables with correlation 1 using Cholesky factorization?
是否可以使用cholesky分解技術將correlation = 1
設置為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
有任何想法嗎?
實際上,可以通過使用透視 Cholesky分解來實現。
correlationMAT<- matrix(1,nrow = 2,ncol = 2)
U <- chol(correlationMAT, pivot = TRUE)
#Warning message:
#In chol.default(correlationMAT, pivot = TRUE) :
# the matrix is either rank-deficient or indefinite
U
# [,1] [,2]
#[1,] 1 1
#[2,] 0 0
#attr(,"pivot")
#[1] 1 2
#attr(,"rank")
#[1] 1
注意, U
具有相同的列。 如果執行MAT %*% U
,則將MAT[, 1]
復制兩次,這意味着第二個隨機變量將與第一個隨機變量相同。
newMAT<- MAT %*% U
cor(newMAT)
# [,1] [,2]
#[1,] 1 1
#[2,] 1 1
您不必擔心兩個隨機變量是相同的。 請記住,這僅表示標准化后它們是相同的(到N(0, 1)
)。 您可以通過不同的標准偏差來重新縮放它們,然后以不同的均值來移動它們以使其與眾不同。
樞軸式Cholesky分解非常有用。 我對這篇文章的回答: 通過Pivoted Cholesky因子分解生成具有秩不足協方差的多元正態rv可以提供更全面的信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.