0

I am building a hierarchical bayesian model for shots in a football/soccer match. my code is below.

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)

I get the following errors when trying to run the jags.model function:

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

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

and

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

Any help greatly appreciated.

Ed.T
  • 1
  • 1
  • you are missing a closing bracket, for the model statement `}` – user20650 Jul 31 '16 at 11:01
  • thanks, good spot. I am now getting the following error: `Error in jags.model(model2.spec, data = list(N = length(dat1$hometeam), : RUNTIME ERROR: Compilation error on line 25. Attempt to redefine node taudef[1]` any ideas? thanks in advance – Ed.T Jul 31 '16 at 11:26
  • From a quick eyeball, do you actually want the priors (from muatt to taudef) inside the second loop, or should it be closed before them? Where is home defined? – user20650 Jul 31 '16 at 11:47
  • ahhh you are right, closing it before the priors does the trick. Thanks so much! – Ed.T Jul 31 '16 at 11:54

0 Answers0