# Solved – Weighted generalized regression in BUGS, JAGS

In `R` we can "prior weight" a `glm` regression via the weights parameter. For example:

``glm.D93 <- glm(counts ~ outcome + treatment, family = poisson(), weights=w) ``

How can this be accomplished in a `JAGS` or `BUGS` model?

I found some paper discussing this, but none of them provides an example. I'm interested mainly into Poisson and logistic regression examples.

Contents

It might be late… but,

• Adding data points is not advised as it would change degrees of freedom. Mean estimates of fixed effect could be well estimated, but all inference should be avoided with such models. It is hard to "let the data speaks" if you change it.
• Of course it only works with integer-valued weights (you cannot duplicate 0.5 data point), which is not what is done in most weighted (lm) regression. In general, a weighing is created based on local variability estimated from replicates (e.g. 1/s or 1/s^2 at a given 'x') or based on response height (e.g. 1/Y or 1/Y^2, at a given 'x').

In Jags, Bugs, Stan, proc MCMC, or in Bayesian in general, the likelihood is not different than in frequentist lm or glm (or any model), it is just the same !! Just create a new column "weight" for your response, and write the likelihood as

y[i] ~ dnorm(mu[i], tau / weight[i])

Or a weighted poisson:

y[i] ~ dpois(lambda[i] * weight[i])

This Bugs/Jags code would simply to the trick. You will get everything correct. Don't forget to continue multiplying the posterior of tau by the weight, for instance when making prediction and confidence/prediction intervals.

Rate this post