Date: November 12, 2026
When the outcome is yes or no
lm() breaks when Y is 0 or 1glm(..., family = binomial), and turning its output into odds ratiosThe plan for class
| Lecture | ~50 min |
| 🚿 Activity | ~20 min |
| ☕ Break | |
| 📂 M2 work time | the rest of class |
M2 is due Sunday 11/15. Bring your questions.
The data: Cards Against Humanity’s Pulse of the Nation poll (2017). 1,000 U.S. adults, real survey questions, and some less serious ones.
lm()?So far every outcome has been a number on a scale. Lots of outcomes in psychology are binary:
Code it 1 = the thing happened and 0 = it didn’t. Then the mean of the 0s and 1s is the proportion of 1s, which is a probability.
lm()?A made-up class of 200: hours studied and whether they passed the exam.
[1] -0.1555193 1.1928485
We need a model whose predictions stay between 0 and 1 and bend near the edges.
ggplot(exam, aes(hours, passed)) +
geom_jitter(width = 0, height = 0.03, alpha = 0.4) +
geom_smooth(method = "lm", se = FALSE, color = "gray60", linetype = "dashed") +
geom_smooth(method = "glm", method.args = list(family = binomial),
se = FALSE, color = "#C8102E", linewidth = 1.3) +
labs(x = "Hours studied", y = "Probability of passing") +
theme_bw(base_size = 15)
Same data. The red curve is a logistic regression: never below 0, never above 1, steepest in the middle.
| Probability p | Odds = p / (1 − p) | Log-odds = ln(odds) |
|---|---|---|
| .10 | 0.11 (1 to 9) | −2.20 |
| .25 | 0.33 (1 to 3) | −1.10 |
| .50 | 1 (even) | 0 |
| .75 | 3 (3 to 1) | 1.10 |
| .90 | 9 (9 to 1) | 2.20 |
So logistic regression fits a straight line on the log-odds scale:
\[ \ln\left(\frac{p}{1-p}\right) = b_0 + b_1 X_1 + b_2 X_2 + \cdots \]
Ten people answer “Do you believe in ghosts?”
👻👻👻👻👻👻👻👻🙅🙅
| Probability | 8 of 10 = .80 |
| Odds | 8 believers to 2 = 4 |
| Log-odds | ln(4) = +1.39 |
🙅🙅🙅🙅🙅🙅🙅🙅👻👻
| Probability | 2 of 10 = .20 |
| Odds | 2 believers to 8 = 0.25 |
| Log-odds | ln(0.25) = −1.39 |
Because adding on the log-odds scale is multiplying the odds.
| Log-odds | Odds | Probability | ||
|---|---|---|---|---|
| 0 | 1 | .50 | ||
| 0 + 0.69 | → | 1 × 2 = 2 | → | .67 |
| 0.69 + 0.69 | → | 2 × 2 = 4 | → | .80 |
| 1.39 + 0.69 | → | 4 × 2 = 8 | → | .89 |
Important
One coefficient, three readings: +0.69 in log-odds = × 2 in odds = “it depends where you start” in probability.
Try 0, then ±1.39 (the two rooms), then ±4. Each step of 1 near the middle moves the probability a lot; out near the edges it barely moves.
Coefficients come out in log-odds, and nobody thinks in log-odds.
So we translate:
| Scale | How to get there | Read it as |
|---|---|---|
| Log-odds | what glm() gives you |
sign and p-value only |
| Odds ratio | exp(b) |
“the odds are multiplied by ___” |
| Probability | predict(..., type = "response") |
“a ___ has a __% chance” |
Important
Odds ratio = 1 means no effect. Above 1: higher odds. Below 1: lower odds. An OR of 0.40 means the odds are 60% lower, not that the probability is.
“Do you believe in ghosts?” (Yes / No)
n prop_believe
1 946 0.3773784
About 38% believe. (I dropped the 28 people who answered “Other” for gender. With n = 28, the estimate would be very noisy. In your own work, make that decision before you see the results, and report it.)
glm(): one new argument# A tibble: 2 × 5
term estimate std.error statistic p.value
<chr> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 0.0292 0.211 0.139 0.890
2 age -0.0109 0.00412 -2.63 0.00842
family = binomial is what makes it logistic. Leave it off and you’ve fit lm() again.Parameter | Odds Ratio | SE | 95% CI | z | p
------------------------------------------------------------------
(Intercept) | 1.03 | 0.22 | [0.68, 1.56] | 0.14 | 0.890
age | 0.99 | 4.08e-03 | [0.98, 1.00] | -2.63 | 0.008
OR = 0.989 per year: each year of age multiplies the odds of believing by 0.989, about 1% lower odds per year.
Per year is tiny. Per decade: exp(10 × −0.0109) = 0.90, so 10% lower odds for every 10 years older.
Before the model, the 2 × 2 table:
# A tibble: 2 × 5
gender n believe p odds
<fct> <int> <dbl> <dbl> <dbl>
1 Woman 476 232 0.487 0.951
2 Man 470 125 0.266 0.362
Odds ratio by hand: 0.362 / 0.951 = 0.38. Men have about 38% of the odds that women do.
Parameter | Odds Ratio | SE | 95% CI | z | p
----------------------------------------------------------------
(Intercept) | 0.95 | 0.09 | [0.79, 1.14] | -0.55 | 0.582
gender [Man] | 0.38 | 0.05 | [0.29, 0.50] | -6.94 | < .001
Same number. The odds ratio is just a ratio of two groups’ odds. The intercept (0.95) is the reference group’s odds: women.
Parameter | Odds Ratio | SE | 95% CI | z | p
--------------------------------------------------------------------
(Intercept) | 1.88 | 0.44 | [1.19, 2.98] | 2.70 | 0.007
age | 0.99 | 4.23e-03 | [0.98, 0.99] | -3.17 | 0.002
gender [Man] | 0.37 | 0.05 | [0.28, 0.48] | -7.14 | < .001
Same “holding constant” logic as multiple regression:
A 25-year-old woman. Plug her into the model, one scale at a time:
| Step | Woman, 25 | Man, 25 |
|---|---|---|
| Log-odds = b0 + bage × 25 (+ bman) | 0.630 + (-0.0136 × 25) = 0.29 | 0.29 + (-1.00) = -0.71 |
| Odds = elog-odds | e^0.29^ = 1.34 | e^-0.71^ = 0.49 |
| Probability = odds / (1 + odds) | 1.34 / 2.34 = .57 | 0.49 / 1.49 = .33 |
plogis() does the last two steps in one go: plogis(0.29) = 0.57.
Men have 0.37 times the odds. What that does to the probability depends on where you start:
| Woman’s probability | Same-age man (× OR on the odds) | Change (percentage points) |
|---|---|---|
| .05 | .02 | -3 |
| .20 | .08 | -12 |
| .50 | .27 | -23 |
| .80 | .59 | -21 |
| .95 | .87 | -8 |
The odds ratio is the same in every row. The change in probability is biggest near .50 and tiny near 0 or 1, because that’s where the S-curve is steepest.
Tip
This is why a Results section reports the odds ratio (one number that’s true everywhere), and the Discussion uses predicted probabilities at values of X that matter.
Odds ratios are for the Results section. Probabilities are for humans.
# A tibble: 4 × 3
age gender p_believe
<dbl> <chr> <dbl>
1 25 Woman 0.57
2 25 Man 0.33
3 65 Woman 0.44
4 65 Man 0.22
A 25-year-old woman: 57%. A 65-year-old man: 22%.
Warning
type = "response" matters. Leave it off and predict() returns log-odds.

The lines look almost straight here because the probabilities stay in the middle of the range. The S only shows up near 0 and 1.
Last week’s block comparison works here too, with one change:
Analysis of Deviance Table
Model 1: ghost ~ age
Model 2: ghost ~ age + gender
Resid. Df Resid. Dev Df Deviance Pr(>Chi)
1 944 1246.9
2 943 1193.8 1 53.136 0.0000000000003113 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Logistic regression has no F test. It compares deviance (the logistic version of leftover error) with a χ² test. Adding gender reduced deviance by 53.1, χ²(1) = 53.14, p < .001.
We used logistic regression to predict belief in ghosts (1 = yes) from age and gender (N = 946; 37.7% believed). Holding age constant, men had lower odds of believing than women, OR = 0.37, 95% CI [0.28, 0.48], p < .001. Each additional year of age was associated with slightly lower odds, OR = 0.987, 95% CI [0.978, 0.995], p = .002. For example, the model predicts a 57% probability of believing for a 25-year-old woman and 22% for a 65-year-old man.
Tip
Report the odds ratio with its CI, then give at least one predicted probability so readers can tell how big the effect is.
| Linear | Logistic | |
|---|---|---|
| Outcome | Continuous | Binary (0/1) |
| R | lm(y ~ x) |
glm(y ~ x, family = binomial) |
| Coefficient | Change in Y | Change in log-odds |
| Easier to read | b itself | exp(b) = odds ratio |
| Compare models | anova() → F |
anova(test = "Chisq") → χ² |
| Fit | R² | Tjur’s R² (or another pseudo-R²) |
| Explain it with | Predicted Y | Predicted probability |
Tip
~20 min · Pairs · Same CAH data
“Is it acceptable to pee in the shower?”
Who says yes? Age, gender, and a predicted probability for two people.
Due Sunday 11/15. Use the rest of class. I’ll come around.
M2 checklist (from Week 11)
Is your outcome binary? Then today’s model is your model. Ask me about it while you’re here.
📂 M2, due Sunday 11/15
📋 Lab 11: Logistic Regression, due Tuesday 11/17 at 11:59pm
📖 Readings for Mixed/Multilevel Models:
💾 Class Check next week