revell
谢谢hangover的解释。我对likelihood之类的概念掌握的不是很好。没办法写出likelihood,再根据likelihood写出WinBUGS程序.所以基本上是改写别人的代码,当然在概念上尽量搞懂为什么这样做.:(
我最近改写了Tony的代码,试着把多个自变量放进去,而且还是二维的数据.我用WinBUGS试过了可以运行.但是不知道代码对不对.如果你看得懂pp.307页的代码的话,能不能帮我看看我改写的代码是否符合orthogonal reparametrization的思想.下面的代码包含两个自变量(x和num),以及数据和inits.简单的解释一下,pz是指定每一时期的lam都是1/13的概率,而pw是指定每个自变量对lam赋值的时候都有1/2的概率.也许是比较stupid的方法?
我另外还将二维数据改写成了三维数据,但是很怀疑是否正确。所以如果下面的应用于二维数据的代码可以用的话,我情愿不去碰三维数据.
MODEL2.1 treating incidental parameter problem, two independent variables
model{
for( i in 1 : N ) {
for( j in 1 : T ) {
y[i, j] ~ dbern(mu[i, j])
mu[i, j] <- phi(alpha +beta * x[i, j] + beta.num * num[i, j] + beta.yr[j])}
alpha ~ dnorm(nu, 1)
nu <- lam[i, z, w]
z ~ dcat (pz[])
w ~ dcat (pw[])
lam[i, 1, 1] <- -beta * x[i, 1]
lam[i, 2, 1] <- -beta * x[i, 2]
lam[i, 3, 1] <- -beta * x[i, 3]
lam[i, 4, 1] <- -beta * x[i, 4]
lam[i, 5, 1] <- -beta * x[i, 5]
lam[i, 6, 1] <- -beta * x[i, 6]
lam[i, 7, 1] <- -beta * x[i, 7]
lam[i, 8, 1] <- -beta * x[i, 8]
lam[i, 9, 1] <- -beta * x[i, 9]
lam[i, 10, 1] <- -beta * x[i, 10]
lam[i, 11, 1] <- -beta * x[i, 11]
lam[i, 12, 1] <- -beta * x[i, 12]
lam[i, 13, 1] <- -beta * x[i, 13]
lam[i, 1, 2] <- -beta.num * num[i, 1]
lam[i, 2, 2] <- -beta.num * num[i, 2]
lam[i, 3, 2] <- -beta.num * num[i, 3]
lam[i, 4, 2] <- -beta.num * num[i, 4]
lam[i, 5, 2] <- -beta.num * num[i, 5]
lam[i, 6, 2] <- -beta.num * num[i, 6]
lam[i, 7, 2] <- -beta.num * num[i, 7]
lam[i, 8, 2] <- -beta.num * num[i, 8]
lam[i, 9, 2] <- -beta.num * num[i, 9]
lam[i, 10, 2] <- -beta.num * num[i, 10]
lam[i, 11, 2] <- -beta.num * num[i, 11]
lam[i, 12, 2] <- -beta.num * num[i, 12]
lam[i, 13, 2] <- -beta.num * num[i, 13]
}
for(j in 1:T){
beta.yr[j] ~ dnorm(0,0.001)
}
beta ~ dnorm(0, 0.001)
beta.num ~ dnorm(0, 0.001)
}
init for model 1 and 2 only
list(alpha=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
beta = 0,
beta.num = 0,
beta.yr = c(NA,0,0,0,0,0,0,0,0,0,0,0,0),
)
Data 2 for Model 2 and model 2.1 only
list(
N=10,T=13,
pz=c(0.076923, 0.076923, 0.076923, 0.076923, 0.076923, 0.076923, 0.076923, 0.076923, 0.076923, 0.076923, 0.076923, 0.076923, 0.076923),
pw=c(0.5, 0.5),
y=structure(
.Data=c(
0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1,
0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0,
0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0),
.Dim=c(10,13)
),
x=structure(
.Data=c(
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0,
1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1,
1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0,
1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0,
1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0),
.Dim=c(10,13)
),
num=structure(
.Data=c(
0.6931, 0.6931, 0.6931, 0.6931, 0.6931, 0.6931, 0.6931, 0.6931, 0.6931, 1.0986, 1.0986, 1.0986, 1.0986,
1.6094, 1.6094, 1.6094, 1.6094, 1.6094, 1.6094, 1.6094, 1.7918, 1.7918, 1.7918, 1.7918, 1.7918, 1.7918,
2.3979, 2.4849, 2.5649, 2.5649, 2.5649, 2.5649, 2.5649, 2.6391, 2.6391, 2.6391, 2.6391, 2.6391, 2.6391,
2.6391, 2.6391, 2.6391, 2.6391, 2.7081, 2.7081, 2.7081, 2.7081, 2.7726, 2.7726, 2.9444, 2.9444, 2.9957,
2.7081, 2.7081, 2.7081, 2.7726, 2.8904, 2.9444, 3.0445, 3.0445, 3.1355, 3.1355, 3.1781, 3.1781, 3.1781,
2.1972, 2.1972, 2.3026, 2.3026, 2.3026, 2.3979, 2.3979, 2.3979, 2.3979, 2.3979, 2.3979, 2.3979, 2.3979,
1.7918, 1.7918, 1.7918, 1.7918, 1.7918, 1.7918, 1.7918, 2.0794, 2.1972, 2.3026, 2.3026, 2.3026, 2.3026,
0.0000, 0.0000, 0.0000, 0.6931, 0.6931, 0.6931, 0.6931, 0.6931, 0.6931, 0.6931, 0.6931, 0.6931, 0.6931,
1.9459, 1.9459, 2.0794, 2.0794, 2.0794, 2.0794, 2.0794, 2.0794, 2.0794, 2.0794, 2.1972, 2.1972, 2.1972,
2.3026, 2.3026, 2.3026, 2.4849, 2.4849, 2.5649, 2.8332, 2.8332, 2.8332, 2.9444, 3.0445, 3.0445, 3.0445),
.Dim=c(10, 13)
)
)
END