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
subtitle = "The empirical proportions are in orange while the model-\nimplied proportions are the black circles. The dashed line is\nthe model-implied average survival proportion.") +
217
-
annotate(geom = "text", x = c(8, 16 + 8, 32 + 8), y = 0,
subtitle = "The horizontal axis displays pond number. The vertical axis measures\nthe absolute error in the predicted proportion of survivors, compared to\nthe true value used in the simulation. The higher the point, the worse\nthe estimate. No-pooling shown in orange. Partial pooling shown in black.\nThe orange and dashed black lines show the average error for each kind\nof estimate, across each initial density of tadpoles (pond size). Smaller\nponds produce more error, but the partial pooling estimates are better\non average, especially in smaller ponds.",
492
-
y = "absolute error") +
492
+
y = "absolute error") +
493
493
theme_fivethirtyeight() +
494
494
theme(panel.grid = element_blank(),
495
495
plot.subtitle = element_text(size = 10))
@@ -810,11 +810,11 @@ post %>%
810
810
geom_density(size = 0, fill = "orange1", alpha = 3/4) +
811
811
geom_density(aes(x = sd_block__Intercept),
812
812
size = 0, fill = "orange4", alpha = 3/4) +
813
-
scale_y_continuous(NULL, breaks = NULL) +
814
-
coord_cartesian(xlim = c(0, 4)) +
815
-
ggtitle(expression(sigma["[x]"])) +
816
813
annotate(geom = "text", x = 2/3, y = 2, label = "block", color = "orange4") +
817
814
annotate(geom = "text", x = 2, y = 3/4, label = "actor", color = "orange1") +
@@ -1341,7 +1341,7 @@ and we've been grappling with the relation between the grand mean $\alpha$ and t
1341
1341
1342
1342
For our first step, we'll introduce the models.
1343
1343
1344
-
### Intercepts-only models with one or two grouping variables
1344
+
### Intercepts-only models with one or two grouping variables.
1345
1345
1346
1346
If you recall, `b12.4` was our first multilevel model with the chimps data. We can retrieve the model formula like so.
1347
1347
@@ -1435,22 +1435,22 @@ print(b12.8)
1435
1435
1436
1436
Now we've fit our two intercepts-only models, let's get to the heart of this section. We are going to practice four methods for working with the posterior samples. Each method will revolve around a different primary function. In order, they are
1437
1437
1438
-
*`brms::posterior_samples()`
1439
-
*`brms::coef()`
1440
-
*`brms::fitted()`
1441
-
*`tidybayes::spread_draws()`
1438
+
*`brms::posterior_samples()`,
1439
+
*`brms::coef()`,
1440
+
*`brms::fitted()`, and
1441
+
*`tidybayes::spread_draws()`.
1442
1442
1443
1443
We've already had some practice with the first three, but I hope this section will make them even more clear. The `tidybayes::spread_draws()` method will be new, to us. I think you'll find it's a handy alternative.
1444
1444
1445
-
With each of the four methods, we'll practice three different model summaries.
1445
+
With each of the four methods, we'll practice three different model summaries:
1446
1446
1447
-
*Getting the posterior draws for the `actor`-level estimates from the `b12.7` model
1448
-
*Getting the posterior draws for the `actor`-level estimates from the cross-classified `b12.8` model, averaging over the levels of `block`
1449
-
*Getting the posterior draws for the `actor`-level estimates from the cross-classified `b12.8` model, based on `block == 1`
1447
+
*getting the posterior draws for the `actor`-level estimates from the `b12.7` model;
1448
+
*getting the posterior draws for the `actor`-level estimates from the cross-classified `b12.8` model, averaging over the levels of `block`; and
1449
+
*getting the posterior draws for the `actor`-level estimates from the cross-classified `b12.8` model, based on `block == 1`.
1450
1450
1451
1451
So to be clear, our goal is to accomplish those three tasks with four methods, each of which should yield equivalent results.
1452
1452
1453
-
### `brms::posterior_samples()`
1453
+
### `brms::posterior_samples()`.
1454
1454
1455
1455
To warm up, let's take a look at the structure of the `posterior_samples()` output for the simple `b12.7` model.
1456
1456
@@ -1521,7 +1521,7 @@ str(p3)
1521
1521
1522
1522
Again, I like this method because of how close the wrangling code within `transmute()` is to the statistical model formula. I wrote a lot of code like this in my early days of working with these kinds of models, and I think the pedagogical insights were helpful. But this method has its limitations. It works fine if you're working with some small number of groups. But that's a lot of repetitious code and it would be utterly un-scalable to situations where you have 50 or 500 levels in your grouping variable. We need alternatives.
1523
1523
1524
-
### `brms::coef()`
1524
+
### `brms::coef()`.
1525
1525
1526
1526
First, let's review what the `coef()` function returns.
Conversely, it can be a little abstract. Let's keep expanding our options.
1600
1600
1601
-
### `brms::fitted()`
1601
+
### `brms::fitted()`.
1602
1602
1603
1603
As is often the case, we're going to want to define our predictor values for `fitted()`.
1604
1604
@@ -1684,7 +1684,7 @@ str(f3)
1684
1684
1685
1685
Let's learn one more option.
1686
1686
1687
-
### `tidybayes::spread_draws()`
1687
+
### `tidybayes::spread_draws()`.
1688
1688
1689
1689
Up till this point, we've really only used the tidybayes package for plotting (e.g., with `geom_halfeyeh()`) and summarizing (e.g., with `median_qi()`). But tidybayes is more general; it offers a handful of convenience functions for wrangling posterior draws from a tidyverse perspective. One such function is `spread_draws()`, which you can learn all about in Matthew Kay's vignette, [*Extracting and visualizing tidy draws from brms models*](https://mjskay.github.io/tidybayes/articles/tidy-brms.html). Let's take a look at how we'll be using it.
0 commit comments