我希望运行分层泊松模型来曲棍球目标趋势数据。这是在bug中设置的模型:
modelString <- "model {
for(i in 1:n_obs){
hockey_goals[i] ~ dpois(p[i])
log(p[i]) <- p_inter + p_age * age[i] + p_sv_pct * sv_pct[i] + p_team * team[i] + p_win_pct * win_pct[i] + log(n_mins[i])
}
p_inter ~ dnorm(0,0.00001)
p_age ~ dnorm(0, 0.00001)
p_sv_pct ~ dnorm(0, 0.00001)
p_team ~ dnorm(0, 0.00001)
p_win_pct ~ dnorm(0, 0.00001)
}"
然后我编译并加载数据:
season_goals <- data$GA
n_mins <- data$MIN
age <- data$Age
sv_pct <- data$SV.
team <- data$Tm
win_pct <- data$W/data$GP
data <- list(n_obs=length(season_goals),n_mins=n_mins,hockey_goals=season_goals,age=age,
sv_pct=sv_pct,team=team,win_pct=win_pct)
# Get the data into BUGS:
modelData( bugsData( data ) )
#------------------------------------------------------------------------------
# INTIALIZE THE CHAINS.
nchain = 1
modelCompile( numChains=nchain )
modelGenInits()
#------------------------------------------------------------------------------
# RUN THE CHAINS.
samplesSet( c("p_age","p_sv_pct","p_team","p_win_pct") )
# R command defines a new variable that specifies an arbitrary chain length:
chainLength = 10000
# BRugs tells BUGS to generate a MCMC chain:
modelUpdate( chainLength )
此时我收到一个错误: handleRes(res)出错:NA
关于我哪里出错的任何想法......?
答案 0 :(得分:0)
我希望我可以发表评论,但我没有足够的声誉。无论如何,我编写了一些数据并运行了模型的简化版本(即只播放了年龄和分钟数)。我在OpenBUGS的GUI版本中运行它并且它不起作用。然后我将你系数的先验值改为dnorm(0,0.01
)并更新了。
所以我建议改变前辈。你拥有的非常非常模糊。按建议更改它们不会影响您的推理,您可以让模型运行。