Other sites

Mixed distribution

In the football data there was some reason to use a mixed distribution in the football data (ref) so I tried doing that. It was more difficult than I expected. Not only is a mixture of distributions fairly difficult, also the system was over parameterized, causing grief.

mixed distribution

data from a mixed distribution is simply said data which is from a combination of distributions. Most obvious example is length of people; males are longer than females. Combine their lengths and a joint non normal distribution appears. Separate them, two normal distributions. This problem is equivalent to the eyes problem in winbugs. Except that I use JAGS and it was supposed to be part of a larger model. The example section in JAGS shows two ways how to do this. In the end I chose to use the dnormmix distribution in the mix module. To quote the JAGS manual: ‘The mix module defines a novel distribution dnormmix(mu,tau,pi) representing a finite mixture of normal distributions‘ and ‘If you want to use the dnormmix distribution but do not care about label switching, then you can disable the tempered transition sampler withset factory “mix::TemperedMix” off, type(sampler)’That is me, so here is how to do that in R:

library(R2jags)

Loading required package: coda

Loading required package: lattice

Loading required package: R2WinBUGS

Loading required package: rjags

linking to JAGS 3.3.0

module basemod loaded

module bugs loaded

Loading required package: abind

Loading required package: parallel

Attaching package: ‘R2jags’

The following object(s) are masked from ‘package:coda':

traceplot

load.module(“mix”)

module mix loaded

set.factory(“mix::TemperedMix”, ‘sampler’, FALSE)

NULL

list.factories(‘sampler’)

factory status

1 mix::TemperedMix FALSE

2 bugs::DSum TRUE

3 bugs::Conjugate TRUE

4 bugs::Dirichlet TRUE

5 bugs::MNormal TRUE

6 base::Finite TRUE

7 base::Slice TRUE

football model

This is the previous model with dnormmix grafted in and overall strength with attack/defense removed in an attempt to simplify and understand the estimation problems . Note that Astr[1] is fixed to 1, Dstr[1] is almost fixed to 0 and all other AStr and DStr are free. I am not 100% sure about those parts. Astr needs to be fixed because otherwise the whole set of Astr[] and Dstr[] changes in a similar way over the MCMC samples. It is their relative numbers that count. Somehow, there is still a need to fix Dstr[1], as there is still an overall change. Yet, I have the feeling fixing Astr[1] gives information to determine Dstr[2:nclub] hence Astr[2:nclub] hence Dstr[1]. Yet, they all move similar, and Dstr[1] is clearly not 0 as suggested by the prior.

fbmodel1 <- function() {

for (i in 1:N) {

HomeMadeGoals[i] ~ dpois(HS[i])

OutMadeGoals[i] ~ dpois(OS[i])

log(HS[i]) <- Home + Dstr[OutClub[i]] + Astr[HomeClub[i]]

log(OS[i]) <- Dstr[HomeClub[i]] + Astr[OutClub[i]]

}

Astr[1] <- 1

Dstr[1] ~ dnorm(0,10)

for (i in 2:nclub) {

Astr[i] ~ dnormmix(MAStr,tauAStr1,EtaAStr1)

Dstr[i] ~ dnormmix(MDStr,tauDStr1,EtaDStr1)

}

for (i in 1:3) {

MAStr[i] ~ dnorm(0,.01)

MDStr[i] ~ dnorm(0,.01)

tauDStr1[i] <- tauDStr

tauAStr1[i] <- tauAStr

eee[i] <- 3

}

EtaAStr1[1:3] ~ ddirch(eee[1:3])

EtaDStr1[1:3] ~ ddirch(eee[1:3])

sigmaAstr <- 1/sqrt(tauAStr)

tauAStr ~ dgamma(.001,.001)

sigmaDstr <- 1/sqrt(tauDStr)

tauDStr ~ dgamma(.001,.001)

Home ~ dnorm(0,.0001)

}

params <- c(“Dstr”,”Astr”,”sigmaAstr”,”sigmaDstr”,”Home”)

inits <- function(){

list(TopStr=rnorm(JAGSData$nclub),

AD=rnorm(JAGSData$nclub),

sigmaAD=runif(1),

sigmaStr=runif(0,.5),

Home=rnorm(1)

)

}

jagsfit <- jags(JAGSData, model=fbmodel1, inits=inits,

parameters=params,progress.bar=”gui”,

n.iter=5000)

jagsfit

Inference for Bugs model at “C:/Users/…/RtmpSGssTD/modeld94a9b3849.txt”, fit using jags,