根据R中的特定相关矩阵从多元正态分布中得出数据

发布于 2025-02-07 08:49:51 字数 560 浏览 2 评论 0原文

我从多元正态分布中得出数据。我创建了Sigma矩阵所需的相关结构。由于我以标准偏差为1,因此我希望Sigma矩阵和Z矩阵的相关性是相同的,但不是相同的。如何解决这个问题?那么,如何根据我想要的相关矩阵从多元正态分布中得出数据?

  blck1 <- c(1:8)
  blck2 <- c(9:20)
  pr <- seq(0.05, 0.01, length.out = 20)
  Sigma <- toeplitz(pr)

  #### Blok1 ###############
  pr_blck1 <- seq(0.7, 0.3, length.out = length(blck1))
  Sigma_blck1 <- toeplitz(pr_blck1)
  Sigma[blck1, blck1] <-  Sigma_blck1
  diag(Sigma) <- 1
  
 Z <- rmvnorm(n= 50, 
               mean  = rep(0, 20), 
               sigma = Sigma )
 
Sigma
cor(Z)

I derive data from a multivariate normal distribution. I created the correlation structure I wanted by the sigma matrix. Since I take the standard deviation as 1, I expect the Sigma matrix and correlation of Z matrix to be the same, but it is not the same. how do i solve this problem? So, how can I derive data from the multivariate normal distribution according to the correlation matrix I want?

  blck1 <- c(1:8)
  blck2 <- c(9:20)
  pr <- seq(0.05, 0.01, length.out = 20)
  Sigma <- toeplitz(pr)

  #### Blok1 ###############
  pr_blck1 <- seq(0.7, 0.3, length.out = length(blck1))
  Sigma_blck1 <- toeplitz(pr_blck1)
  Sigma[blck1, blck1] <-  Sigma_blck1
  diag(Sigma) <- 1
  
 Z <- rmvnorm(n= 50, 
               mean  = rep(0, 20), 
               sigma = Sigma )
 
Sigma
cor(Z)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文