Priors for Truncated Parameters - RJAGS

I would like to estimate the parameters of a specific model.

The model specification is as follows:

$p_t = k_t + B_t/(1-B_t) + \eta_t$, where $\eta_t \sim N(0, \sigma^2)$

$R_{t+1} = R_{t} + R_t (R_t - B_t) (1-R_t)$

$B_{t+1} = B_{t} + (R_t - B_t) \left( \frac{(k_t - d_t B_t + a_t (1-B_t))}{(1-R_t)} + (1-B_t) R_t \right)$

$k_t = k_{t-1} + \epsilon_t$

Conditions for parameters:

• $R_t$ and $B_t$ should be between $0$ and $1$.
• $d_t$ and $a_t$ should be positive.

Estimation attempt in RJAGS

I have attempted to estimate the model (in sample estimation of $p_t$) using RJAGS; see my code below:

jagsscript = cat("

model{

#GARCH observations with latent data
for(t in 1:N)
{

p[t]        ~ dnorm(k[t] +(B[t]/(1-B[t]))* (k[t]-d[t]), eta)
p_fitted[t] ~ dnorm(k[t] +(B[t]/(1-B[t]))*(k[t]-d[t]), eta)
}

for(t in 1:N-1)
{
B[t+1]    <- B[t]+ (R[t]-B[t])*(  (k[t]-d[t]*B[t]+a*(1-B[t]))/(1-R[t]) + (1-B[t])*R[t] )
R[t+1]    <- R[t] + R[t]*(R[t]-B[t])*(1-R[t])
}

for(t in 2:N)
{
k[t]      ~  dnorm(k[t-1], zeta)
}

#priors for latent data
R[1]         ~dnorm(0, 0.001)I(0,1)
B[1]         ~dnorm(0, 0.001)I(0,1)
k[1]         ~dnorm(0, 0.001)
a            ~dnorm(0, 0.001)I(0,1000)
eta         ~  dgamma(0.01, 0.01)
zeta        ~  dgamma(0.01, 0.01)
}

",file="ss_model.txt")


Using the above code and data, I get the error: Error calculating log density at initial values.

I checked the priors and I see that I can resolve the error when I assign scalar numbers to R[1] and B[1], for example:

R[1]         <-0.5
B[1]         <-0.5


However, this is not what I want.

• How can I specify the priors such that the above conditions for the parameters is satisfied?

You get the error "Error calculating log density at initial values" as the initial values of some of your parameters results in the posterior of your model being NaN, or something similar (like you would divide by zero). A solution to this is to explicitly initialize your parameters to safe starting values. This you can do by passing a list of starting values to the jags.model function in R.

It might still be the case that you get the error "Error calculating log density at initial values" even after having done this, and that would mean that the priors you have allows the parameters to take on values that "does not work" in your equations (say, resulting in a divide by zero or similar).

Also, even though you might be able to use the I() notation, I think JAGS generally uses T() instead. Also your priors on R[1] and B[1] are basically uniform over the interval [0, 1], so I would just put uniform priors over them instead, like this:

R[1] ~ dunif(0, 1)
B[1] ~ dunif(0, 1)


Also when using trucation you don't need to specify an upper limit, this works:

a ~ dnorm(0, 0.001) T(0,)


Update:

How would you initialize given the conditions as stated for the parameters?

In the rjags manual you have all the info, you could, for example, do:

init_val <- c(0.5, rep(NA, 1:N))

model <- jags.model("ss_model.txt", data = data_list, inits = list(R = init_val, B = init_val))


That is init the first element to 0.5, and the rest to NA. Here is a good blog post that explains the concept: http://doingbayesiandataanalysis.blogspot.se/2012/02/jags-code-for-exercise-121.html

• Thanks, but I unfortunately keep getting the same error. It is clear that parameters have to be initialized properly and priors should be appropriate. I don't think that initializing R[1]=B[1]=0.5 is what we need because R[t+1]=R[t] and B[t+1]=B[t] in that case. Can you please further help me in order to solve this problem? (The bounty is yours if I can get it solved) – rbm Aug 20 '15 at 8:47
• Even if I change the initial values completely I keep getting the same error. – rbm Aug 20 '15 at 8:57
• Man, I can't begin to decipher you pretty hairy model (especially since I don't know what it is about). What I would do to troubleshoot this is to take the "deterministic" part of your model, implement it in R, try different parameter values and see if you can replicate teh error there (that is, for what parameter values does your model break down). Otherwise you could play with constraining the priors in JAGS to see if you can get something going. Like, start with putting really narrow uniform (dunif) priors on everything, and see if you can get it to run, and if so, expand from there. – Rasmus Bååth Aug 20 '15 at 10:37
• Do you get anything to work? – Rasmus Bååth Aug 26 '15 at 15:04