I had exactly the same with specifying dgamma(0.001, 0.001)
for WinBUGS! Jags can actually take it (and I recommend you to use Jags if you don't need advanced WinBUGS features; and even if you want to use WinBUGS, it comes in handy for debugging, because Jags has much more comprehensible error reporting), but for WinBUGS, you must do:
x[..] ~ dnorm(mean[..], tau)
tau ~ dgamma(0.01, 0.01)
Don't be afraid, dgamma
is a good choice. You just have to tweak the parameters.
Follow this resource which perfectly explains gamma parameters and prior choice!
http://www.unc.edu/courses/2010fall/ecol/563/001/docs/lectures/lecture14.htm#precision
Also note that it might come in handy to normalize the input variables - it makes parameter estimation (and prior choice) much more smooth and easier, because the basic priors will work perfectly with the usual constants.
Much about your question is unclear, but I can talk about the median in the gamma distribution and you may be able to resolve the problem from that.
The gamma distribution is typically written either in the rate form or the scale form (I'll avoid using $\beta$ here, since your intention isn't clear):
Rate form:
$$f(x;\alpha,\phi) = \frac{\phi^\alpha}{\Gamma(\alpha)} x^{\alpha-1}e^{-\phi x} \quad \text{ for } x > 0 \text{ and } \alpha, \phi > 0$$
Scale form:
$$f(x;\alpha,\theta) = \frac{x^{\alpha-1}e^{-\frac{x}{\theta}}}{\theta^\alpha\Gamma(\alpha)} \quad \text{ for } x > 0 \text{ and } \alpha, \theta > 0$$
It's sometimes also written in the mean form (especially for GLMs):
$$f(x;\alpha,\mu) = \frac{\alpha^\alpha}{\mu^\alpha\Gamma(\alpha)}x^{\alpha-1}e^{-\frac{x\alpha}{\mu}} \quad \text{ for } x > 0 \text{ and } \alpha, \mu > 0$$
--
The mean is $\alpha\theta = \alpha/\phi=\mu$.
The median doesn't have a simple closed form, but for larger $\alpha$, it can be approximated.
For $\beta=1$, for large $\alpha$, the median is approximately the mean $-\frac{1}{3}$. This works well for $\alpha$ around 10 and higher.
More accurately, the median is approximately $\frac{3 \alpha - 0.8}{3 \alpha + 0.2}$ times the mean (as long as $\alpha$ is not too small, say no less than somewhere around 1-2, it works okay):
Another way to approach the median is via the Wilson-Hilferty transformation; since the cube root of a gamma is approximately normal, one can approximate the relationship between the mean and the median via that relationship (the median directly transforms both directions, but the mean is more complicated - one can use Taylor expansions to approximate the mean). (Examination of this approximation suggests it's actually pretty poor. The Wikipedia page uses it to approximate the median for the chi-square distribution, but frankly it looks like it's not nearly as good as even the "$-\frac{1}{3}$" rule I mentioned earlier, let alone the other one.)
For more accuracy, if one specifies the median and one specifies the scale or rate parameter, one can use the gamma cdf or the inverse gamma cdf (the gamma quantile function) to iteratively solve for the required alpha.
If $F$ is the gamma cdf and $F^{-1}$ is its inverse, you use root finding to solve $F_{\alpha,\beta}(m) - \frac{1}{2}=0$ for $\alpha$, or to solve $m - F^{-1}_{\alpha,\beta}(\frac{1}{2})=0$
A good starting point would be from one of the previously mentioned approximations.
I think I know what an appropriate β parameter is (though I could be wrong on this point, feel free to make comments if I'm thinking about that incorrectly)
It's a bit hard to comment about whether you have a misconception here if you aren't explicit about what you actually think and why.
Best Answer
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.