Logistic Regression Inferential Statistics Binary Outcomes 32 min read September 15, 2026
BY: Statistics Fundamentals Team
Reviewed By: Minsa A (Senior Statistics Editor)

Logistic Regression Examples: Step-by-Step Calculations & Interpretation

A doctor predicts whether a patient has diabetes based on glucose levels and BMI. A bank estimates the probability a loan applicant defaults. A marketer models which customers will click a promotional email. Each situation calls for logistic regression: the outcome is binary, the goal is a probability, and a straight line would produce predictions below zero or above one.

This guide walks through four complete worked examples with full arithmetic, covers odds ratios, probability conversion, confusion matrices, ROC curves, and model diagnostics, and includes working code for R, Python, SPSS, and Stata. The interactive calculator below lets you enter your own binary-outcome data and get fitted probabilities, coefficients, and classification results.

What You'll Learn
  • ✓ What logistic regression is and when to use it instead of linear regression
  • ✓ Four complete worked examples: exam pass rate, disease diagnosis, customer purchase, and loan approval
  • ✓ How to convert log-odds to probability step by step
  • ✓ How to interpret odds ratios correctly (and the mistakes people make)
  • ✓ Confusion matrix, sensitivity, specificity, precision, and ROC-AUC
  • ✓ Logistic regression in R, Python, SPSS, and Stata
  • ✓ Model assumptions, diagnostics, and common errors

What Is Logistic Regression?

Definition: Binary Logistic Regression
Logistic regression is a statistical model that estimates the probability of a binary outcome (such as pass/fail, disease/no disease, or purchase/no purchase). Rather than predicting the outcome directly, it models the log-odds of the outcome as a linear combination of predictors, then transforms the result into a probability between 0 and 1 using the logistic function.
logit(p) = log(p / 1-p) = β₀ + β₁X₁ + ... + βₖXₖ

The word "logistic" refers to the logistic function (sometimes called the sigmoid function), which takes any real number and maps it to the interval (0, 1). That property is what makes logistic regression suitable for binary outcomes: no matter how large or small the linear predictor is, the fitted probability stays between zero and one.

Logistic regression is part of the generalized linear model family. The underlying theory connects to inferential statistics and probability. For related background, see the main logistic regression page, or contrast it with simple linear regression and multiple linear regression.

🏠

Healthcare

Predict disease presence or absence from clinical measurements and patient history.

📈

Finance

Model loan default, credit card fraud, or stock market direction (up/down).

💅

Marketing

Estimate purchase probability, email click-through, or churn from customer data.

🎓

Education

Predict pass/fail, dropout risk, or program completion from student characteristics.

The Logistic Function and Logistic Regression Equation

The logistic function converts any real number into a probability. If the linear predictor is called η (eta), then:

Logistic (Sigmoid) Function
p = 1 / (1 + e)
p = predicted probability (between 0 and 1) η = β₀ + β₁X₁ + ... + βₖXₖ (linear predictor) e = Euler's number ≈ 2.71828

The S-Shaped Logistic Curve

0 0.5 1.0 -6 0 +6 η=0, p=0.5 p approaches 1 p approaches 0 Linear Predictor (η)

The full logistic regression equation is written two ways. The log-odds form is the standard model equation; the probability form shows what the model actually predicts:

Log-Odds Form (Model Equation)
logit(p) = log(p/1−p) = β₀ + β₁X₁ + β₂X₂ + ... + βₖXₖ
log(p/1−p) = log-odds (logit of p) β₀ = intercept β₁...βₖ = predictor coefficients X₁...Xₖ = predictor values

Probability, Odds, and Log-Odds

One of the most important things to get right in logistic regression is understanding three related but distinct concepts. Many interpretation mistakes come from treating odds as if they were probabilities, or treating odds ratios as if they were probability ratios.

Conversion Example

From Probability to Odds to Log-Odds

1

Start with probability p = 0.80
The event occurs 80% of the time under the model.

2

Calculate odds: Odds = p / (1 − p) = 0.80 / 0.20 = 4.00
The event is 4 times more likely to occur than not occur.

3

Calculate log-odds: logit(0.80) = ln(4.00) ≈ 1.386
This is what the linear predictor η equals when p = 0.80.

4

Reverse: log-odds back to probability
p = 1 / (1 + e−1.386) = 1 / (1 + 0.25) = 1 / 1.25 = 0.80

Probability (p)Odds (p / 1−p)Log-Odds (logit)
0.100.111−2.197
0.200.250−1.386
0.300.429−0.847
0.501.0000.000
0.702.3330.847
0.804.0001.386
0.909.0002.197
💡
Key Point

When p = 0.50, the odds equal 1.00 and the log-odds equal 0. The logistic curve always passes through the point where η = 0 and p = 0.5.

What Is an Odds Ratio in Logistic Regression?

Each coefficient in a logistic regression model represents the change in log-odds for a one-unit increase in that predictor, holding all other predictors constant. Exponentiating the coefficient gives the odds ratio (OR):

Odds Ratio Formula
OR = eβ
OR = odds ratio β = logistic regression coefficient e = Euler's number ≈ 2.71828
OR > 1
Higher odds of outcome
A one-unit increase in the predictor is associated with higher odds of the outcome, holding others constant.
OR = 1
No association
The predictor shows no linear association with the log-odds of the outcome in this model.
OR < 1
Lower odds of outcome
A one-unit increase in the predictor is associated with lower odds of the outcome, holding others constant.
Common Mistake

An OR of 2 does NOT mean the probability doubles. It means the odds are twice as high. At p = 0.50 (odds = 1), doubling the odds gives odds = 2, which corresponds to p ≈ 0.67, not p = 1.0.

Odds Ratio Calculation Example

OR Calculation

Interpreting Two Coefficients

1

Coefficient β₁ = 0.693 (study hours)
OR = e0.6932.00

Interpretation: Each additional study hour is associated with approximately twice the odds of passing the exam, holding other model variables constant.

2

Coefficient β₂ = −0.693 (absences)
OR = e−0.6930.50

Interpretation: Each additional absence is associated with approximately half the odds of passing, holding other model variables constant. This is a 50% reduction in the odds, not a 50% reduction in probability.

Example 1: Predicting Whether a Student Passes an Exam

This example uses a small dataset to walk through every step: from raw data to fitted equation to predicted probability to classification. The outcome is binary (Pass = 1, Fail = 0). The two predictors are study hours per week and attendance percentage.

StudentStudy Hours (X₁)Attendance % (X₂)Pass (Y)
12600
23650
34700
45721
56751
67781
78801
85680
99851
1010901
113620
127821

12 students: 8 passed (Y=1), 4 failed (Y=0).

Fitted Model

Applying maximum likelihood estimation to the dataset above yields (illustrative of a model fitted to this data):

Fitted Logistic Regression Model: Exam Pass
logit(p) = −12.4 + 0.75 × StudyHours + 0.10 × Attendance
Intercept β₀ = −12.4 Study Hours β₁ = 0.75 → OR = e⁰·⁷⁵ ≈ 2.12 Attendance β₂ = 0.10 → OR = e⁰·¹⁰ ≈ 1.11

Step-by-Step: Predicting a New Student's Probability

Prediction: Student A

Study Hours = 7, Attendance = 78%

1

Calculate the linear predictor η:
η = −12.4 + (0.75 × 7) + (0.10 × 78) = −12.4 + 5.25 + 7.8 = 0.65

2

Convert log-odds to probability:
p = 1 / (1 + e−0.65) = 1 / (1 + 0.522) = 1 / 1.522 ≈ 0.657

3

Apply the classification threshold (0.50):
0.657 > 0.50, so predicted class = Pass (Y = 1)

4

Interpret the coefficient for study hours:
OR = e0.75 ≈ 2.12. Each additional study hour is associated with approximately 2.12 times the odds of passing, holding attendance constant.

✓ The fitted model estimates a 65.7% probability of passing for a student with 7 study hours and 78% attendance. At a 0.50 threshold, this student is classified as likely to pass.

Prediction: Student B

Study Hours = 3, Attendance = 62%

1

η = −12.4 + (0.75 × 3) + (0.10 × 62)
= −12.4 + 2.25 + 6.20 = −3.95

2

p = 1 / (1 + e−(−3.95)) = 1 / (1 + e3.95)
= 1 / (1 + 52.46) ≈ 0.019

3

0.019 < 0.50, so predicted class = Fail (Y = 0)

✓ Estimated probability of passing is only 1.9%. At a 0.50 threshold, this student is classified as likely to fail.

Example 2: Medical Diagnosis (Disease Present or Absent)

A clinical researcher models whether a patient tests positive for a metabolic condition, using three predictors: age, blood pressure, and smoking status. Smoking is a binary predictor (0 = non-smoker, 1 = smoker).

Fitted Model: Disease Diagnosis
logit(p) = −9.2 + 0.04 × Age + 0.03 × BP + 1.12 × Smoker
Age coefficient = 0.04 → OR ≈ 1.04 BP coefficient = 0.03 → OR ≈ 1.03 Smoker coefficient = 1.12 → OR ≈ 3.06
Medical Example

Patient: Age = 55, BP = 140 mmHg, Smoker = 1

1

η = −9.2 + (0.04 × 55) + (0.03 × 140) + (1.12 × 1)
= −9.2 + 2.2 + 4.2 + 1.12 = −1.68

2

p = 1 / (1 + e1.68) = 1 / (1 + 5.366) ≈ 0.157

3

Interpret the smoking coefficient:
OR = e1.12 ≈ 3.06. Smokers in this model have approximately 3.06 times the odds of testing positive compared to non-smokers of the same age and blood pressure. This association does not prove that smoking causes the condition.

✓ The fitted model estimates a 15.7% probability of testing positive for a 55-year-old smoker with BP of 140. Note that "associated with" language is appropriate here; the study design determines whether causal conclusions are warranted.

Example 3: Customer Purchase Prediction

An e-commerce company fits a logistic regression model to predict whether a website visitor will complete a purchase. The three predictors are: number of website visits in the past 30 days, number of previous purchases, and whether a discount was offered (0 = no, 1 = yes).

Fitted Model: Customer Purchase
logit(p) = −4.8 + 0.15 × Visits + 0.55 × PriorPurchases + 1.30 × Discount
Visits OR = e⁰·¹⁵ ≈ 1.16 Prior Purchases OR = e⁰·⁵⁵ ≈ 1.73 Discount OR = e¹·³⁰ ≈ 3.67
Business Example

Customer A: 8 visits, 3 prior purchases, discount offered

1

η = −4.8 + (0.15 × 8) + (0.55 × 3) + (1.30 × 1)
= −4.8 + 1.2 + 1.65 + 1.30 = −0.65

2

p = 1 / (1 + e0.65) = 1 / (1 + 1.916) ≈ 0.343

3

Interpret discount coefficient:
OR = e1.30 ≈ 3.67. Customers who received a discount have approximately 3.67 times the odds of purchasing compared to those who did not, holding visits and prior purchases constant.

✓ Estimated purchase probability: 34.3%. At a 0.50 threshold, this customer is predicted not to purchase. The business might lower the threshold to catch more potential buyers at the cost of more false positives.

Example 4: Loan Approval Probability

A financial institution uses logistic regression to estimate whether a loan applicant will be approved (Y = 1) or declined (Y = 0). The three predictors are: annual income (thousands), debt-to-income ratio, and credit score.

Fitted Model: Loan Approval
logit(p) = −15.0 + 0.06 × Income + (−0.30) × DebtRatio + 0.018 × CreditScore
Income OR = e⁰·⁰⁶ ≈ 1.062 DebtRatio OR = e⁻⁰·³ ≈ 0.741 CreditScore OR = e⁰·⁰¹⁸ ≈ 1.018
Finance Example

Applicant: Income = $75k, Debt Ratio = 28%, Credit Score = 720

1

η = −15.0 + (0.06 × 75) + (−0.30 × 28) + (0.018 × 720)
= −15.0 + 4.5 − 8.4 + 12.96 = 4.06

2

p = 1 / (1 + e−4.06) = 1 / (1 + 0.017) ≈ 0.983

3

Interpret debt ratio coefficient:
OR = e−0.30 ≈ 0.741. A one-unit increase in the debt-to-income ratio is associated with approximately 26% lower odds of approval, holding income and credit score constant. (1 − 0.741 = 0.259, so about 26% lower.)

✓ Estimated approval probability: 98.3%. This applicant is classified as approved at any reasonable threshold. This page uses an educational model; real lending decisions require validation, fairness assessment, and domain expertise.

Interactive Logistic Regression Calculator

The calculator below lets you convert log-odds to probability, compute odds from probability, or estimate fitted probability using a simple single-predictor logistic equation. For full multi-predictor MLE on your own data, software such as R, Python, or SPSS is recommended.

Logistic Regression Calculator

-
Probability
-
Odds
-
Log-Odds

Classification Thresholds and the Confusion Matrix

Logistic regression produces a probability for each observation. To classify observations as outcome = 1 or outcome = 0, you apply a threshold. The standard default is 0.50, but this is not always the best choice. The right threshold depends on how costly false positives are compared to false negatives.

Classification Threshold Explorer

Move the slider to see how changing the threshold affects confusion matrix metrics. Uses the fitted probabilities from Example 1 (12 students).

0.50
-
True Positives
-
False Positives
-
False Negatives
-
True Negatives
-
Sensitivity
-
Specificity
-
Accuracy
-
Precision

Confusion Matrix Structure

Actual Positive (Y=1) Actual Negative (Y=0)
Predicted Positive TP
True Positive
FP
False Positive
Predicted Negative FN
False Negative
TN
True Negative

Classification Metrics

TP/(TP+FN)
Sensitivity (Recall)
TN/(TN+FP)
Specificity
TP/(TP+FP)
Precision
(TP+TN)/N
Accuracy
Accuracy Can Be Misleading

If 95% of observations have Y=0, a model that always predicts 0 would achieve 95% accuracy while correctly identifying zero positive cases. Sensitivity, specificity, and ROC-AUC are more informative when the outcome is rare.

ROC Curve and AUC

The ROC (Receiver Operating Characteristic) curve plots sensitivity (true positive rate) against 1 − specificity (false positive rate) at every possible threshold. The area under the ROC curve (AUC) summarizes the model's ability to rank higher-risk observations above lower-risk ones.

AUC = 0.5
Random (coin flip) discrimination
AUC = 0.7
Acceptable discrimination
AUC = 0.8
Good discrimination
AUC = 1.0
Perfect discrimination on evaluated data

ROC Curve (Conceptual)

Random (AUC=0.5) Good model (AUC ≈ 0.85) False Positive Rate (1-Specificity) Sensitivity (True Positive Rate) 0 1 0 1
AUC Does Not Measure Calibration

A model with high AUC can still have poorly calibrated probabilities. A model with AUC = 0.85 could predict 0.40 for an observation that actually has a 0.80 true probability. Use calibration plots to check whether predicted probabilities match observed event rates.

Logistic Regression Assumptions

Logistic regression has different assumptions from linear regression. The most important ones to check:

1

Binary (or Categorical) Outcome

Standard binary logistic regression requires the outcome to have exactly two categories, coded 0 and 1. Make sure the coding is clear and documented: which value is the "event" (Y=1)?

2

Independent Observations

Each observation must be independent of the others. Clustered or repeated-measures data requires different methods, such as mixed models or GEE.

3

Linearity in the Logit

The relationship between continuous predictors and the log-odds should be approximately linear. This does not mean the relationship between predictors and probability must be linear. Check with plots or by adding polynomial terms.

4

No Perfect Multicollinearity

Predictors should not be exact linear combinations of one another. High (but not perfect) correlation inflates standard errors and produces wide confidence intervals but does not automatically invalidate the model.

5

Sufficient Events

The number of events (the less common outcome) should be adequate relative to the number of predictors. Traditional rules of thumb (e.g., 10 events per predictor) are rough heuristics with known limitations. Simulation-based power analysis is more reliable when the dataset is small.

What Logistic Regression Does NOT Require

Logistic regression does not assume normally distributed predictors, normally distributed residuals, or homoscedasticity. These are linear regression assumptions and do not apply here.

Logistic vs Linear Regression

Feature Linear Regression Logistic Regression
Typical outcomeContinuous numericBinary (or categorical)
PredictionExpected value of YProbability (0 to 1)
Model scaleOutcome directlyLog-odds (logit)
Estimation methodOrdinary least squaresMaximum likelihood
Coefficient meaningChange in expected YChange in log-odds
Exponentiated coefficientNot typically an odds ratioOdds ratio
Residual assumptionsNormality, homoscedasticityNot required
Model fit measureR² (variance explained)Pseudo-R², AUC, deviance
Example use casePredict salary from experiencePredict hired (yes/no) from experience

For more detail on the linear side, see simple linear regression and multiple linear regression. Correlation between predictors and outcomes is discussed in the Pearson correlation section.

Logistic Regression in R, Python, SPSS, and Stata

R

Use glm() with family = binomial(link = "logit"). The link = "logit" is the default for binary outcomes and does not need to be written explicitly in most versions, but specifying it is good practice for clarity.

R
# Fit the model
model <- glm(
  pass ~ study_hours + attendance,
  data = student_data,
  family = binomial(link = "logit")
)

# View coefficient table
summary(model)

# Odds ratios
exp(coef(model))

# Confidence intervals for odds ratios (profile likelihood)
exp(confint(model))

# Predicted probabilities for the original data
fitted_probs <- fitted(model)

# Predict for new data
new_student <- data.frame(study_hours = 7, attendance = 78)
predict(model, newdata = new_student, type = "response")

Python (statsmodels)

For inferential output (p-values, confidence intervals, standard errors), use statsmodels. For purely predictive pipelines, scikit-learn is common but uses regularization by default and does not produce standard inferential output.

Python (statsmodels - inferential)
import statsmodels.formula.api as smf
import numpy as np
import pandas as pd

# Fit the model
model = smf.logit(
    "pass ~ study_hours + attendance",
    data=student_data
).fit()

# View summary table
print(model.summary())

# Odds ratios
print(np.exp(model.params))

# Confidence intervals (odds ratio scale)
print(np.exp(model.conf_int()))

# Predict probability for new observation
new_obs = pd.DataFrame({"study_hours": [7], "attendance": [78]})
print(model.predict(new_obs))
Python (scikit-learn - predictive)
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, roc_auc_score

# Note: scikit-learn uses L2 regularization by default (C=1.0)
# Set penalty='none' for unpenalized estimation (requires solver='lbfgs')
model = LogisticRegression(penalty=None, solver='lbfgs')
model.fit(X_train, y_train)

# Predicted probabilities (column 1 = probability of Y=1)
probs = model.predict_proba(X_test)[:, 1]

# Classification report: precision, recall, F1
print(classification_report(y_test, model.predict(X_test)))

# AUC
print("AUC:", roc_auc_score(y_test, probs))

SPSS

In SPSS, go to Analyze → Regression → Binary Logistic. Place your binary outcome in the Dependent box and your predictors in the Covariates box. For categorical predictors, use the Categorical button to set the reference category.

Key output to interpret:

  • B: The coefficient on the log-odds scale.
  • S.E.: Standard error of B.
  • Wald: Test statistic (B / S.E.) squared; tests whether the coefficient differs from zero.
  • Sig.: p-value for the Wald test.
  • Exp(B): The odds ratio.
  • 95% CI for Exp(B): Confidence interval for the odds ratio.

Stata

Stata
* Fit logistic regression: outputs log-odds coefficients
logit pass study_hours attendance

* Fit and display odds ratios directly
logistic pass study_hours attendance

* Predicted probabilities
predict fitted_prob, pr

* ROC curve and AUC
lroc

* Classification table at threshold 0.5
estat classification

Excel

Excel's standard Regression tool (Data Analysis Toolpak) performs linear regression and is not appropriate for logistic regression. To fit logistic regression in Excel, users typically use Excel's Solver add-in to maximize the log-likelihood numerically, which requires careful setup. For most purposes, R, Python, SPSS, or Stata will produce more reliable and better-validated results. If you must stay in Excel, consider exporting data to a dedicated statistical package.

How to Read Logistic Regression Output

A typical logistic regression coefficient table (shown here in the format most software produces) includes the following columns. This example uses the exam pass model from Example 1:

PredictorB (Coef.)S.E.z / Waldp-valueExp(B) / OR95% CI (OR)
Intercept−12.404.20−2.950.003<0.001-
Study Hours0.750.312.420.0162.12[1.15, 3.90]
Attendance0.100.061.670.0951.11[0.98, 1.24]

What each column tells you:

  • B: Study hours has a coefficient of 0.75. This is the estimated change in log-odds for each additional study hour, holding attendance constant.
  • Exp(B) = 2.12: Each additional study hour is associated with 2.12 times the odds of passing, holding attendance constant.
  • 95% CI [1.15, 3.90]: The confidence interval does not cross 1.00, so the association is statistically distinguishable from no association at the 5% level.
  • Attendance CI [0.98, 1.24]: This interval crosses 1.00, meaning the evidence for an attendance effect is weaker (p = 0.095 with this sample size).
💡
Confidence Intervals That Cross 1

When a 95% confidence interval for an odds ratio includes 1.00, the association is not statistically significant at the 5% level. This does not mean there is no association; it means the data are insufficient to rule out OR = 1 at the chosen significance threshold.

Assessing Logistic Regression Model Fit

Several measures describe how well a logistic regression model fits the data. None of them is a direct equivalent to R² from linear regression.

MeasureWhat It CapturesTypical Range
Log-likelihoodFit of the model under maximum likelihood; more negative = worse fitNegative values
Deviance−2 × log-likelihood; lower = better fitPositive values
AICDeviance penalized for number of parameters; for model comparisonLower = better
McFadden pseudo-R²Proportional improvement in log-likelihood over the null model; 0.2-0.4 is considered good for many contexts0 to 1
AUC (ROC)Discrimination: how well the model ranks positive cases above negative cases0.5 to 1.0
Calibration plotWhether predicted probabilities match observed event frequenciesVisual; Hosmer-Lemeshow test
Pseudo-R² Is Not R²

McFadden's pseudo-R² of 0.20 does not mean the model explains 20% of the variance. The values are generally lower than ordinary R², and comparing them across different datasets or outcome types is misleading. Use pseudo-R² only for comparing models on the same data.

Common Logistic Regression Mistakes

MistakeIncorrectCorrect
Interpreting OROR = 2 means probability doublesOR = 2 means odds are twice as high
Coefficient scaleB = 0.75 means a 75% higher probabilityB = 0.75 means a 0.75 increase in log-odds
Statistical significancep < 0.05 proves the effect is importantp < 0.05 means evidence against H₀; look at CI width and OR magnitude
Accuracy95% accuracy means the model is excellentAccuracy can be high if the majority class dominates; check sensitivity and specificity
AUC and calibrationAUC = 0.85 means probabilities are well-calibratedAUC measures discrimination; calibration requires separate checks
NormalityPredictors must be normally distributedNo normality requirement for predictors in logistic regression
CausationA significant coefficient proves X causes the outcomeLogistic regression estimates associations; causation requires appropriate study design
Threshold0.50 is always the correct classification cutoffOptimal threshold depends on the relative costs of false positives and false negatives
Pseudo-R²McFadden R² = 0.15 means 15% of variance explainedPseudo-R² measures are not directly comparable to ordinary R²
Reference categoryForgetting which category was treated as the referenceAlways specify which category is the reference when interpreting odds ratios for categorical predictors

Practice Problems

Practice 1
A researcher predicts whether a patient has diabetes (yes/no) from glucose level and BMI. Which type of regression is appropriate?
Binary logistic regression. The outcome has two categories (diabetes: yes = 1, no = 0), and the goal is to estimate the probability of having diabetes given the predictor values. Linear regression would not be appropriate because predictions could fall below 0 or above 1.
Practice 2
Convert probability p = 0.60 to odds and log-odds. Show your work.
Odds = p / (1 − p) = 0.60 / 0.40 = 1.50
Log-odds = ln(1.50) ≈ 0.405
So the odds are 1.5 to 1 in favor of the event, and the log-odds (logit) are approximately 0.405.
Practice 3
A logistic model gives log-odds = −0.847 for a particular observation. What is the predicted probability?
p = 1 / (1 + e0.847) = 1 / (1 + 2.333) = 1 / 3.333 ≈ 0.30
The predicted probability is approximately 30%.
Practice 4
A logistic regression coefficient for "exercise hours per week" is 0.405. What is the odds ratio? Interpret it.
OR = e0.4051.50
Each additional hour of exercise per week is associated with approximately 1.50 times the odds of the modeled outcome (50% higher odds), holding other predictors in the model constant. This is a 50% increase in the odds, not a 50% increase in probability.
Practice 5
A model has OR = 0.60 for "high-fat diet." Interpret this odds ratio.
OR = 0.60 means that the high-fat diet group has 0.60 times the odds of the outcome compared to the reference group, holding other predictors constant. This represents a (1 − 0.60) = 40% reduction in odds. Since the OR is below 1, a high-fat diet is associated with lower odds of the modeled outcome in this model.
Practice 6
Given the model: logit(p) = −4 + 0.08 × Age, what is the predicted probability for Age = 50?
η = −4 + (0.08 × 50) = −4 + 4 = 0
p = 1 / (1 + e0) = 1 / (1 + 1) = 1 / 2 = 0.50
When the linear predictor equals zero, the predicted probability is exactly 0.50. This makes sense because logit(0.5) = 0.
Practice 7
A model is evaluated on 100 observations: TP = 30, FP = 10, TN = 45, FN = 15. Calculate accuracy, sensitivity, and specificity.
Accuracy = (TP + TN) / N = (30 + 45) / 100 = 75%
Sensitivity = TP / (TP + FN) = 30 / (30 + 15) = 30 / 45 ≈ 66.7%
Specificity = TN / (TN + FP) = 45 / (45 + 10) = 45 / 55 ≈ 81.8%
The model identifies about two-thirds of actual positives correctly and correctly identifies about 82% of actual negatives.
Practice 8
A disease has 5% prevalence. A model achieves 95% accuracy by predicting "no disease" for every patient. What is wrong with this?
The model has zero sensitivity: it never correctly identifies any diseased patient (TP = 0). All 5% of diseased patients are false negatives. The high accuracy comes entirely from correctly classifying the 95% majority class. For rare outcomes, accuracy is a poor measure of model quality. Sensitivity, specificity, precision, recall, and AUC provide a more complete picture.

Frequently Asked Questions

Logistic regression is a statistical model for estimating the probability of a binary outcome. It models the log-odds of the outcome as a linear combination of predictors, then transforms the result into a probability between 0 and 1 using the logistic function. It is used when the outcome has two categories, such as pass/fail, purchase/no purchase, or disease present/absent.

The model equation is: logit(p) = log(p / 1−p) = β₀ + β₁X₁ + ... + βₖXₖ. The probability is obtained by applying the logistic function: p = 1 / (1 + e−η), where η is the linear predictor. The coefficients are estimated by maximum likelihood.

An odds ratio is the exponentiated coefficient: OR = eβ. An OR greater than 1 means higher predictor values are associated with higher odds of the outcome. An OR less than 1 means lower odds. An OR of exactly 1 corresponds to no linear association. The odds ratio does not equal a probability ratio: OR = 2 does not mean the probability doubles.

Linear regression applied to a binary outcome can produce predicted values below 0 or above 1, which are not valid probabilities. The constant variance assumption also fails with binary data. Logistic regression solves this by modeling the log-odds, which can range over all real numbers, and converting it to a probability that stays between 0 and 1.

No. Logistic regression does not require normally distributed predictors, normally distributed errors, or equal variance across groups. These are linear regression assumptions. Logistic regression does assume that continuous predictors have an approximately linear relationship with the log-odds of the outcome, but not that the predictors themselves are normal.

A classification threshold converts a predicted probability into a predicted class. For example, with a threshold of 0.50, observations with p ≥ 0.50 are predicted as Y = 1 and those with p < 0.50 as Y = 0. The threshold of 0.50 is the default but is not always optimal. When false negatives are more costly than false positives (such as in medical screening), a lower threshold raises sensitivity at the cost of specificity.

Relative risk (risk ratio) is the ratio of two probabilities: P(outcome | exposed) / P(outcome | unexposed). Odds ratio is the ratio of two odds. When the outcome is rare, the OR approximates the relative risk. When the outcome is common, they can differ substantially. Logistic regression directly produces odds ratios, not relative risks. To estimate relative risks from a logistic model, alternative methods such as Poisson regression with robust standard errors or modified Poisson regression are sometimes used.

Use the glm() function with family = binomial(link = "logit"). For example: model <- glm(outcome ~ x1 + x2, data = df, family = binomial()). View results with summary(model) and get odds ratios with exp(coef(model)). Confidence intervals for odds ratios: exp(confint(model)).

Sample size needs depend on the number of predictors, the prevalence of the outcome, the effect sizes of interest, and how much precision you need in coefficient estimates. Traditional heuristics such as "10 events per predictor" are rough guides with known limitations. For small or imbalanced samples, simulation-based power analysis provides better guidance. Penalized methods such as Firth logistic regression can help when samples are small relative to the number of predictors.

Complete separation occurs when a predictor or combination of predictors perfectly distinguishes all positive from all negative cases. When this happens, the maximum likelihood coefficient estimate tends toward infinity and standard errors become very large or the algorithm fails to converge. Quasi-complete separation occurs when separation is near-perfect. Solutions include collecting more data, combining sparse categories, using penalized methods such as Firth logistic regression, or Bayesian methods with informative priors.

Key Takeaways

⚡ Logistic Regression Examples: Summary
  • Logistic regression models the probability of a binary outcome through the log-odds transformation, keeping fitted values between 0 and 1.
  • Coefficients are on the log-odds scale. Exponentiating them gives odds ratios.
  • OR > 1 means higher odds; OR < 1 means lower odds. An OR of 2 does not mean probability doubles.
  • To get a predicted probability: calculate the linear predictor η, then apply p = 1 / (1 + e−η).
  • Classification requires choosing a threshold. The default of 0.50 is not always optimal.
  • Accuracy alone is misleading with imbalanced outcomes. Use sensitivity, specificity, and AUC as well.
  • AUC measures discrimination (ranking), not calibration (probability accuracy). Check both.
  • Logistic regression does not assume normally distributed predictors or residuals.
  • A statistically significant coefficient does not establish that the predictor causes the outcome.
  • In R, use glm(family = binomial()). In Python, use statsmodels.formula.api.logit for inference.