ANALYSIS TOOL BOX

Hypothesis Testing

ConductLogisticRegressionAnalysis

Conduct logistic regression analysis to model categorical outcomes and assess predictor impact.

hypothesis-testingstatisticssignificanceinference

Introduction

When the outcome you're predicting is a category rather than a number — will this customer churn, which of three products will they pick — linear regression's continuous output doesn't map cleanly onto the question. ConductLogisticRegressionAnalysis fits the right model automatically: binomial logistic regression for a two-category outcome, or multinomial logistic regression when there are three or more, using statsmodels under the hood. It returns coefficients, p-values, and pseudo R-squared, and can plot probability curves per predictor so you can see how the predicted probability actually shifts across a variable's range.

Teaching Note

Logistic regression analysis is essential for:

  • Predicting binary outcomes such as customer churn, conversion, or default
  • Modeling multi-class choices like product preference or tier selection
  • Identifying key drivers that increase or decrease the probability of an event
  • Clinical research for disease diagnosis and risk factor assessment
  • Analyzing social science survey data with nominal or ordinal categories
  • Evaluating the odds ratios of specific predictors in classification tasks
  • Validating classification models through diagnostic visualizations

Parameters

ParameterTypeDefaultDescription
dataframerequiredThe pandas DataFrame containing the data for the regression analysis.
outcome_variablerequiredName of the column in the DataFrame representing the categorical outcome variable.
list_of_predictorsrequiredA list of column names for the independent (predictor) variables to include in the model.
add_constantTrueIf True, adds an intercept (constant term) to the model. Defaults to True.
scale_predictorsFalseIf True, scales the predictor variables to have a mean of 0 and standard deviation of 1 using StandardScaler before fitting the model. Defaults to False.
show_diagnostic_plots_for_each_predictorTrueIf True, displays logistic regression plots with probability curves for each predictor. Defaults to True.
show_helpFalseIf True, prints a quick guide to the console explaining how to access and interpret the output dictionary. Defaults to False.

Returns

A dictionary with 'Fitted Model' (the statsmodels Logit or MNLogit results object) and 'Model Summary' (a comprehensive statistical summary of the regression).

Example

python
from analysistoolbox.hypothesis_testing import ConductLogisticRegressionAnalysis
import pandas as pd

# Binomial logistic regression: predicting customer churn
df = pd.DataFrame({
    'churn': [0, 1, 0, 1, 0, 1] * 20,
    'monthly_spend': [50, 100, 45, 120, 60, 150] * 20,
    'tenure_months': [24, 2, 36, 1, 12, 4] * 20
})
results = ConductLogisticRegressionAnalysis(
    dataframe=df,
    outcome_variable='churn',
    list_of_predictors=['monthly_spend', 'tenure_months']
)
print(results['Model Summary'])