7

I'm building a multi-level Bayesian model using rJAGS and I would like to specify a Cauchy prior for several of my parameters. Is there a way to do this in JAGS, or do I need to switch to STAN? My JAGS model is below. I'd like to replace the dnorm distributions with Cauchy, but JAGS cannot find the standard R Cauchy distributions, e.g. dcauchy, pcauchy

model_string <- "model{
for (i in 1:n){
    y[i] ~ dbin(mu[i], 1) 
p.bound[i] <- max(0, min(1, mu[i])) #381 gelman
logit(mu[i]) <- a[dc[i]] + b1*x1[i] + b2*x2[i]
}

b1 ~ dnorm(0,.001) 
b2 ~ dnorm(0,.001) 

for (j in 1: n.dc ){
    a[j] ~ dnorm(g0, tau.a)  #not goj, g1j
}

g0 ~ dnorm(0,.001) 
tau.a <- pow(sigma.a , -2)
sigma.a ~ dnorm(0,.001) 
}"
Emily
  • 825
  • 3
  • 10
  • 20
  • This is a coding site, but not a code writing service. Please edit your function to include code or delete the question and seek a venue where you can get statistical programming tutoring. – IRTFM Jan 22 '16 at 00:03
  • Updated - the question was not about creating the code but about the capacity of JAGS – Emily Jan 22 '16 at 15:06
  • As illustrated in the answer, providing the code allows answers that identify the requested facilities but also allow identification of methodological errors about which you are unaware.. – IRTFM Jan 22 '16 at 17:48

1 Answers1

9

The Cauchy distribution is a special case of the t distribution, with 1 degree of freedom (Wikipedia link). While JAGS does not have the Cauchy, it does have the t distribution.

dt(mu, tau, k)

Just set k equal to 1 and you have a Cauchy prior

dt(mu, tau, 1)

I would not set your variance to a normal or Cauchy prior though, considering that variance is always positive (and the normal or Cauchy is not). Try something like the gamma distribution for your precision.

tau.a ~ dgamma(0.001,0.001) # vague precision parameter
sigma.a <- 1/sqrt(tau.a)
mfidino
  • 3,030
  • 1
  • 9
  • 13
  • Gelman discusses use of _half_-cauchy priors on sd parameters here: [Prior distributions for variance parameters in hierarchical models](https://projecteuclid.org/download/pdf_1/euclid.ba/1340371048) – jbaums Jan 24 '16 at 01:16
  • Interesting. Thanks for the share! – mfidino Jan 26 '16 at 14:55
  • 5
    In JAGS, the half-Cauchy prior for standard deviation (not variance) can be coded by truncating the t distribution: `dt(mu, tau, 1)T(0,)`. – tflutre Apr 18 '16 at 16:27
  • 5
    Gelman recommends a non-informative Cauchy prior `dt(0, pow(2.5,-2), 1)` https://arxiv.org/pdf/0901.4011.pdf – jO. Jan 14 '17 at 16:57