I want to estimate the shape parameter of gamma distribution in Winbugs. I select gamma distribution as prior for shape parameter. Data set is generated using MATLAB as:

gamrnd(5,1,[100 1])

a small part of data loaded to model is here:


The model in Winbugs is simple and as follows:

   for( i in 1 : n ) {
      y[i] ~ dgamma(a,b)
   a ~ dgamma(3,1)

Estimation is strongly dependent on the prior that was selected for a. As for each distribution, (normal-gamma-uniform) the estimated a value is around the mean value of the selected prior distribution. For example, choosing the above-mentioned prior (a ~ dgamma(3,1)) resulted in shape parameter estimation 3.026; also running the model for more iterations doesn't change results so much!

What is the problem and how can I solve that?


I run a similar script in R, but it seems that OK, setting prior of the b

How is your prior of b setting?

Has your MCMC chain already converged?

PS: I tried something as below as you set b as fixed. But I also tried some other prior of b, it is OK.

N <- 100
x <- rgamma(N, 5, 1)

model {
    for (i in 1:length(x)) {
        x[i] ~ dgamma(a, b)
    a ~ dgamma(3, 1)
    b <- 1

jags <- jags.model('example1.bug',
                   data = list('x' = x),
                   n.chains = 4,
                   n.adapt = 100)

mcmc.samples <- coda.samples(jags,
             c('a', "b"),
             n.iter = 10000) 

| cite | improve this answer | |
  • $\begingroup$ yes coverage is occurred! i supposed b to be constant and the data set is added to question. $\endgroup$ – user110502 Nov 26 '13 at 11:53
  • $\begingroup$ may i ask you for the R script for this model? $\endgroup$ – user110502 Nov 26 '13 at 11:58
  • $\begingroup$ @user110502 it seems that other b's prior like log-normal I tried is also OK. But you could try the script above. $\endgroup$ – Shusheng Nov 26 '13 at 12:11
  • $\begingroup$ @user110502 Note that asking for code (arguably) takes this off-topic. Your original question floats somewhere between statistics and statistical computing, but the help for CV does spell out that questions focused entirely on code belong elsewhere. $\endgroup$ – Nick Cox Nov 26 '13 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.