Skip to content

Commit 3028d7b

Browse files
ch 8 setup
1 parent 24e037c commit 3028d7b

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

_quarto.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ website:
1313
text: Causal Confounds
1414
- href: ch7ModelComparison.qmd
1515
text: Model Metrics
16+
- htrg: ch8_conditional.qmd
17+
text: Interactions
1618
format:
1719
html:
1820
theme: cosmo

ch8_conditional.qmd

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,42 @@ execute:
55
echo: false
66
warning: false
77
message: false
8+
cache: true
9+
cache.lazy: false
10+
fig-align: center
811
---
12+
13+
```{r setup}
14+
knitr::opts_chunk$set(fig.align = "center")
15+
16+
library(tidyverse)
17+
library(brms)
18+
library(bayesplot)
19+
library(tidybayes)
20+
library(patchwork)
21+
library(GGally)
22+
library(dagitty)
23+
library(ggdag)
24+
library(ggrepel)
25+
26+
library(rethinking)
27+
detach(package:rethinking, unload = T)
28+
data(milk)
29+
at <- c(-3, -2, -1, 0, 1, 2, 3)
30+
31+
32+
```
33+
34+
The Armstrong Whitworth A.W.38 Whitley was a frontline Royal Air Force bomber. During the second World War, the A.W.38 carried bombs and pamphlets into German territory. The A.W.38 has fierce natural enemies: artillery and interceptor fire. Many planes never returned from their missions. And those that survived had the scars to prove it. Most observers intuit that helping bombers means reducing the kind of damage we see on them, perhaps by adding armor to the parts of the plane that show the most damage.
35+
36+
Up-armoring the damaged portions of returning bombers did little good. Instead, improving the A.W.38 bomber meant armoring the undamaged sections. The evidence from surviving bombers is misleading, because it is conditional on survival. Bombers that returned home conspicuously lacked damage to the cockpit and engines. They got lucky. Bombers that never returned home were less so. To get the right answer, in either context, we have to realize that the kind of damage seen is conditional on survival.
37+
38+
![](plots/airplane.png){fig-align="center" width=50%}
39+
40+
Conditioning is one of the most important principles of statistical inference. Data, like the bomber damage, are conditional on how they get into our sample. Posterior distributions are conditional on the data. All model-based inference is conditional on the model. Every inference is conditional on something, whether we notice it or not.
41+
42+
Simple linear models frequently fail to provide enough conditioning, however. Every model so far in this book has assumed that each predictor has an independent association with the mean of the outcome. What if we want to allow the association to be conditional? For example, in the primate milk data from the previous chapters, suppose the relationship between milk energy and brain size varies by taxonomic group (ape, monkey, prosimian). This is the same as suggesting that the influence of brain size on milk energy is conditional on taxonomic group. The linear models of previous chapters cannot address this question.
43+
44+
To model deeper conditionality—where the importance of one predictor depends upon another predictor—we need interaction (also known as moderation). Interaction is a kind of conditioning, a way of allowing parameters (really their posterior distributions) to be conditional on further aspects of the data.
45+
46+
More generally, interactions are central to most statistical models beyond the cozy world of Gaussian outcomes and linear models of the mean. In generalized linear models (GLMs), even when one does not explicitly define variables as interacting, they will always interact to some degree. Multilevel models induce similar effects. Common sorts of multilevel models are essentially massive interaction models, in which estimates (intercepts and slopes) are conditional on clusters (person, genus, village, city, galaxy) in the data. Multilevel interaction effects are complex. They’re not just allowing the impact of a predictor variable to change depending upon some other variable, but they are also estimat- ing aspects of the distribution of those changes. This may sound like genius, or madness, or both. Regardless, you can’t have the power of multilevel modeling without it.

index.qmd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ Visualizations are what got me interested in statistics in the first place! I lo
5555

5656
**(4)️ [Model Metrics](ch7ModelComparison.qmd) 🎯 **
5757

58-
- Occam's razor 🪒,
58+
- Occam's razor, AIC , LOO, Oh my!
59+
60+
**(5) [Interactions](ch8_conditional.qmd) 🎨**
61+
62+
- Covariate effects conditional on other covariate effects!
5963

6064
## References
6165

0 commit comments

Comments
 (0)