我想把Bivariate泊松分布拟合到我的硕士论文的一系列运动成绩中。
但是使用贝叶斯建模使用WinBUGS(第8章,第3.4节,第292-294页)中给出的模型,我似乎无法使模型起作用。
模型代码如下:
m1_string <- "model {
C <- 0
for(i in 1:n_games) {
minscore[i] <- min( HomeGoals[i],AwayGoals[i]) + 1
# Generate minscore latent variable
u[i] ~ dunif(0,minscore[i])
z3[i] <- trunc( u[i] )
HomeGoals[i] <- z1[i] + z3[i]
AwayGoals[i] <- z2[i] + z3[i]
Zeros[i] <- 0
Zeros[i] ~ dpois( zeros.mean[i] )
zeros.mean[i] <- -l[i] + C
l[i] <- -lambda_home[HomeTeam[i],AwayTeam[i]] + z1[i]*log( lambda_home[HomeTeam[i],AwayTeam[i]] ) - loggam( z1[i]+1 )
-lambda_away[HomeTeam[i],AwayTeam[i]] + z2[i]*log( lambda_away[HomeTeam[i],AwayTeam[i]] ) - loggam( z2[i]+1 )
-lambda_3[HomeTeam[i],AwayTeam[i]] + z3[i]*log( lambda_3[HomeTeam[i],AwayTeam[i]] ) - loggam( z3[i]+1 )
}
for(home_i in 1:n_teams) {
for(away_i in 1:n_teams) {
log( lambda_home[home_i, away_i] ) <- mu + skill[home_i] - skill[away_i]
log( lambda_away[home_i, away_i] ) <- mu + skill[away_i] - skill[home_i]
log( lambda[home_i, away_i] ) <- beta
}
}
skill[1] <- 0
for(j in 2:n_teams) {
skill[j] ~ dnorm(group_skill, group_tau)
}
group_skill ~ dnorm(0, 0.0625)
group_tau <- 1 / pow(group_sigma, 2)
group_sigma ~ dunif(0, 3)
mu ~ dnorm(0, 0.0625)
beta ~ dnorm(0, 0.0625)
}"
当通过R中的jags.model()
函数提供给JAGS的数据时,我提供以下列表:
HomeTeam / AwayTeam-主队和客队 HomeGoals / AwayGoals - 观察到的分数
n_games - 数据集中的游戏数量
n_teams - 数据集中的团队数量
当我尝试编译时:
# Compiling model 1
m1 <- jags.model(textConnection(m1_string), data = data_list, n.chains = 3,
n.adapt = 5000)
消息ERROR:RUNTIME ERROR
非常感谢任何帮助。