Can you give me example to write half-normal prior using Nimble package in R?
For example, if I want my precision variable "tau.b" to follow a Half-Normal(0, 2.5), will it be correct if I put it as below?
for (k in 1:nvar) {b[k] ~ dnorm(mu.b[k],tau.b[k])}
#HALF NORMAL prior for the precision of b[]
tau.b ~ dnorm(0, 2.5)
tau.b ~ dconstraint(tau.b>0)
Thanks in advance!
PS: I have tried to read the Nimble manual page 53, but it is still not clear to me of how to apply it.
I think your method (setting
tau.b ~ dnorm(...)
and then usingconstraint_data ~ dconstraint(tau.b > 0)
should work (the manual specifies that you should setconstraint_data
to 1 in the data provided to the model), but might be overkill/less efficient than specifying a truncated distribution, asLeaving the last argument blank declares that there is only lower truncation at 0, with no truncation at the upper limit.
Why don't you try them both on a toy example and see how it goes?
(It's not clear to me whether you want a single joint prior on the precision or a single joint prior — the former seems more likely, but you refer to both
tau.b[k]
andtau.b
in your example ...)The manual does say that methods that rely on automatic differentiation won't work with truncation; my guess is that
dconstraint()
would break AD as well.See Section 5.2.7.1, "Truncation" (this is on p. 52, not 53)