楼主: ReneeBK
4900 1

[精彩WinBUGS答问]Array index is greater than array upper bound [推广有奖]

  • 1关注
  • 62粉丝

VIP

已卖:4900份资源

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49655 个
通用积分
55.9937
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57805 点
帖子
4005
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

楼主
ReneeBK 发表于 2014-6-17 06:54:36 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

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

经管之家联合CDA

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

感谢您参与论坛问题回答

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

+2 论坛币
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)

二维码

扫码加我 拉你入群

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

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

关键词:winbugs Greater WINBUG array Index message appears please normal error

沙发
ReneeBK 发表于 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).

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

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