← 3. Relationships & regression
Regression analysis
Try this analysis →

Generalized Linear Model (GLM)

Analyze relationships between variables with a model that fits the distribution of the outcome.

Probability distributionLink functionGamma GLMInterpreting coefficients

AgeVisitsChronic illnesslog linkexp( … )$$$$Expected cost (always positive)Exponentiate the linear predictor to predict a positive mean
$0High costAnnual medical costsLong right tail
Distribution of annual medical costs

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.

SECTION 1

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.

SECTION 2

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 dataTypical distribution · linkExample
Continuous, symmetric valuesNormal · identityTest scores
0 or 1Binomial · logitService cancellation
Event counts of 0 or morePoisson · logMonthly accident counts
Values above 0, right-skewedGamma · logPatient medical costs
Distinction: A GLM is not one specific test but a modeling framework that can be applied to many kinds of outcomes. The combination of distribution and link function must suit the research question.
SECTION 3

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.

PredictorsAge · visits · chronic illnessβ₀ + β₁X₁ + …Linear predictor = log(μ)μ = exp(…)Expected cost (positive)
Structure of the log link

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.

SECTION 4

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.

VariableRoleExample
Annual medical costs (USD)Outcome$1,280 / $2,650 / $4,130
AgePredictor25–75 years
Chronic illnessPredictorNo / Yes
Outpatient visitsPredictor1–5 per year

The sample and values are hypothetical data generated for learning. No real patient records were used.

SECTION 5

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.

SECTION 6

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.

SECTION 7

How do you read a GLM results table?

Check the regression coefficients, exponentiated coefficients, confidence intervals and p-values together.

Predictorβexp(β)95% CIp-value
const7.2421397.501287.00–1517.48< .001
Age (10 years)0.0911.101.05–1.14< .001
Chronic illness (yes)0.2781.321.17–1.48< .001
Outpatient visits (per visit)0.0751.081.04–1.12< .001
11.11.21.31.41.5Ageper 10 yrs1.10Chronic illnessyes1.32Outpatient visitsper visit1.08exp(β) · expected cost multiplier
Expected cost multiplier exp(β)

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.

SECTION 8

How do you compare predicted medical costs?

Fix the other conditions and change only the variable of interest to compare expected means.

$1,000$1,500$2,000$2,500Age 30Age 40Age 50Age 60Age 70Chronic illnessNone× 1.32
Expected medical costs by age

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.

SECTION 9

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 checkPurpose
Deviance and residual patternsCheck whether systematic error remains
Mean–variance relationshipCheck whether the chosen distribution explains the variability
Extreme values · influenceCheck whether a few observations strongly affect the coefficients
Comparing alternative modelsEvaluate 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.

SECTION 10

How is it different from other analyses?

GLM covers many models, and logistic and Poisson regression are typical examples within it.

MethodMain outcomeKey difference
Linear regression (normal GLM)Mostly continuousLinear relationship between mean and predictors
Binary logistic regression0/1Binomial distribution with logit link
Poisson regressionEvent countsCounts with log link
Negative binomial regressionOverdispersed event countsMore flexible variance structure than Poisson
Gamma GLMPositive continuousUsed 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.

SECTION 11

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.

SECTION 12

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.

Example reporting sentence

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.

SECTION 13

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.

✓ Wrap-up

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.

KEY TAKEAWAY

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.