全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 winbugs及其他软件专版
4846 1
2014-06-17
I could not get the WinBUGS code below to work. It works for normal priors, but not for uniform priors. The error message that appears after I click compile is array index is greater than array upper bound for age. What does that mean? Can any one please help me work the code below please?

model
{
for (i in 1:n) {
# Linear regression on logit
logit(p) <- alpha + b.sex*sex + b.age*age
# Likelihood function for each data point
frac ~ dbern(p)
}
alpha ~ dunif(0, 1) # Prior for intercept
b.sex ~ dunif(0, 1) # Prior for slope of sex
b.age ~ dunif(0, 1) # Prior for slope of age
}
Data
list(sex=c(1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0,     1,
1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1,     1, 0,
0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1,      1, 1,
0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1),
age= c(69, 57, 61, 60, 69, 74, 63, 68, 64, 53, 60, 58, 79, 56, 53, 74, 56, 76, 72,
56, 66, 52, 77, 70, 69, 76, 72, 53, 69, 59, 73, 77, 55, 77, 68, 62, 56, 68, 70, 60,
57, 51, 51, 63, 57, 80, 52, 65, 72, 80, 73, 76, 79, 66, 51, 76, 75, 66, 75, 78, 70,
67, 51, 70, 71, 71, 74, 74, 60, 58, 55, 61, 65, 52, 68, 75, 52, 53, 70),
frac=c(1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1,        0,
1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,        1, 1,
1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1,      1, 1,
1, 0, 1, 1, 0, 0, 1, 0, 0, 1),
n=100)
Initial Values
list(alpha=0.5, b.sex=0.5, b.age=0.5)

二维码

扫码加我 拉你入群

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

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

全部回复
2014-6-17 06:55:12
Oh, that's clear. WinBUGS says array index is greater than array upper bound for age. That clearly hints an error -> I see you have n = 100 and the age list is not long enough:

> your_list <- list(...)
> str(your_list)
List of 4
$ sex : num [1:100] 1 1 1 0 1 1 0 0 0 0 ...
$ age : num [1:79] 69 57 61 60 69 74 63 68 64 53 ...
$ frac: num [1:100] 1 1 1 0 1 1 0 1 1 0 ...
$ n   : num 100
Anyways, I wouldn't use uniform prior here; unless you actually know what you are doing, I would recommend flat normal, like dnorm(0, 1.0E-10) or so. You should also allow negative values for the coefficients. The "null hypothesis" normally is that the coefficient is zero, so for the mean value of the posterior distribution of the coefficient to be zero, you should "allow it some space from both sides" (intuitivelly said).
二维码

扫码加我 拉你入群

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

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

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群