楼主: Lisrelchen
2347 1

[本週專題]WinBUGS: Undefined Real Result? [推广有奖]

  • 0关注
  • 62粉丝

VIP

已卖:4194份资源

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
50288 个
通用积分
83.6906
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

楼主
Lisrelchen 发表于 2014-6-26 21:36:35 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
Attched please review my code for latent class model. Until I had done model check-up, there are no errors. However, when I tried to "update" the sample, suddenly the trap message said "undefined real result" popped up. How can I deal with this problem? Thanks
  1. model { # Marginal tabulations of Latent Diagnosis against Observed Items for (i in 1:n) { for (j in 1:K) { for (k in 1:2) {M1[j,k,i] <- equals(T[i],j)*equals(Y[i,1],k-1)}}} for (j in 1:K) {for (k in 1:2) {Tab1[j,k] <- sum(M1[j,k,1:n])}}

  2. for (i in 1:n) { for (j in 1:K) { for (k in 1:2) {M2[j,k,i] <- equals(T[i],j)*equals(Y[i,2],k-1)}}} for (j in 1:K) {for (k in 1:2) {Tab2[j,k] <- sum(M2[j,k,1:n])}}

  3. for (i in 1:n) { for (j in 1:K) { for (k in 1:2) {M3[j,k,i] <- equals(T[i],j)*equals(Y[i,3],k-1)}}} for (j in 1:K) {for (k in 1:2) {Tab3[j,k] <- sum(M3[j,k,1:n])}}

  4. Bernoulli sampling
  5. for (s in 1:n) {for (j in 1:M) {Y[s,j] ~ dbern(pi[T[s],j]) # new item data Z[s,j] ~ dbern(pi[T[s],j])} for (h in 1:2) { for (i in 1:2) { for (j in 1:2) { g[h,i,j,s] <- equals(Z[s,1]+1,h)*equals(Z[s,2]+1,i)*equals(Z[s,3]+1,j)}}}}

  6. Implied aggregate table (G.new)
  7. for (h in 1:2) { for (i in 1:2) { for (j in 1:2) {G[h,i,j] <- sum(g[h,i,j,])}}}

  8. for (k in 1:M) {for (j in 1:K) {logit(pi[j,k]) <- theta[j,k]}}

  9. Posterior memberships
  10. for (i in 1:n) { for (j in 1:K) {post[j,i] <- equals(T[i],j)}}

  11. Priors
  12. for (k in 1:M) {theta[1,k] ~ dnorm(0,0.1) I(,theta[2,k]) theta[2,k] ~ dnorm(0,0.1) I(theta[1,k],)} eta.s[1] ~ dgamma(w1,1) I(,eta.s[2]) eta.s[2] ~ dgamma(w1,1) I(eta.s[1],) for (j in 1:K) {eta[j] <- eta.s[j]/sum(eta.s[])} for (i in 1:n) {T[i] ~ dcat(eta[])}}

  13. B: Data list( n = 103, # number of patients observed K = 2, # number of latent classes M = 3 , # number of diagnostic tests w1 =1,

  14. observed item data
  15. Y=structure(.Data=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,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,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2, 1,2,1,2,1,2,1,2,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,1,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1),eta.s=c(0.427, 0.573),theta=structure(.Data=c(-2.5, -3.3, -2.7, 1.7, 1.4, 1.72),.Dim=c(2,3)),Z=structure(.Data=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,0,0,1,0,0,1,0,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1, 1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),.Dim=c(103,3)))
复制代码

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Undefined winbugs Defined DEFINE WINBUG undefined suddenly message against problem

沙发
Lisrelchen 发表于 2014-6-26 21:38:10
Error messages in WinBugs are terrible to interpret. I believe that this message is indicating that the program is unable to perform the calculations of the model due to illogical or extreme values selected by the sampler.

The first thing I would do is calculate values wherever you use a function. For example calculate the logit transformation by hand instead of using the logit function. I have fixed this exact error by making this change once.

Secondly, I would carefully go over your priors to make sure that they don't allow parameter values that could cause an error in calculation. For example,
d~dnorm(0,1)
c <- log(d)
should cause a trap error because the prior allows for negative values which cannot be log transformed. Another example is if the prior allows for extremely positive values of a parameter that will later be exponentiated. I don't know what the limit is on this, but obviously exp(10000000) will cause an error.

I would try giving it the best initial values that you can come up with.

Provide slightly informed priors.

Make sure that the looping is as efficient as it can be. Marc Kery's book Introduction to Winbugs for Ecologist provides some tips on this (http://www.lce.esalq.usp.br/arquivos/aulas/2010/LCE5813/Introduction%20to%20WinBUGS%20for%20Ecologists.pdf)

Lastly, I would perform the analysis in JAGS. Subtle differences between bugs and jags means that some problems can be resolve by simply switching programs. Not very satisfying but may work.

I hope this helps you resolve your trap error and move forward!

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-24 06:21