# Jags error with dgamma

I am trying to sample from a Gamma distribution in JAGS

gd[i] ~ dgamma(k,r)


where k and r are have priors such that they are positive. However I get the following error when I compile the model:

  Error in node gd[9]
Unobserved node inconsistent with unobserved parents at initialization


Any ideas?

EDIT: BACKGROUND

What I am trying to do is to estimate the parameters of the CIR process with Bayesian techniques. In order to assess the estimator, I have simulated some data with given parameters on a quarterly basis (timeStep=90):

jdata <- list(timeSerie=c(35000, 47123.3999346341, 55373.904244638, 71755.7487795017, 91246.3370619453, 76969.2358694695, 83390.030308266, 80657.1222156083, 76784.466470129, 83962.4642428193, 85335.5796326587, 87018.8279086056, 74059.9912730579, 69683.5404626939, 90356.0122717258, 87240.7793078735, 74276.2931903815, 39899.5948334073, 37911.738710607, 73811.7536157058, 69334.5390010963, 51326.297331755, 42711.7358571988, 32409.9939465308, 16663.7353817099, 22421.1721803643, 38604.0551895535, 50181.3269231991, 44346.3517857709, 52127.2156791002, 54740.1181745155, 41869.456839522, 50665.5626313423, 51121.4339441224, 39059.432945341, 44350.0205383802, 68629.3291332604, 49933.2126408239, 64358.5131164748, 102975.634845413, 84658.5787221384, 52243.061086781, 56988.7184089767, 43548.6558054764, 38536.145535317, 43115.4155553003, 50328.6208374212, 47191.4284861612, 42603.6038389972, 43749.2977769786, 43583.8022320709, 36672.3782472362, 26377.9033658583, 41746.6472558272, 26086.7868276075, 47228.5390765096, 75765.4757503756, 70939.107521347, 63949.8857556708, 55153.6701237129),timeStep=90)


Then I wrote a model with JAGS. The problem is that the CIR process has scaled noncentral chi square distribution and this is not directly supported in JAGS. So inspired by R implementation, I came up with

model {
for (i in 2:length(timeSerie)){
ncp[i] <- 2*c*et*timeSerie[i-1]
pd[i] ~ dpois(ncp[i]/2)
cd[i] ~ dgamma(pd[i]+1E-10,c)
gd[i] ~ dgamma(df/2,4*c)
timeSerie[i] ~ dsum(cd[i],gd[i])
}

#parameters
et <- exp(-kappa*timeStep)
c <- 2*kappa/(sigma^2*(1-et))
df <- 4*kappa*mu/sigma^2

#CIR parameter priors
lkappa ~ dunif(-10,-2)
kappa <- exp(lkappa)
mu ~ dunif(30000,100000)
lsigma ~ dunif(0,5)
sigma <- exp(lsigma)
}


Trying to run the model (jags.model in R), I get the following error

  Error in node gd[18]
Unobserved node inconsistent with unobserved parents at initialization


(Now it is 18 instead of 8, because I use other simulated data).

I tried to debug JAGS (gdb and valgrind) to no avail: I don't have enough knowledge to do it...

• could you provide a reproducible example? – David LeBauer Mar 10 '11 at 18:16
• @David please see the edit... – teucer Mar 11 '11 at 7:57
• teucer -- I tried to fit your model in JAGS, to me it seems that your model formulation in JAGS is not right. Could you please tell us the model in formulae (not in JAGS model language).. it would help me in formulating the JAGS model better. If you want to sample gd, you want to make it as a deterministic node by using <- and not ~ – suncoolsu Sep 3 '11 at 18:41