# Weighted Linear Regression using GLM

**URL:** <https://discourse.pymc.io/t/weighted-linear-regression-using-glm/2558>\
**Category:** Questions\
**Created:** [January 20, 2019, 9:07pm UTC](https://discourse.pymc.io/t/weighted-linear-regression-using-glm/2558 "2019-01-20T21:07:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HarryShomer](https://avatars.discourse-cdn.com/v4/letter/h/9de0a6/32.png) [@HarryShomer](https://discourse.pymc.io/u/HarryShomer)\
**Post date:** [January 20, 2019, 9:07pm UTC](https://discourse.pymc.io/t/weighted-linear-regression-using-glm/2558/1 "2019-01-20T21:07:33Z")

</div>

Hi,

I found a [couple](https://discourse.pymc.io/t/how-to-perform-weighted-inference/1825/6) [questions](https://discourse.pymc.io/t/likelihood-with-weighted-observations/1745) related to the topic of weighting the observations for inference. I was wondering if there was a way to achieve this using a [GLM](https://docs.pymc.io/api/glm.html) object. I had trouble finding anything in the docs.

If it isn’t possible using GLM I was wondering what the preferred (or possibly established) method for doing so was.

Thanks,

Harry

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [January 21, 2019, 5:48am UTC](https://discourse.pymc.io/t/weighted-linear-regression-using-glm/2558/2 "2019-01-21T05:48:50Z")

</div>

Since the weights are usually element-wise multiply to the observed likelihood, I dont see a straightforward way to do it with GLM object. You can try either:

1. Writing a custom distribution to express the weighted likelihood
2. Express it as an additional term and use pm.Potential to add it to the model.

---

<div class="post-metadata">

**Author:** ![RusselDaries](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/russeldaries/32/4406_2.png) [@RusselDaries](https://discourse.pymc.io/u/RusselDaries)\
**Post date:** [August 30, 2021, 9:42am UTC](https://discourse.pymc.io/t/weighted-linear-regression-using-glm/2558/3 "2021-08-30T09:42:57Z")

</div>

Hi @junpenglao , for approach number 2 - how would you perform draw sample from posterior prediction?
