# Winbugs Code Problem

#### and8238

##### New Member
Hi,

I am writing my thesis which is about football betting. I encountered a minor problem and would really appreciate it if you can help me. The problem I have is in the calculation of the total points of each time.

Below you can find the whole program...where the data points include the home team, away team, home goals, away goals, home replicated goals, away replicated goals.

Thank you very much

model{
for (i in 1:n){
# stochastic component
goals1~dpois(lambda1)
goals2~dpois(lambda2)
log(lambda1)<- mu + home + a[ ht ] + d[ at ]
log(lambda2)<- mu + a[ at ] + d[ ht ]
}
# STZ constraints
a[1]<- -sum( a[2:20] )
d[1]<- -sum( d[2:20] )
#
# prior distributions
mu~dnorm(0,0.001)
home~dnorm(0,0.001)
for (i in 2:K){
a~dnorm(0,0.01)
d~dnorm(0,0.01)
}

for (i in 1:n){
# replicated league
goals1.rep~dpois(lambda1.rep)
goals2.rep~dpois(lambda2.rep)
log(lambda1.rep)<- mu + home + a[ ht ] + d[ at ]
log(lambda2.rep)<- mu + a[ at ] + d[ ht ]
goal.diff.rep <- goals1.rep-goals2.rep # replicated difference
# points earned by each home team (i)
points1 <- 3*(1-step(-goal.diff.rep)) + 1*equals(goal.diff.rep,0)
# points earned by each away team (j)
points2 <- 3*(1-step( goal.diff.rep)) + 1*equals(goal.diff.rep,0)
}}
# calculation of the total points for each team
for (j in 1:K){ for (i in 1:n){

total.points[j,i] <- (points1)*equals(ht,j) + (points2)*equals(at,j)

}
tp[j]<-sum(total.points[j,1:380])

}

}

INITS
list( mu=0.5, home=0.5, a=c(NA, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0) , d=c(NA, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0) )

DATA - LIST FORMAT
list(n=380, K=20,
ht = c(16, 1, 7, 13, 14, 15, 19, 4, 11, 6, 18, 17, 2, 10, 3, 5, 8, 12, 9, 5, 8, 17, 18, 20, 10, 2, 3, 12, 7, 1, 4, 6, 13, 14, 16, 11, 19, 15, 5, 4, 7, 16, 18, 6, 3, 17, 19, 11, 9, 9, 1, 2, 8, 10, 12, 20, 15, 13, 14, 4, 5, 6, 7, 16, 19, 3, 11, 17, 18, 20, 1, 2, 9, 10, 12, 14, 15, 13, 8, 20, 5, 6, 7, 2, 11, 3, 12, 17, 15, 16, 1, 4, 8, 9, 14, 18, 13, 19, 10, 8, 4, 5, 9, 11, 18, 13, 19, 2, 17, 10, 6, 7, 12, 14, 16, 20, 3, 15, 1, 10, 1, 6, 7, 14, 15, 16, 12, 20, 3, 5, 2, 8, 9, 19, 4, 13, 17, 11, 18, 2, 8, 4, 9, 11, 1, 3, 14, 15, 16, 20, 12, 7, 10, 5, 17, 13, 19, 11, 3, 9, 12, 14, 17, 18, 4, 6, 16, 6, 20, 5, 1, 13, 15, 20, 2, 7, 10, 19, 8, 8, 1, 2, 9, 10, 12, 13, 14, 15, 20, 6, 17, 19, 3, 4, 7, 11, 16, 18, 5, 5, 3, 4, 6, 7, 11, 17, 19, 16, 9, 8, 10, 12, 14, 15, 20, 13, 1, 2, 18, 4, 5, 6, 11, 16, 19, 3, 7, 17, 9, 2, 8, 12, 13, 14, 15, 10, 20, 1, 18, 14, 16, 19, 15, 6, 4, 11, 13, 9, 2, 3, 5, 8, 10, 18, 20, 12, 17, 15, 6, 7, 11, 13, 16, 19, 14, 4, 1, 18, 7, 8, 5, 9, 12, 18, 20, 3, 17, 9, 1, 8, 10, 13, 16, 18, 14, 4, 19, 2, 10, 11, 6, 12, 15, 17, 20, 3, 5, 2, 7, 9, 4, 5, 8, 11, 13, 19, 18, 17, 2, 10, 7, 6, 1, 3, 12, 15, 16, 20, 14, 18, 2, 4, 8, 13, 5, 1, 10, 12, 14, 15, 16, 20, 7, 1, 11, 3, 9, 19, 17, 4, 5, 8, 9, 18, 19, 11, 13, 2, 6, 7, 3, 10, 12, 14, 16, 20, 1, 15, 10, 7, 8, 13, 15, 19, 20, 2, 1, 5, 6, 17, 3, 4, 6, 9, 11, 12, 14, 16, 17, 18),
at = c(9, 2, 18, 20, 3, 12, 5, 17, 8, 10, 19, 16, 15, 14, 7, 11, 4, 6, 19, 4, 16, 7, 11, 15, 1, 13, 6, 14, 9, 12, 18, 5, 8, 20, 3, 17, 2, 10, 14, 12, 20, 15, 2, 9, 10, 8, 13, 1, 13, 17, 16, 5, 6, 19, 3, 18, 11, 7, 4, 9, 1, 2, 10, 12, 15, 20, 13, 14, 8, 11, 18, 17, 3, 16, 7, 19, 6, 4, 5, 10, 18, 14, 16, 8, 9, 4, 13, 19, 1, 6, 7, 11, 20, 2, 15, 17, 5, 3, 12, 7, 20, 10, 15, 14, 12, 16, 1, 3, 6, 13, 18, 2, 19, 8, 4, 5, 11, 17, 9, 8, 13, 19, 4, 18, 5, 11, 9, 2, 17, 7, 12, 15, 10, 16, 1, 14, 20, 6, 16, 10, 1, 6, 14, 7, 17, 8, 2, 4, 5, 9, 11, 19, 18, 3, 12, 15, 20, 10, 13, 8, 20, 7, 5, 15, 19, 1, 2, 13, 1, 9, 14, 18, 3, 16, 4, 6, 17, 11, 12, 19, 3, 11, 18, 4, 5, 17, 16, 7, 6, 15, 2, 14, 9, 13, 12, 20, 10, 1, 8, 2, 12, 14, 8, 13, 15, 9, 10, 1, 4, 18, 7, 16, 17, 19, 3, 11, 5, 6, 9, 10, 12, 20, 2, 14, 8, 1, 15, 13, 6, 18, 17, 4, 19, 5, 16, 3, 7, 11, 3, 12, 8, 9, 20, 3, 5, 18, 2, 7, 19, 16, 6, 13, 15, 4, 14, 1, 11, 2, 12, 3, 5, 9, 17, 18, 10, 8, 20, 20, 17, 11, 19, 16, 15, 7, 13, 14, 4, 11, 15, 2, 20, 12, 7, 5, 6, 3, 17, 1, 6, 4, 16, 10, 14, 18, 8, 19, 13, 9, 1, 1, 16, 20, 14, 3, 10, 12, 6, 15, 7, 5, 8, 17, 19, 2, 18, 9, 13, 4, 11, 14, 20, 7, 10, 1, 15, 4, 9, 2, 13, 8, 19, 17,
5, 10, 16, 18, 12, 6, 1, 15, 16, 3, 20, 10, 7, 12, 6, 14, 4, 11, 5, 2, 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, 1, 3, 0, 0, 1, 1, 1, 1, 1, 0, 1, 2, 2, 2, 4, 1, 1, 1, 0, 2, 0, 1, 0, 2, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 2, 1, 2, 2, 3, 1, 2, 1, 1, 3, 0, 0, 1, 0, 3, 1, 0, 0, 3, 1, 1, 0, 1, 0, 4, 2, 3, 1, 1, 0, 1, 0, 1, 0, 0, 2, 4, 1, 2, 3, 1, 0, 3, 1, 0, 1, 0, 0, 2, 2, 1, 1, 0, 1, 2, 0, 1, 3, 2, 1, 2, 1, 1, 0, 2, 1, 1) )

goals1.rep[] goals2.rep[]
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA
NA NA

END

#### Dason

What is your problem? Honestly that is probably the most important piece of information.

#### and8238

##### New Member
When I load the data values, compile the model and load and generate the initial values it all works fine....however when I go to Inference-> Samples in Winbugs...it doesn't let me set total.points to get the posterior summaries

#### and8238

##### New Member
ok found what the problem was thank you