pymc-devs / pymc-examples

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

Error in A Primer on Bayesian Methods for Multilevel Modeling #561

Closed henrytdsimmons closed 11 months ago

henrytdsimmons commented 11 months ago

Notebook title: A Primer on Bayesian Methods for Multilevel Modeling
Notebook url: https://www.pymc.io/projects/examples/en/latest/case_studies/multilevel_modeling.html

Issue description

Under the text "Let’s now turn our attention to the unpooled model, and see how it fares in comparison." there is the code block:

coords = {"county": mn_counties}

with pm.Model(coords=coords) as unpooled_model:
    floor_idx = pm.MutableData("floor_ind", floor_measure, dims="obs_id")

    alpha = pm.Normal("alpha", 0, sigma=10, dims="county")
    beta = pm.Normal("beta", 0, sigma=10)
    sigma = pm.Exponential("sigma", 1)

    theta = alpha[county] + beta * floor_ind

    y = pm.Normal("y", theta, sigma=sigma, observed=log_radon, dims="obs_id")

Here, floor index is assigned to floor_idx but then when calculating theta, we use floor_ind not floor_idx

floor_ind was previously defined in an higher up code block and is identical so there are no errors introduced, but it's still a mistake.

Proposed solution

Rename floor_ind to floor_idx:

theta = alpha[county] + beta * floor_ind to theta = alpha[county] + beta * floor_idx

twiecki commented 11 months ago

Good catch, want to do a PR?

henrytdsimmons commented 11 months ago

Yep

henrytdsimmons commented 11 months ago

https://github.com/pymc-devs/pymc-examples/pull/562

twiecki commented 11 months ago

Closed by #562.