0

フットボール/サッカーの試合でショットの階層ベイジアン モデルを構築しています。私のコードは以下です。

dat1 <- read.csv("1314prem.csv")

home <- 0.2 # for simplicity fixing home (can be modelled separately)

model2.string <-"
model {
for (i in 1:N){
# Observed shots in game i
homesot[i] ~ dpois(theta[i,1])
awaysot[i] ~ dpois(theta[i,2])

# Karlis & Ntzoufras
log(theta[i,1]) <- home + att[hometeam[i]] + def[awayteam[i]]
log(theta[i,2]) <- att[awayteam[i]] + def[hometeam[i]]
}

for (t in 1:N){
att[t] <- att.star[t] - mean(att.star[])
att.star[t] ~ dnorm(muatt,tauatt)
def[t] <- def.star[t] - mean(def.star[])
def.star[t] ~ dnorm(mudef,taudef) 


muatt ~ dnorm(0, 0.0001)
tauatt ~ dgamma(0.1,0.1)
mudef ~ dnorm(0, 0.0001)
taudef ~ dgamma(0.1,0.1)
}
"
model2.spec<-textConnection(model2.string)

# fit model to data

jags2 <- jags.model(model2.spec,
                    data = list('N' = length(dat1$hometeam),'homesot' = dat1$homesot,
                                'awaysot'= dat1$awaysot,'hometeam'=dat1$hometeam,
                                'awayteam'=dat1$awayteam),
                    n.chains=4,
                    n.adapt=100)

jags.model 関数を実行しようとすると、次のエラーが発生します。

Error in jags.model(model2.spec, data = list(N = length(dat1$hometeam),  : 

Error parsing model file:
syntax error on line 29 near ""

Compiling model graph

Error in jags.model(model2.spec, data = list(N = length(dat1$hometeam),  : 
  Nothing to compile

In addition: Warning messages:
1: In jags.model(model2.spec, data = list(N = length(dat1$hometeam),  :
  Unused variable "N" in data
2: In jags.model(model2.spec, data = list(N = length(dat1$hometeam),  :
  Unused variable "homesot" in data
3: In jags.model(model2.spec, data = list(N = length(dat1$hometeam),  :
  Unused variable "awaysot" in data
4: In jags.model(model2.spec, data = list(N = length(dat1$hometeam),  :
  Unused variable "hometeam" in data
5: In jags.model(model2.spec, data = list(N = length(dat1$hometeam),  :
  Unused variable "awayteam" in data

どんな助けでも大歓迎です。

4

0 に答える 0