# How do I parameterize a Weibull distribution in JAGS / BUGS?

Based on the answer to a previous question, For which distributions are the parameterizations in BUGS and R different?

I have been transforming R parameterizations to JAGS parameterizations, but I have been getting errors so I am asking a separate question to clarify that the transformation is correct.

R's ?dweibull states the pdf (with $a = \text{shape}$ and $b = \text{scale}$):

$$(^a/_b)(^x/_b)^{a-1} \text{exp}(- (^x/_b)^a)$$

And the JAGS manual states the pdf as:

$$\nu \lambda x^{\nu-1}\text{exp}(-\lambda x^\nu)$$

I can see that the parameterization used by R has $f(b)^a$ but the JAGS parameterization does not have an equivalent $f(\lambda)^\nu$. But I can't bring myself to pull out a pencil when I have all of this computational power at my fingertips. So I did the following empirical demonstration that the JAGS parameterization is not to simply transform shape to rate as $\text{rate} =1/b$:

The following plot represents two samples (code below),

• R (red) from $\small{Y\sim\text{Weibull}(a = 2, b = 50)}$
• JAGS (blue) from $\small{Y\sim\text{Weibull}(\lambda = 2, \nu = 1/50)}$

library(rjags)
shape <- 2
rate  <- 50
set.seed(0)
model.string <-
writeLines(paste("\nmodel{\nbeta ~ dweib (2,",1/rate,")\nY <- beta\n}"), con = 'weibulltest.bug')
j.model  <- jags.model(file = "weibulltest.bug", data = list(x=NA)) #hack
mcmc.object <- coda.samples(model = j.model, variable.names = c('Y'), n.iter = 10000)
Y.jags <- as.matrix(mcmc.object)
Y.r <- rweibull(10000, shape, rate)
plot(density(Y.r), col = 'red', ylim = c(0,0.15))
lines(density(Y.jags), col = 'blue')


Doing the algebra, we have $\lambda= (1/b)^a$ (by equating the constant term within the exponent): since $a=\nu$, this is consistent with $a (1/b)^{a} = \nu \lambda$. You're right that my answer elsewhere is wrong; feel free to edit it yourself if I don't get around to it sooner (at least the link is there to warn people) ...)
• Before working backward from your answer, I see I was stuck because I didn't think (long enough) to apply $\frac{1}{b^a}= \frac{1}{b}\frac{1}{b^{a-1}}$ – David LeBauer Nov 18 '11 at 15:25