1
$\begingroup$

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.

$\endgroup$

1 Answer 1

2
$\begingroup$

I have several rather random ideas:

  • Your j loop goes from 1 to 17, but you seem to only have 16 predictors.

  • I would try to experiment with somewhat more informative priors for beta[j], say dnorm(0, 0.01). I vaguely remember that this used to be an issue once when I was also using log link (but with Poisson distribution).

  • I would try to experiment with initializing your alpha. Also, maybe try using some continuous and positive alternative to dunif() (gamma?). Or maybe try to make the prior a bit narrower.

  • Does the model run with just a single predictor?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.