Statistical Background¶
This page provides background on the statistical models and methods used in LEAP.
Contents
Generalized Linear Models¶
A generalized linear model (GLM) is a generalization of ordinary linear regression that allows for response variables with non-normal error distributions.
Background: Ordinary Linear Regression¶
In ordinary linear regression, we assume that the response variable \(y\) can be described by the equation:
where \(i\) is the index of the sample, \(n\) is the number of features, \(\beta_0, \beta_1, \ldots, \beta_n\) are the model coefficients, and \(x_{1,i}, \ldots, x_{n,i}\) are the features of the \(i\)-th sample.
GLM: Linear Predictor¶
For a GLM, we assume that the relationship between different terms is linear, but the terms themselves are not necessarily linear. The linear predictor \(\eta_i\) can include polynomial terms, interaction terms, or transformed variables. The key constraint is that the \(\beta\) parameters must enter linearly — exponents on \(\beta\) themselves are not permitted.
Valid examples of linear predictors:
Invalid — the exponent on a \(\beta\) makes this non-linear:
GLM: Random Component¶
The random component assumes that the observed data \(Y\) comes from an exponential family of distributions — such as Gaussian, Poisson, binomial, or gamma:
where \(\theta_i\) is a function of the explanatory variables and \(Q(\theta)\) is the natural parameter.
GLM: Link Function¶
The link function \(g\) connects the mean \(\mu_i = E(Y \mid X = x_i)\) to the linear predictor:
The goal of a GLM is to estimate \(\mu\), not \(\eta\) directly. The link function that maps \(\mu\) to \(Q(\theta)\) is called the canonical link function.
Example 1: Identity Link (Ordinary Linear Regression)¶
For ordinary linear regression, the link function is the identity:
The random component is the Gaussian distribution:
Example 2: Poisson Distribution with Log Link¶
When the response variable represents counts of events (non-negative integers), the Poisson distribution is a natural choice. Incidence and prevalence rates — counts of individuals diagnosed with or living with a condition in a given time interval — follow this pattern.
The log link is the canonical link for the Poisson distribution. The mean \(\mu_i\) is always positive, but the linear predictor \(\eta_i\) can be any real number. The log link satisfies this constraint:
The random component is the Poisson distribution:
This is the distribution family used in LEAP’s occurrence Model 1 to predict population-level asthma incidence and prevalence rates.
Example 3: Negative Binomial Distribution with Log Link¶
The Poisson distribution assumes that the mean and variance are equal:
When the variance exceeds the mean — a common problem in count data known as
overdispersion — the Negative Binomial distribution is a better choice. It
introduces an extra parameter \(\theta\) that controls the degree of overdispersion:
As \(\theta \to \infty\), the Negative Binomial distribution converges to the Poisson
distribution.
The standard form of the Negative Binomial probability mass function is:
where \(k\) is the number of failures before \(r\) successes, and \(p\) is the probability of success. We reparametrize using \(\mu\) and \(\theta\) via:
Substituting \(\sigma^2\) and simplifying:
Math: \(p\) and \(r\)
Letting \(y = k\), the probability mass function in terms of \(\mu\) and \(\theta\) is:
Math: \(P(Y = y;\, \mu, \theta)\)
The log link is the natural choice, since the mean is always positive but the linear predictor \(\eta^{(i)}\) can be any real number:
This is the distribution family used in LEAP’s Antibiotic Exposure Model to predict per-capita antibiotic exposure rates.
Example 4: Ordinal Regression with Logit Link¶
Ordinal regression is used when the response variable is ordered but the intervals between levels are arbitrary. Rather than modelling a single mean, the model predicts the cumulative probability of being at or below each level \(k\) using the logistic (sigmoid) function as the link:
where \(\theta_k\) is the threshold parameter for level \(k\), \(\eta^{(i)}\) is the linear predictor, and \(\sigma(x) = \dfrac{1}{1 + e^{-x}}\) is the logistic function. The probability of being in exactly level \(k\) follows from the cumulative probabilities:
A patient-specific random effect \(\beta_0^{(i)} \sim \mathcal{N}(0, \sigma^2)\) can be added to the linear predictor to account for within-subject correlation across repeated measurements, giving:
This is the model used in LEAP’s Asthma Control Model to predict asthma control level.
Contingency Tables¶
A contingency table (also called a cross-tabulation or crosstab) displays the joint frequency distribution of two categorical variables. They are commonly used in statistics to examine the relationship between two variables, and to calculate odds ratios and other measures of association.
Two-by-Two Contingency Table¶
The simplest form is a 2×2 table, which has two rows and two columns. Consider two binary variables — an exposure and an outcome — for a population of \(n\) individuals:
| outcome + | outcome - | total | |
|---|---|---|---|
| exposure + | a |
b |
n₁ |
| exposure - | c |
d |
n₀ |
| total | n₂ |
n |
where the marginal totals are:
The odds ratio measures the strength of association between the exposure and the outcome:
An odds ratio of 1 indicates no association; values greater than 1 indicate that exposure is associated with increased odds of the outcome.
Example: Smoking and Lung Cancer¶
Suppose we observe n = 300 patients and record whether they smoke and whether they have
lung cancer:
| lung cancer | no lung cancer | total | |
|---|---|---|---|
| smoker | a = 100 |
b = 50 |
n₁ = 150 |
| non-smoker | c = 25 |
d = 125 |
n₀ = 150 |
| total | n₂ = 125 |
n = 300 |
The odds ratio for this table is:
This means that smokers have 10 times the odds of developing lung cancer compared to non-smokers in this population.
Usage in LEAP¶
Contingency tables are used in LEAP to optimize the age-dependent beta parameters for the incidence equation in Occurrence Model 2: Risk Factors. See the Calibrating Age-Dependent Odds Ratios section of the Asthma Occurrence Model for details.
Python Examples¶
For a hands-on walkthrough of GLMs using statsmodels and plotly — including
code you can run locally — see the notebook below.