explain why logistic regression is used for a yes/no outcome;
interpret coefficients as odds ratios;
explain what a p-value does—and does not—tell us;
use an effect estimate, confidence interval, and clinical context together;
recognize when clustered medical data need a mixed-effects model.
The medical question
Imagine a fictional study of 300 patients in 10 clinics. Each patient received either a new treatment (treatment = 1) or standard care (treatment = 0). The outcome recovered is 1 if the patient recovered within 30 days and 0 otherwise. We also record age because age may affect recovery.
Our main question is:
After accounting for age, is the new treatment associated with 30-day recovery?
The data below are simulated for teaching. They do not describe real patients or establish that any real treatment works.
Mathematics: generate one binary outcome per patient
Let \(Y_i\) denote recovery for patient \(i\), \(T_i\) denote treatment, and \(A_i=\text{Age}_i-60\) denote centered age. A binary outcome follows a Bernoulli distribution:
treatment recovery_proportion
1 Standard care 0.3066667
2 New treatment 0.4133333
This is an unadjusted comparison. It does not account for age, and it treats all patients as independent even though patients from one clinic may resemble one another.
Why not ordinary linear regression?
For a binary outcome, a straight-line model can predict impossible values below 0 or above 1. Logistic regression instead models the log-odds:
where \(p_i\) is patient \(i\)’s probability of recovery. Centering age at 60 makes the intercept refer to a 60-year-old patient rather than a hypothetical zero-year-old patient.
Because observations are Bernoulli, the likelihood for \(\boldsymbol\beta=(\beta_0,\beta_1,\beta_2)\) is
Logistic regression chooses the maximum-likelihood estimate \(\widehat{\boldsymbol\beta}=\arg\max_{\boldsymbol\beta}\ell(\boldsymbol\beta)\). Unlike ordinary least squares, this optimization has no simple closed-form solution, so glm() solves it iteratively.
An OR of 1 means equal odds of recovery in the two treatment groups.
An OR above 1 means higher odds with the new treatment.
An OR below 1 means lower odds with the new treatment.
For example, OR = 1.50 means 50% higher odds, not 50 percentage points higher probability and not necessarily 50% higher risk.
For age, the OR is for each additional year because age is measured in years. An age OR of 0.96 would mean about 4% lower odds per additional year: \(100(0.96-1)=-4\%\). Centering age changes the intercept, but it does not change the age slope, its odds ratio, or its p-value.
Odds are not probabilities
The same odds ratio can correspond to different changes in probability, depending on the starting risk. Predicted probabilities make the result more concrete. Here are predictions for a 60-year-old patient:
For treatment value \(t\) and centered age \(a\), first calculate
group predicted_recovery
1 Standard care 0.3029234
2 New treatment 0.4166685
These model-based probabilities are often more understandable to patients and clinicians than odds ratios. They are estimates, not guarantees for an individual patient.
R reports a two-sided Wald p-value. Informally, it asks:
If the treatment truly had no association with recovery, and the model’s assumptions were correct, how surprising would an estimate at least this far from zero be because of random sampling variation?
A small p-value means the observed estimate is relatively incompatible with that null model. It is not:
the probability that the null hypothesis is true;
the probability that the result happened “by chance”;
the probability that the treatment works;
the size or clinical importance of the effect;
proof that treatment causes recovery.
For example, p = 0.03 does not mean there is a 3% probability that no treatment effect exists. It describes the data under a null hypothesis; it does not assign a probability to that hypothesis.
How the p-value is calculated
For each coefficient, R divides the estimate by its standard error:
\[z=\frac{\widehat\beta}{SE(\widehat\beta)}.\]
It then compares \(|z|\) with a standard normal distribution. We can reproduce the treatment p-value:
where \(Z\sim N(0,1)\) under the large-sample null approximation and \(\Phi\) is the standard normal cumulative distribution function. The R functions pnorm() and abs() translate this equation directly.
The standard error reflects uncertainty. Larger samples generally produce smaller standard errors, so a tiny effect can have a small p-value in a very large study. Conversely, a clinically important estimated effect can have a large p-value in a small, imprecise study.
Reading p-values with confidence intervals
At a conventional two-sided 5% significance level, these statements usually agree for the same coefficient and method:
p < 0.05;
the 95% confidence interval for the log-odds coefficient excludes 0;
the 95% confidence interval for the odds ratio excludes 1.
The confidence interval is more informative because it shows both the estimated effect and its precision. A wide interval means many effect sizes remain compatible with the data.
Avoid saying “there is no effect” merely because p >= 0.05. A better statement is: “The study did not provide strong evidence against no association; the confidence interval shows which beneficial or harmful effects remain plausible.”
A responsible decision process
Do not let p < 0.05 make the decision by itself. Before seeing the data, define the primary outcome, model, significance level, and a minimum clinically important effect. Then ask:
What is the direction and size? Read the odds ratio and predicted probabilities.
How uncertain is it? Read the confidence interval, not only the p-value.
Is it clinically meaningful? Compare the estimate and interval with a pre-specified clinical threshold.
Is the design credible? Consider randomization, missing data, confounding, measurement quality, and whether assumptions are reasonable.
Were many hypotheses tested? Selective reporting and multiple testing can create small p-values even when no real effects exist.
Do benefits outweigh harms, costs, and patient preferences? Statistical evidence is only one part of a medical decision.
A compact conclusion template is:
After adjustment for age, the estimated treatment odds ratio was [OR] (95% CI [lower, upper], p = [p]). This is [compatible/not compatible] with no association at the pre-specified 5% level. The estimated probability difference for a 60-year-old was [difference] percentage points. Clinical importance should be judged against the pre-specified threshold and study limitations.
Use the next chunk to fill in those values.
For the 60-year-old example, the model-based absolute effect is the probability difference
The ordinary model assumes that, after accounting for treatment and age, all observations are independent. But patients treated in the same clinic may share staff, procedures, referral patterns, or local populations. Their outcomes may therefore be correlated.
Ignoring that correlation can make standard errors too small and p-values too optimistic. The second lesson uses the same data and adds a clinic-level random intercept.
Check your understanding
If the treatment OR is 1.7, does that mean recovery probability rose by 70 percentage points? Why not?
If p = 0.08, can you conclude that treatment has no effect?
Which communicates more information: a p-value alone, or an odds ratio with a confidence interval? Why?
What part of this study makes the independence assumption questionable?