就像这篇文章的标题所说,当我尝试使用BRugsFit
(带有coda=T
)从R运行在WinBUGS中运行良好的代码和数据时,出现以下错误:
Error in glm.fit(x = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, :
NA/NaN/Inf in foreign function call (arg 1)
In addition: Warning messages:
1: glm.fit: algorithm did not converge
2: glm.fit: algorithm did not converge
3: glm.fit: algorithm did not converge
4: glm.fit: algorithm did not converge
5: step size truncated due to divergence
在尾声对象上执行
tail()
时,我会一遍又一遍地得到相同的数字。另一方面,当我运行WinBUGS时,保存尾声并将其加载到R中,我会得到一些随机变化,就像我期望的那样,并且没有关于收敛的警告。这是我的模型(它使用“一个把戏”来查找Logistic-Makeham分布的参数的后验者)。
model {
for(i in 1:n){
ones[i]<-1;
# here I pre-calculate two quantities that occur several times
# in the PDF, to save a little processing time
expbx[i] <- exp(b*x[i]); expbx1[i]<- 1/(1+sd*(expbx[i]-1));
# below is the actual PDF
p[i]<-(c+a*expbx[i]*expbx1[i])*exp(-c*x[i])*pow(expbx1[i],1/s);
# the ones trick
ones[i]~dbern(p[i]);
}
b~dunif(0,1); d~dexp(1); c~dexp(1); s.raw~dflat();
# a (lambda) parametrized this way because it comes out more accurate
# s forced to be > 0
a<-b*d; s<-abs(s.raw);
# NOT a standard deviation, just s times d, to save processing time
sd<-s*d;
# I save all the parameters I'm interested in to one vector, for convenient
# viewing of them all in the same window.
out[1]<-a; out[2]<-b; out[3]<-c; out[4]<-s; out[5]<-d;
}
这是我的数据的典型示例:
list(n= 148 ,x=c( 1246,1175,1048,1169,1043,802,543,719,1296,817,1122,542,839,443,1536,700,834,232,596,1096,1118,957,974,1031,1149,1044,1108,
519,677,569,952,1243,970,1736,1262,1026,979,1543,1029,761,533,540,511,1150,1589,1169,1029,1248,1572,638,731,525,968,1467,1596,1077,712,1603,1
203,991,37,1775,893,993,913,1487,1186,1381,977,1247,857,786,615,733,1206,1059,1508,569,1205,754,886,1099,843,599,780,1294,1603,1242,883,1320,
507,1097,1193,218,1362,1181,1118,453,1291,972,787,1061,1097,1100,1117,1174,596,1305,1071,940,919,999,1209,1043,1161,1016,1025,750,423,732,
1389,907,1184,1275,944,1209,1073,1098,1348,976,817,557,211,961,880,1039,1287,736,1400,1757,1355,977,198,689,853,1251,767,768 ))
...和典型的初始化(我使用4条链,细化20条,burnin 2000,20000次迭代)
list( d=0.001738,b=0.0009672,c=0.002451,s.raw=0.001511 )
list( d=0.006217,b=0.005596,c=0.00777,s.raw=0.007019 )
list( d=1.504E-05,b=4.825E-06,c=2.172E-07,s.raw=6.104E-05 )
list( d=0.3011,b=0.03552,c=0.1274,s.raw=0.2549 )
OpenBUGS会简单地舍入到比WinBUGS少的有效位数吗?如果是的话,也许我可以更改设置以使其停止这样做?
最佳答案
我对此的初步答案似乎是...
将format
和bugsInits()
命令的bugsData()
参数设置为fg
。
对先验分布进行参数化,以使如果参数很小(对数刻度为负两位),则将进行倒数(或其他适当的变换)采样。
仅使用较大的间隔间隔(在我的情况下为80)和大量迭代。 OpenBUGS当前不支持过度松弛,仅此而已。
如果某些变量是分类变量,请勿尝试将它们包括在与连续变量相同的摘要中。
对于建议关闭过度松弛的响应者:问题是我无法开启它,而没有它,迭代将永远持续下去。但这似乎是目前唯一的选择。我希望WinBUGS手册对使用此功能的含义有更具体的说明。哦,我想我最终需要阅读他们引用的论文。但是,由于OpenBUGS中甚至不提供此功能,因此目前尚不明确。
如果有人比我能提供的更好或更详细的答案,我将让我的问题待一会儿。