application of dsum in r aimed estimation using rjags

user128
2013-12-01
2013-12-09

• user128
2013-12-01

i want to estimate parameters of two gamma distribution that was used to generate a data set: i used rjags and here is the code:

rm(list = ls())
N <- 1000
x <- rgamma(N, 7, 1)
y <- rgamma(N, 4, 1)
z <- x+y

jags.data <- list("z"=z,"N"=N)
jags.params <- c("a","c")
inits <- list("a"=rgamma(1,c(5,1)),"c"=rgamma(1,c(5,1)))
jags.inits <- list(inits)

GamEst <- function() {
for (i in N) {
x[i] ~ dgamma(a, 1)
y[i] ~ dgamma(c, 1)
z[i] ~ dsum(x[i],y[i])
}
a ~ dgamma(6, 1)
c ~ dgamma(6, 1)
}
jagsfit <- jags(data=jags.data, inits=jags.inits, jags.params,
n.iter=5000, n.chains=1, model.file=GamEst)

unfortunately the modeling was stopped and the error massage
"Error in jags.model(model.file, data = data, inits = init.values, n.chains = n.chains, :
Error in node z[1000]
Observed node inconsistent with unobserved parents at initialization.
Try setting appropriate initial values."
was appeared!

what is the problem?
how can i use dsum function?(??dsum or ?dsum resulted in any information!)
also how should be considered the initialization values so that the error "Observed node inconsistent with unobserved parents at initialization.
Try setting appropriate initial values" does not appear?

• Martyn Plummer
2013-12-09

What does the error message say?

Try setting appropriate initial values.

You need to set initial values for `x` and `y` so that they add up to `z`. This is the constraint you are imposing on the model with `dsum`.