I am new to Jags and I'm trying to fit a multinomial model to my data. When I run the code I get the following error: "positive.counts[1,1:9] is partly observed and partly missing". I googled it and I found that this is due to the fact that a node cannot have observed and missing values at the same time. This is because in my data (see code below) there are values and NA in the same row. If I substitute the NA with 0 values the model works properly. Does anyone have a solution to this? Below you can find the data and the code!
Many thanks in advance,
Elisa
##########################################################################
# load jags
library(runjags)
# define the data:
data <- list("N_cases"=c(978,737, 737, 1189, 270, 268), "positive.counts" = matrix(c(649 ,567 ,464 ,821, 98, 117,203 , 133, 81, 290, 41, 26,3, 7, 4, 6, 5, 0,NA, NA, NA, NA, 20, 19,24, 15, 3, NA, 21, 15,NA, NA, 184, NA, 17, 23, NA, NA, NA, NA, 26, 17,99, 15, 1, 72, 14, 25,NA, NA, NA, NA, 28, 26),6,9), "n"= 6,"n_responses" = 9)
# define the model
model { mu.w <- 0
prec <- 0.5
for (s in 1:n_responses) {
w[s] ~ dnorm(mu.w, prec);
a[s] <- exp(w[s]); # positive parameter
}
for (i in 1:n){
positive.counts[i,1:n_responses] ~ dmulti(p[i,1:n_responses], N_cases[i])
}
for(i in 1:n){
for (s in 1:n_responses) {
delta[i, s] ~ dgamma(a[s], 1)
}
}
for(i in 1:n){
for (s in 1:n_responses) {
p[i, s] <- delta[i,s] / sum(delta[i,1:n_responses])
}
}
}
# run the model
n.adapt=1000
n.burn=5000
n.iters=10000
n.chains <- 5;
n.total.samples <- 10000
n.samples.per.chain <- (n.total.samples %/% n.chains)
n.thin <- n.iters %/% n.samples.per.chain; if(n.thin==0) n.thin <- 1;
tomonitor <- c("a","p")
mcmc.post <- run.jags(model="multi_model.jags",
data=data,
method="parallel",
sample=n.samples.per.chain,
burnin=n.burn,
adapt=n.adapt,
n.chains=n.chains,
thin=n.thin,
monitor= tomonitor);
positive.counts
matrix represent? And when you say "If I substitute the NA with 0 values the model works properly" I think you mean "If I substitute the NA with 0 valuesrun.jags
does not produce any errors". The two statements are very far from equivalent. ;) – Limey