Generalized Linear Model (GLM)
Analyze relationships between variables with a model that fits the distribution of the outcome.
Do medical costs rise with age? Do patients with and without a chronic illness differ in average medical costs, even when everything else is the same? Questions like these can be handled with regression, but first we need to consider the nature of medical cost data.
Medical costs are greater than 0, and while most people spend relatively little, a few can incur much larger amounts. For a right-skewed outcome like this, a model that accounts for an appropriate probability distribution can be more useful than ordinary linear regression.
A generalized linear model (GLM) is a regression framework that links the conditional mean of the outcome to the predictors while letting you choose a probability distribution and link function that fit the data. Binary logistic regression and Poisson regression also belong to this framework.
Rather than repeating the logistic and Poisson regression covered on other pages, this guide follows a case that analyzes medical costs with a gamma GLM, looking at distribution choice, the log link, coefficient interpretation and model diagnostics.
What is a generalized linear model (GLM)?
A regression model that chooses a probability distribution and link function to suit the outcome.
The generalized linear model (GLM) is an analysis method that extends the basic structure of linear regression. It is the same in that it estimates how one or more predictors relate to the conditional mean of the outcome, but it does not assume the outcome must follow a normal distribution.
For example, patients' medical costs cluster at values above 0, while a few patients can have very high amounts. Fitting simple linear regression to such data can mismatch the error distribution and the mean–variance relationship, or produce negative predictions. In this case, you can consider the gamma distribution, which suits positive continuous data.
Why do we need GLMs?
Because medical costs, event counts and event occurrence have different outcome distributions.
Being "regression" does not mean every outcome can be handled the same way. Mostly continuous values such as test scores, the number of accidents in a month, whether a service is canceled, and medical costs all differ in the range of observed values and in how they vary.
| Type of data | Typical distribution · link | Example |
|---|---|---|
| Continuous, symmetric values | Normal · identity | Test scores |
| 0 or 1 | Binomial · logit | Service cancellation |
| Event counts of 0 or more | Poisson · log | Monthly accident counts |
| Values above 0, right-skewed | Gamma · log | Patient medical costs |
How does a GLM work?
You specify a probability distribution, a linear predictor and a link function together.
A GLM has three components. First, choose the conditional distribution of the outcome. Second, build the linear predictor β₀ + β₁X₁ + … from the predictors. Third, connect the conditional mean μ to the linear predictor through a link function.
In this example we use the form log(μ) = β₀ + β₁X₁ + β₂X₂ + β₃X₃. So μ is computed as exp(linear predictor), and exponentiating a predictor's coefficient gives the multiplier on expected medical costs, holding everything else equal.
Real-world example: analyzing patients' annual medical costs
Estimate expected medical costs accounting for age, chronic illness and number of outpatient visits.
Suppose we observed one-year medical costs, age, chronic illness status and number of outpatient visits for 240 hypothetical patients. All costs are positive and some patients have high costs, so we fit a GLM with a gamma distribution and a log link.
| Variable | Role | Example |
|---|---|---|
| Annual medical costs (USD) | Outcome | $1,280 / $2,650 / $4,130 |
| Age | Predictor | 25–75 years |
| Chronic illness | Predictor | No / Yes |
| Outpatient visits | Predictor | 1–5 per year |
The sample and values are hypothetical data generated for learning. No real patient records were used.
Why choose a gamma GLM?
It suits continuous outcomes that are positive and whose variance can grow with the mean.
The gamma GLM is often considered for positive continuous outcomes. Typical examples are data above 0 with a long right tail, such as medical costs, length of hospital stay and service processing time. Under the gamma distribution, the conditional variance is proportional to the square of the mean.
However, if medical costs include zeros, a standard gamma GLM is hard to apply as is. You should consider a two-part model that separates whether any cost occurred from the positive amount spent, or another distribution. Being medical cost data does not by itself make a gamma GLM always the best choice.
How does the log link change coefficient interpretation?
An exponentiated coefficient represents a multiplier, not a change in the mean.
With a log link, it is convenient to read exp(β), the exponentiated coefficient β. Holding everything else equal, a one-unit increase in a predictor makes the expected medical cost exp(β) times as large.
For example, if the multiplier for a 10-year increase in age is 1.14, expected medical costs are about 14% higher. This does not mean every patient's actual costs rise by exactly 14%. Categorical variables are interpreted as a comparison with the reference category.
How do you read a GLM results table?
Check the regression coefficients, exponentiated coefficients, confidence intervals and p-values together.
| Predictor | β | exp(β) | 95% CI | p-value |
|---|---|---|---|---|
| const | 7.242 | 1397.50 | 1287.00–1517.48 | < .001 |
| Age (10 years) | 0.091 | 1.10 | 1.05–1.14 | < .001 |
| Chronic illness (yes) | 0.278 | 1.32 | 1.17–1.48 | < .001 |
| Outpatient visits (per visit) | 0.075 | 1.08 | 1.04–1.12 | < .001 |
These are results from actually fitting a gamma GLM (log link) to the hypothetical data, using HC3 robust standard errors. Age is per 10-year increase and outpatient visits are per one-visit increase. The intercept is the value at the centered variables and reference categories.
When interpreting, first check whether the multiplier is above or below 1, then see whether the confidence interval includes 1. The p-value alone does not tell you how large the difference in medical costs is in practical terms.
How do you compare predicted medical costs?
Fix the other conditions and change only the variable of interest to compare expected means.
The graph shows the annual medical costs the model expects as age and chronic illness status change, with the other variables held at the same values. Because the model uses a log link, the predicted mean by age can appear as a curve on the original cost scale.
The two lines in the graph are not individual patients' actual costs but the conditional means under each condition. Prediction intervals and the spread of actual costs need to be evaluated separately.
How do you assess model fit and diagnostics?
Diagnose whether the distribution and link function are appropriate, and check for observations with excessive influence.
In a GLM, check residual deviance, Pearson residuals, the relationship between fitted values and residuals, and influential observations together. If standardized Pearson residuals show a systematic pattern with the predicted mean, revisit the variance structure.
| What to check | Purpose |
|---|---|
| Deviance and residual patterns | Check whether systematic error remains |
| Mean–variance relationship | Check whether the chosen distribution explains the variability |
| Extreme values · influence | Check whether a few observations strongly affect the coefficients |
| Comparing alternative models | Evaluate fit and interpretability together |
A model is not valid simply because its deviance is low. You also need to consider the observation structure and how the data were collected.
How is it different from other analyses?
GLM covers many models, and logistic and Poisson regression are typical examples within it.
| Method | Main outcome | Key difference |
|---|---|---|
| Linear regression (normal GLM) | Mostly continuous | Linear relationship between mean and predictors |
| Binary logistic regression | 0/1 | Binomial distribution with logit link |
| Poisson regression | Event counts | Counts with log link |
| Negative binomial regression | Overdispersed event counts | More flexible variance structure than Poisson |
| Gamma GLM | Positive continuous | Used for positive spending, durations, etc. |
Poisson regression and binary logistic regression should not be seen as built on principles entirely separate from GLM. Negative binomial regression, on the other hand, is often implemented in GLM form, but the implementation differs depending on the negative binomial model used and how the dispersion parameter is estimated.
What should you check before the analysis?
Check the unit of data and independence, the range of the outcome, and the model form.
First, check whether the outcome is truly positive and how many zeros there are. Next, check whether observations per patient are independent. If the same patients were observed repeatedly, you may need a different approach that accounts for the correlation structure, such as GEE or a mixed model.
You should also check whether the effect of age really has a straight-line relationship in the linear predictor. Use splines or transformations if needed, and also check for high correlation among predictors and large influence from particular observations. Sample size should take into account both the number of coefficients to estimate and the distribution of the data.
How do you write up the results in a paper or report?
Report the distribution and link function, sample size and the interpretation unit of each coefficient together.
Rather than just naming the method, first explain why you used a gamma distribution and a log link. Then present the sample size, predictor units and reference categories, exponentiated coefficients, confidence intervals, test results and diagnostics.
To examine how annual medical costs relate to age, chronic illness status and number of outpatient visits among 240 patients, a gamma generalized linear model with a log link was fitted. Age was rescaled to 10-year units, and regression coefficients were exponentiated and reported as multipliers on mean medical costs. Uncertainty in the coefficients was assessed using HC3 robust standard errors.
This sentence is an example introducing the analysis method. An actual report should add the figures from the results table and the data diagnostics.
Where can GLMs be used?
The starting point is choosing a distribution and link function that fit the research question.
Medical and health research can analyze medical costs, number of visits and whether clinical events occur. Businesses can look at customer churn and service usage counts, and operations can handle processing times and accident counts. What matters is not interpreting every result the same way just because they share the name GLM.
When you start an analysis, check what values the outcome can take, then choose the probability distribution, link function and diagnostics that fit the research question. This process is the first step toward building an appropriate model.
Choose a regression model that fits the nature of the outcome
In a GLM, the distribution and link function you chose are the starting point for interpretation.
Generalized linear models keep the structure of linear regression while letting you analyze many kinds of outcomes, such as binary, count and positive continuous. In this gamma GLM case, we used a log link to see how age, chronic illness and outpatient visits relate to the conditional mean of medical costs.
In the results, do not look only at coefficient significance; also check the size of the exponentiated coefficients and their confidence intervals, the predicted means, and distribution and residual diagnostics. More important than the GLM name itself is choosing a model that fits the data and staying within that model's scope of interpretation.
A GLM is a regression framework that analyzes the conditional mean by choosing a distribution and link function for the outcome. For positive, right-skewed medical costs you can consider a gamma GLM, and the exponentiated coefficients of a log link are interpreted as multipliers on the expected mean. Draw conclusions only after checking distributional fit, residuals and influential observations.