用于偏移模型的 SpBayes

SpBayes for an offset model

我正在 运行宁 spBayes 以适应 'offset' 模型 y ~ 1。

我有一个这样的数据框

    ID   lon   lat      y
1   A  90.0  5.9  0.957096100
2   A  90.5  6.0  0.991374969
3   A  91.1  6.0  0.991374969
4   A  92.7  6.1  0.913501740
5   A  94.0  6.1  0.896575928
6   A  97.8  5.2  0.631320953
7   A  98.9  4.4 -0.282432556
8   A 101.2  2.8  1.829053879
9   A 102.3  2.0  0.993621826
10  A 105.8  0.5  0.038677216

其中变量 ID 是具有两个级别 A 和 B 的因子。我想为这两个 ID 找到一个偏移量。然而,当我 运行

fit.by.ALL <- spLM(formula=y ~ ID, data= df, coords=coords, 
               priors=priors, tuning=tuning, starting=starting,
               cov.model = "exponential", n.samples = n.samples, verbose = TRUE, 
               n.report = 50)

给出结果

Iterations = 1:251
Thinning interval = 1 
Number of chains = 1 
Sample size per chain = 251 

1. Empirical mean and standard deviation for each variable,
   plus standard error of the mean:

               Mean     SD Naive SE Time-series SE
(Intercept)  1.0736 2.8674  0.18099        0.18099
IDB          -0.9188 0.1922  0.01213        0.01213

2. Quantiles for each variable:

              2.5%    25%     50%     75%   97.5%
(Intercept) -4.952 -0.773  1.1059  3.0165  6.4824
IDB         -1.303 -1.048 -0.9284 -0.7679 -0.5795

不喜欢的结果非常稳定,因为每次我 运行 它都会不断变化。

此外,要找到 ID B 的最终偏移量,我需要将(截距)均值添加到 IDB 均值,它对 SD 有何作用?

对于两个 ID(用 y~1 而不是 y~ID)分别 运行 spLM 公式会更好吗?

谢谢

我不清楚你所说的 "fit an offset model y ~ 1" 是什么意思。当我读到这篇文章时,我认为你想要一个只有截距的模型,但进一步阅读它表明你想要一个可以估计两组均值的模型,这可以使用

y ~ 0+ID # manually remove the intercept,

回答您的问题:

the result doesn't like is very stable as it keep changing every time I run it.

您没有使用很多迭代。尝试 运行 次迭代。通过足够的迭代,结果应该是稳定的。

Moreover, to find the final offset for the ID B I need to add the (Intercept) Mean to the IDB Mean, how does it work for the SD?

同样,我不确定您所说的偏移量是什么意思,但是如果您的意思是您想要 A 组和 B 组之间的均值差异,这正是您在以 IDB 开头的行中所具有的内容。也就是说,-0.9188 是 B 组和 A 组之间均值的估计差异,即 B 组的均值估计比 B 组的均值小 0.9188,SD 是后验标准差。

如果您对 B 组的均值感兴趣,那么必须将(截距)添加到 IDB 是正确的,但不能简单地添加 SD。您在这里有两个选择:1)使用适当的设计矩阵(上面代码中的X)直接获得所需的参数估计值或 2)获得 MCMC 样本并计算(截距)和 IDB 参数的总和对于每次迭代,然后取这些总和的均值和标准差。

Would it be better to run the spLM formula separately for the two IDs (with y~1 instead of y~ID)?

如果您 运行 将它们分开,那么您将分别估计空间参数。如果两个不同组的空间参数不同,运行 它们分开很有意义。如果它们相同(或相似),那么将这两个组放在一起可能更有意义,这样您就可以 "borrowing information" 关于这两个组之间的空间参数。