pymc-devs / pymc-examples

Examples of PyMC models, including a library of Jupyter notebooks.
https://www.pymc.io/projects/examples/en/latest/
MIT License
269 stars 234 forks source link

Little mistake in "GLM: Linear regression" #428

Closed asong-code closed 1 year ago

asong-code commented 1 year ago

Notebook title: GLM: Linear regression Notebook url: https://www.pymc.io/projects/docs/en/stable/learn/core_notebooks/GLM_linear.html

Issue description

The formula here seems to be wrong. image

Proposed solution

I think the correct formula should be:

idata.posterior["y_model"] = idata.posterior["Intercept"] + idata.posterior["slope"] * xr.DataArray(x)

OriolAbril commented 1 year ago

We should probably add a note on this. The model uses bambi to take advantage of the formula defined model. In such cases, as there can be multiple slopes, bambi names each slope with the name of the variable in the formula it multiplies, here x. Thus idata.posterior["x"] contains the posterior samples for the slope that multiplies x.

asong-code commented 1 year ago

ok. I first thought that the bambi part was optional so I just skipped that.