【问题标题】:Can I use a covariance matrix to specify the correlation structure in the nlme function gls?我可以使用协方差矩阵来指定 nlme 函数 gls 中的相关结构吗?
【发布时间】:2018-03-24 14:10:26
【问题描述】:

我希望使用 R 包 nlme 中的函数 gls 来分析一组嵌套的空间样本,其中许多样本至少在某些空间坐标中重叠。我想使用 corStruct 或 pdMat 对象来解释响应变量(我在每个空间样本中测量的东西)的非独立性,但我对如何做到这一点感到困惑。

我已经生成了一个协方差矩阵,它应该对空间样本之间非独立性的所有信息进行编码。每行/列是一个不同的空间样本,对角线包含每个空间样本捕获的采样单元的总数,非对角线元素包含空间样本之间共享的采样单元的计数。

我认为我应该在指定相关结构时使用 nlme 函数 gls,可能使用 corSymm 或 pdMat 对象。但是我只看到了通过公式指定 gls 中的相关结构的示例。如何使用我创建的协方差矩阵?

【问题讨论】:

  • 如果您对数据建模的最佳方式有任何疑问,请联系Cross Validated。这似乎不是一个适合 Stack Overflow 的特定编程问题。
  • 我在问如何专门将协方差结构放入 nlme 函数 gls 中。我应该使用 corSymm 吗? pdMat?

标签: r regression nlme


【解决方案1】:

我发现你可以通过使用corSymm提供的一般相关结构来传递nlme函数gls一个正定相关矩阵。

# convert your variance covariance matrix into a correlation matrix
CM <- cov2cor(vcv_matrix)

# if your correlation matrix contains zeros, as mine did, you need to convert it to a positive-definite matrix that substitutes very small numbers for those zeros
CM <- nearPD(CM)$mat

# convert into a corStruct object using general correlation structure provided by corSymm
C <- corSymm(CM[lower.tri(CM)], fixed = T)

# correlation structure can now be included in a gls model
gls(y ~ x, correlation = C, method = "ML")

【讨论】:

  • FWIW 对于nearPD(),您需要担心的不是“包含零”,而是非正定性(例如,单位矩阵即使包含很多零也可以... )
猜你喜欢
  • 1970-01-01
  • 2019-04-15
  • 1970-01-01
  • 2020-07-04
  • 1970-01-01
  • 2019-04-10
  • 2016-05-26
  • 2017-02-12
  • 2022-01-07
相关资源
最近更新 更多