Lecture%203%20logistic%20regression

Table of contents

  1. Logistic regression predictions and extensions
  2. Missing data
  3. Examples
  4. What we’ve learned so far
  5. Test yourself
  6. Coming up

1. Logistic regression predictions and extensions

1.1 Recap: Modelling a binary outcome

Logistic regression is employed when the outcome variable is binary, typically coded as 0 (absence) or 1 (presence). This type of data originates from a binomial or Bernoulli distribution.

The model utilizes a logit link function to connect the probability of the outcome to a linear combination of predictor variables, with parameters estimated via maximum likelihood 3.

  • Binary data distribution: Y follows a Binomial or Bernoulli distribution, Y∼B(n,p)Y \sim B(n, p), where P(Y=y)=(ny)py(1−p)n−yP(Y=y) = \binom{n}{y} p^y (1-p)^{n-y}.
  • Logit link function: The core of logistic regression relates the log odds of the outcome to a linear predictor: log⁡(p1−p)=logit(p)=β0+β1X1+⋯+βkXk\log\left(\frac{p}{1-p}\right) = \text{logit}(p) = \beta_0 + \beta_1X_1 + \dots + \beta_kX_k 3.

1.2 Recap: Simple logistic regression one continuous X

In simple logistic regression with one continuous predictor (X1X_1), the log odds of the outcome are linearly related to X1X_1. The intercept (β0\beta_0) represents the expected log odds when X1=0X_1=0, and its exponentiation (exp⁡(β0)\exp(\beta_0)) gives the expected odds.

The coefficient β1\beta_1 quantifies the change in log odds per unit increase in X1X_1, while exp⁡(β1)\exp(\beta_1) represents the odds ratio, indicating the multiplicative change in odds 4.

📝 For a male (where SexFemale=0\text{Sex}_{\text{Female}}=0) in the model log⁡(p^(hypertension=yes)1−p^(hypertension=yes))=−1.12−0.93×SexFemale\log\left(\frac{\hat{p}(\text{hypertension} = \text{yes})}{1-\hat{p}(\text{hypertension} = \text{yes})}\right) = -1.12 - 0.93 \times \text{Sex}_{\text{Female}}, the log odds of hypertension is −1.12-1.12 12.

1.3 Recap: Simple logistic regression one categorical X

When the predictor (X1X_1) is categorical, the intercept (β0\beta_0) represents the expected log odds of the outcome in the reference group. The coefficient β1\beta_1 represents the difference in log odds between a specific category and the reference category, and its exponentiation (exp⁡(β1)\exp(\beta_1)) is the odds ratio comparing that category to the reference 5.

📝 For a male aged 59 in the model logit(p^(hypertension=yes))=−3.22+0.05×Age−1.05×SexFemale\text{logit}(\hat{p}(\text{hypertension} = \text{yes})) = -3.22 + 0.05 \times \text{Age} - 1.05 \times \text{Sex}_{\text{Female}}, the log odds of hypertension is −3.22+0.05×59−1.05×0=−0.27-3.22 + 0.05 \times 59 - 1.05 \times 0 = -0.27 13.

1.4 Recap: Multiple logistic regression

Multiple logistic regression extends the model to include multiple predictor variables (X1,…,XkX_1, \dots, X_k), either to enhance predictive accuracy or to control for confounding factors. The intercept (β0\beta_0) represents the expected log odds when all predictors are zero.

Each coefficient βk\beta_k represents the adjusted change in log odds for a unit increase in XkX_k, holding all other variables constant 6.

1.5 Recap: logistic regression inference

Hypothesis testing for a coefficient βk\beta_k typically involves testing H0:βk=0H_0: \beta_k = 0 against HA:βk≠0H_A: \beta_k \neq 0. Confidence intervals (CIs) for βk\beta_k are constructed using the estimated coefficient and its standard error.

For large samples, the Wald 95% CI for βk\beta_k is β^k±1.96×SE(β^k)\hat{\beta}_k \pm 1.96 \times \text{SE}(\hat{\beta}_k) on the log odds scale. Exponentiating the bounds of this CI provides the CI for the odds ratio 7.

1.6 Model predictions

Fitted logistic regression models can be used to generate predictions on various scales: the log odds scale, the odds scale, and the probability scale. Predictions on the log odds scale are a direct result of the linear predictor β^0+β^1X1+⋯+β^kXk\hat{\beta}_0 + \hat{\beta}_1X_1 + \dots + \hat{\beta}_kX_k 8.

1.7 Probability prediction

To predict probabilities, the odds are first calculated as odds=exp⁡(β^0+β^1X1+⋯+β^kXk)\text{odds} = \exp(\hat{\beta}_0 + \hat{\beta}_1X_1 + \dots + \hat{\beta}_kX_k). The probability p^\hat{p} is then derived from the odds using the formula p^=odds1+odds\hat{p} = \frac{\text{odds}}{1 + \text{odds}}, which simplifies to p^=exp⁡(β^0+⋯+β^kXk)1+exp⁡(β^0+⋯+β^kXk)\hat{p} = \frac{\exp(\hat{\beta}_0 + \dots + \hat{\beta}_kX_k)}{1 + \exp(\hat{\beta}_0 + \dots + \hat{\beta}_kX_k)}.

This is equivalent to applying the inverse logit function, p=exp⁡(x)1+exp⁡(x)p = \frac{\exp(x)}{1+\exp(x)}, where xx is the linear predictor 9.

The inverse logit function ensures that predicted probabilities are always between 0 and 1. However, it is crucial to note that probabilities do not change linearly with predictor variables; the relationship is sigmoidal 10.

This line graph illustrates the sigmoid function, showing how the output probability approaches 1 as the input increases and 0 as the input decreases.

1.8 Predictions: example 1

For the model logit(p^(hypertension=yes))=−3.46+0.05×Age\text{logit}(\hat{p}(\text{hypertension} = \text{yes})) = -3.46 + 0.05 \times \text{Age}, predictions for a 59-year-old individual involve calculating the log odds, odds, and probability of hypertension 11.

1.9 Predictions: example 2

For the model log⁡(p^(hypertension=yes)1−p^(hypertension=yes))=−1.12−0.93×SexFemale\log\left(\frac{\hat{p}(\text{hypertension} = \text{yes})}{1-\hat{p}(\text{hypertension} = \text{yes})}\right) = -1.12 - 0.93 \times \text{Sex}_{\text{Female}}, predictions for a male (where SexFemale=0\text{Sex}_{\text{Female}}=0) involve calculating the log odds, odds, and probability of hypertension 12.

1.10 Predictions: example 3

Using the model logit(p^(hypertension=yes))=−3.22+0.05×Age−1.05×SexFemale\text{logit}(\hat{p}(\text{hypertension} = \text{yes})) = -3.22 + 0.05 \times \text{Age} - 1.05 \times \text{Sex}_{\text{Female}}, one can predict the log odds, odds, and probability of hypertension for a male aged 59 13.

The image displays a logistic regression equation and a series of calculations to predict the probability of hypertension.

1.11 Log odds and odds are constant but probability is not

While the log odds and odds change linearly or multiplicatively with predictor variables, the probability changes in a non-linear, sigmoidal fashion. This means that the absolute change in probability for a unit change in a predictor is not constant across the range of the predictor 14.

This scatter plot shows the relationship between age and the logit of hypertension, with a fitted regression line.

📝 For a 59-year-old individual in the model logit(p^(hypertension=yes))=−3.46+0.05×Age\text{logit}(\hat{p}(\text{hypertension} = \text{yes})) = -3.46 + 0.05 \times \text{Age}, the log odds of hypertension is −3.46+0.05×59=−0.51-3.46 + 0.05 \times 59 = -0.51 11.

1.12 Log odds and odds are constant but probability is not example

This example involves comparing the difference in log odds and the ratio of odds for hypertension between ages 1 vs 0 and ages 19 vs 18, highlighting the non-constant change in probability 15.

1.13 Predicting the outcome with software

Statistical software can directly generate predictions on the log odds scale (using type = "link") or the probability scale (using type = "response") for a range of predictor values 16.

2. Missing data

2.1 Missing data

Logistic regression models, by default, often perform complete case analysis, meaning only observations with complete data for all variables are used. Advanced methods for handling missing data are typically covered in subsequent courses 17.

2.2 Transforming variables

Variable transformations involve creating new variables from existing ones. This can include:

  • Categorization or combination: Creating new variables by grouping or combining existing ones (e.g., calculating BMI from weight and height, or defining hypertension based on systolic blood pressure thresholds).
  • Scaling or standardization: Applying Z-score normalization or Min-Max normalization.
  • Algebraic operations: Multiplying or dividing continuous variables by a factor to change the scale of interpretation (e.g., converting kilometers to meters, or per 1000 units to per 1 unit) 18.

2.3 Transforming variables example

To interpret the effect of age on hypertension over a 10-year period rather than a 1-year period, the coefficient for age in the model logit(p^(hypertension=yes))=−3.22+0.05×Age−1.05×SexFemale\text{logit}(\hat{p}(\text{hypertension} = \text{yes})) = -3.22 + 0.05 \times \text{Age} - 1.05 \times \text{Sex}_{\text{Female}} would need to be multiplied by 10 19.

📝 To interpret the 10-year effect of age on hypertension, multiply the coefficient for age in the model logit(p^(hypertension=yes))=−3.22+0.05×Age−1.05×SexFemale\text{logit}(\hat{p}(\text{hypertension} = \text{yes})) = -3.22 + 0.05 \times \text{Age} - 1.05 \times \text{Sex}_{\text{Female}} by 10 19.

2.4 Linear separability

Linear separability, also known as complete or quasi-complete separation, occurs when the outcome variable can be perfectly or almost perfectly divided into two classes based on the predictor values. This situation can cause maximum likelihood estimation of the model parameters to fail 20.

2.5 Linear separability example

This section illustrates the concept of linear separability using a dataset where the outcome can be clearly distinguished by predictor values 21.

3. Examples

3.1 Example 2: factors associated with death from laryngeal cancer

This example involves predicting death from laryngeal cancer (1=dead, 0=alive) using cancer stage (1-4), age at diagnosis, and year of diagnosis as predictors. The tasks include writing the fitted equation, providing a confidence interval for the effect of stage 2 on the odds of death, interpreting the effects of stages 3 and 4, interpreting the effect of the year of diagnosis, and calculating the probability of death for a specific individual 22.

Mathematical calculations for confidence intervals and probability of cancer, involving logistic regression coefficients and exponentiation.

3.2 Example 3: is the weather going to be sunny?

The model logit(p^(weather=sunny))=1.19−0.33×Rainyes−0.02×Wind(kph)\text{logit}(\hat{p}(\text{weather} = \text{sunny})) = 1.19 - 0.33 \times \text{Rain}_{\text{yes}} - 0.02 \times \text{Wind}(\text{kph}) is used to predict sunny weather. Questions focus on interpreting the effects of rain and wind speed on the odds of sunny weather, calculating the expected log odds and odds of sunny weather under specific conditions, and calculating the probability of sunny weather 23.

📝 For a caregiver working 40 hours per week for someone with cognitive impairment, the odds of distress are 2.19 times higher than for a caregiver with no hours of care and no cognitive impairment 24.

3.3 Example 4: cognitive impairment and caregiver distress

This example uses multiple logistic regression to predict caregiver distress. The predictors are hours of care per week and cognitive impairment status (No/Yes).

The tasks involve writing the fitted equation, interpreting the effect of a 10-hour increase in care per week on the odds of distress, and calculating the odds and probability of distress for a caregiver working 40 hours per week for someone with cognitive impairment 24.

PredictorOR95% CI
Intercept0.750.60, 0.93
Hours of care per week1.021.00, 1.04
Cognitive impairment: NoRef-
Cognitive impairment: Yes2.191.42, 3.37

4. What we’ve learned so far

4.1 Summary of key concepts

The covered topics include the fundamental aspects of binary data analysis using logistic regression. Key concepts encompass the rationale for employing logistic regression, its application in simple and multiple regression scenarios, and the process of making outcome predictions across different scales (log odds, odds, probability).

The non-linear relationship between probability and predictors, facilitated by the inverse logit function, and essential model considerations have also been addressed 25.

5. Test yourself

5.1 Self-assessment of logistic regression skills

Students should be proficient in making predictions from logistic regression models across different scales (log odds, odds, probability). Understanding and interpreting transformed variables, particularly those resulting from algebraic operations, is crucial.

Furthermore, a solid grasp of linear separability and its implications for model estimation is expected 26.

  • Making predictions: Ability to calculate and interpret predictions on the log odds, odds, and probability scales from a fitted logistic regression model.
  • Interpreting transformed variables: Understanding how variable transformations, especially algebraic operations, affect the interpretation of model coefficients and predictions.
  • Linear separability: Comprehending the concept of linear separability and its potential to cause estimation issues in logistic regression 26.

6. Coming up

6.1 Future topics in logistic regression

Upcoming lectures will delve into the assumptions underlying logistic regression models, methods for checking these assumptions, and assessing overall model fit. The curriculum will also cover techniques for comparing different models, converting predicted probabilities back to the original outcome scale (0 or 1), and evaluating the predictive power of the models 27.

© 2026 Maeve. All rights reserved. This content is protected by copyright.

See also