Class 7 · Simple Logistic Regression and Lab 6.2

STAT 517: Advanced Statistical Models · Fall 2026

This interactive companion follows the Class 7 notes and the detailed student script class07_simple_logistic_regression.R. It moves from probability and log-odds through fitting, inference, prediction, and the assigned-group event-definition lab.

Each WebR code box runs base R directly in your browser. Press Run Code, inspect the result, change something, and run it again. Run the cells in order because later cells reuse objects created earlier. The two public data files are included with this page; nothing needs to be installed.

Goals

  • Move among probability, odds, and log-odds
  • State the modeled event and predictor reference group before interpreting a fit
  • Interpret logistic slopes as odds ratios without confusing odds and risk
  • Use Wald tests and confidence intervals on the coefficient and odds-ratio scales
  • Obtain fitted probabilities and pointwise confidence intervals through the link scale
  • Explain how changing a binary event definition changes a logistic regression

1. Setup

The plotting helper keeps both multi-panel displays readable in an ordinary RStudio plot pane.

2. From probability to log-odds, and back

For an event probability \(p\), the odds are \(p/(1-p)\) and the log-odds are \(\log\{p/(1-p)\}\). In R, qlogis() computes the logit and plogis() computes its inverse, \(\operatorname{expit}(\eta)=e^\eta/(1+e^\eta)\).

Explain the difference between probability, odds, and log-odds. Then change p_example and check your explanation on a second value.

4. Framingham: define the event and reference group

The response records the ten-year coronary heart disease outcome. We model AtRisk as the event and use Female as the predictor reference group.

For a two-level factor response, binomial() models the probability of the second level. State that event before interpreting any coefficient or prediction.

5. Fit the binary-predictor model

The intercept is the fitted log-odds for the reference group. The maleMale coefficient is the difference in fitted log-odds between Male and Female patients. Write an interpretation of its exponentiated value in one sentence. An odds ratio describes a change in odds; it is not a risk ratio.

6. Wald test and confidence intervals

Test \(H_0:\beta_1=0\) against \(H_1:\beta_1\ne0\) and construct the corresponding 95% Wald intervals.

Which value represents no association on each interval scale? State the conclusion of the two-sided test at the 5% level.

7. Predictions for each group on two scales

type = "link" returns fitted log-odds and type = "response" returns the event probability. Check the probability and inverse-link columns against one another.

8. Confidence intervals for the event probability

Build each confidence interval on the link scale and then transform its endpoints.

These intervals quantify uncertainty about the event probability for a given group. An individual future outcome remains either 0 or 1.

9. Horseshoe crabs: one continuous predictor

The response satell counts satellite males and width is carapace width in centimeters. The worked event is having at least one satellite male.

Write the fitted equation on the log-odds scale. Width zero is outside the data, so the raw intercept has little practical use.

10. Optional: center width

The sample mean width rounds to 26.3 cm. Centering there gives the intercept a useful reference point while leaving the fitted probability curve unchanged. Uncomment the block to examine the centered model.

11. Wald inference for the width slope

Interpret the odds ratio and its interval for a one-centimeter increase in width. Keep the event definition and measurement unit in your sentence.

12. Fitted values for the observed crabs

Locate two crabs with the same width and compare their fitted probabilities. Why does an observed event not require its fitted probability to equal 1?

13. Predictions at specified widths

Explain the interval at 26.3 cm in terms of the crab’s event probability. The interval does not describe a range of individual 0/1 outcomes.

14. Probability curve and pointwise uncertainty

These intervals concern the mean event probability at each specified width. They are pointwise intervals, not a simultaneous 95% band for the entire curve.

15. Lab 6.2: the event is a choice

Enter your assigned group number from 1 through 6. This code constructs only your group’s event.

Group Event
1 satell >= 1
2 satell >= 2
3 satell >= 3
4 satell >= 4
5 satell >= 5
6 satell == 0

16. Fit and report your group’s model

Report the event rate, slope, odds ratio, and event probability at 26.3 cm. Use your group’s event definition when interpreting every number.

17. Compare three one-centimeter changes

After groups share their own rows, discuss:

  1. Group 6 compares with group 1. How are their event definitions related, and exactly how does that relationship affect their models?
  2. How do the odds ratios change as the threshold rises from groups 1 through 5? Why must the event definition accompany any reported odds ratio?
  3. Do the three one-centimeter steps produce the same probability change? What additional information is needed to translate an odds ratio into a probability change?