I am trying to fit a Gamma GLM to my data.Here's my code:
Data <- read.csv("ODcost.csv")
###Define data matrix
X <- cbind(1,Data[,c(1:16)])
C <- Data$C
E <- Data$E
N <- length(C)
Gamma.data <- list("C","N","X","E")
Gamma2 <- function() {
# Priors:
for(j in 1:17){beta[j] ~ dnorm(0.0, 0.001)}
alpha ~ dunif(0,100)
# Likelihood data model:
for (i in 1:N) {
log(mu[i]) <- log(E[i]) + inprod(X[i,],beta[])
# dgamma(shape, rate):
C[i] ~ dgamma(alpha, mu[i]/alpha)
}
}
Gamma.inits <- function(){list("beta"=rep(0.001,17))}
Gamma.params <- c(paste("beta[",i=1:17,"]",sep=""))
Gammafit <- jags(data = Gamma.data,inits=Gamma.inits,
parameters.to.save = Gamma.params, n.chains=2, n.iter=10000,
n.burnin=5000, n.thin=2, model.file = Gamma2)
Here's what Data
looks like:
head(Data,n=10)
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 C E
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4462 34
2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 11405 11
3 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 4720 184
4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 4631 14
5 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 7128 17881
6 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 7043 7581
7 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 5688 19699
8 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 5819 8268
9 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 5527 12229
10 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 9853 241
I get the error:
Error in jags.model(model.file, data = data, inits = init.values, n.chains =
n.chains, :
Error in node C[497]
Invalid parent values
And here's what's inside Data[497,]
:
x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 C E
497 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 1140 0
I do not know why the code is stuck at that particular row. Thanks in advance for any help.