You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And now let's use that `predict` function to do out of sample predictions which we will use for visualisation.
172
+
171
173
```{code-cell} ipython3
172
174
:tags: [hide-output]
173
175
@@ -178,6 +180,8 @@ idata1 = predict(
178
180
)
179
181
```
180
182
183
+
Finally, we can now visualise the model fit to data, and our posterior in parameter space.
184
+
181
185
```{code-cell} ipython3
182
186
:tags: [hide-input]
183
187
@@ -413,16 +417,16 @@ def plot(idata):
413
417
plot(idata2);
414
418
```
415
419
416
-
In contrast to plain regression model (Model 1), when we model on the group level we can see that now the evidence points toward _negative_ relationships between $x$ and $y$.
420
+
In contrast to Model 1, when we consider groups we can see that now the evidence points toward _negative_ relationships between $x$ and $y$.
title="Model 2 suggests a negative slopes for each group", xlabel=r"$\beta_1$", ylabel="Group"
425
+
title="Model 2 suggests negative slopes for each group", xlabel=r"$\beta_1$", ylabel="Group"
422
426
);
423
427
```
424
428
425
-
## Model 3: Partial pooling (hierarchical) model
429
+
## Model 3: Partial pooling model
426
430
427
431
Model 3 assumes the same causal DAG as model 2 (see above). However, we can go further and incorporate more knowledge about the structure of our data. Rather than treating each group as entirely independent, we can use our knowledge that these groups are drawn from a population-level distribution.
where $\beta_0$ and $\beta_1$ are the population-level parameters, and $\gamma_0$ and $\gamma_1$ are the group offset parameters.
446
-
447
-
+++
448
-
449
-
This model could also be called a partial pooling model.
449
+
where $\vec{\beta_0}$ and $\vec{\beta_1}$ are the group-level parameters. These group level parameters can be though of as being sampled from population level intercept distribution $\text{Normal}(p_{0\mu}, p_{0\sigma})$ and population level slope distribution $\text{Normal}(p_{1\mu}, p_{1\sigma})$.
450
450
451
451
+++
452
452
@@ -508,32 +508,13 @@ with pm.Model(coords=coords) as model3:
Plotting the DAG now makes it clear that the group-level intercept and slope parameters are drawn from a population level distributions. That is, we have hyper-priors for the slopes and intercept parameters. This particular model does not have a hyper-prior for the measurement error - this is just left as one parameter per group, as in the previous model.
511
+
Plotting the DAG now makes it clear that the group-level intercept and slope parameters are drawn from population level distributions. That is, we have hyper-priors for the slopes and intercept parameters. This particular model does not have a hyper-prior for the measurement error - this is just left as one parameter per group, as in the previous model.
531
512
532
513
```{code-cell} ipython3
533
514
pm.model_to_graphviz(model3)
534
515
```
535
516
536
-
The nodes `pop_intercept` and `pop_slope` represent the population-level intercept and slope parameters. While the 5 $\beta_0$ and $\beta_1$ nodes represent intercepts and slopes for each of the 5 observed groups (respectively), the `pop_intercept` and `pop_slope` represent what we can infer about the population-level intercept and slope. Equivalently, we could say they represent our beliefs about an as yet unobserved group.
517
+
The nodes `pop_intercept` and `pop_slope` represent the population-level intercept and slope parameters. While the $\beta_0$ and $\beta_1$ nodes represent intercepts and slopes for each of the 5 observed groups (respectively), the `pop_intercept` and `pop_slope` represent what we can infer about the population-level intercept and slope. Equivalently, we could say they represent our beliefs about an as yet unobserved group.
537
518
538
519
+++
539
520
@@ -601,8 +582,17 @@ The panel on the right shows the posterior group level posterior of the slope an
0 commit comments