Solved – Priors for Truncated Parameters – RJAGS

bayesianjagsprioruninformative-priorwinbugs

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?

Best Answer

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

Related Question