Ask Mallard

Nonlinearity and splines

A spline lets the relationship between a continuous predictor and the outcome curve smoothly, estimated from the data rather than assumed.

What question does this help answer?

What the shape of the relationship actually is, which matters whenever risk does not rise in a straight line: age, blood pressure, body mass index and dose-response relationships routinely do not.

Why the usual alternatives fail

Assuming a straight line can miss a U shape entirely and report no association where a strong one exists at both ends. Splitting into quartiles produces a step function that says risk is constant within a quartile and jumps at an arbitrary boundary, which is never biologically true. Choosing an optimal cutpoint by trying many and keeping the best is a multiple-testing exercise whose p-value cannot be believed.

Categories against a spline

A curved relationship between a continuous predictor and an outcome. Cutting the predictor into four categories gives flat steps that jump at the cutpoints, while a spline follows the curve smoothly.A continuous relationship, cut into categories, and fitted with a splineContinuous predictorOutcomeUnderlying relationshipSplineCategories: flat inside, jumps at the cutsCategories assume everyone within a band is identical and create jumps at the cutpoints; chosen from thedata, the cutpoints also inflate false positives.
Conceptual diagram. It shows the structure of the idea, not data from any study.

How a restricted cubic spline works

Place a small number of knots across the range of the variable, fit a smooth cubic curve between them, and constrain the curve to be linear beyond the outermost knots so the tails, where data are sparse, do not swing wildly. Three to five knots is usually enough; their placement matters less than their number.

Presenting it

  • Plot the fitted curve with a confidence band, against the variable in its natural units.
  • State the reference value the curve is plotted relative to, since the whole curve moves when it changes.
  • Report a test for nonlinearity, not only a test for any association.
  • Show where the data actually are: a rug plot or histogram, because a dramatic curve in a region holding twelve patients is not a finding.
  • Give a few interpretable contrasts in the text, such as the estimate at the 75th versus the 25th percentile.

Why Mallard may recommend it

Mallard may suggest a spline whenever a continuous exposure or an important confounder is likely to act nonlinearly, and it will question a proposal to categorise a continuous variable without a clinical threshold behind it.

What to watch out for

Cutting a continuous variable into categories is the most common way to handle nonlinearity and among the worst: it discards information, assumes everyone within a category is identical, creates artificial jumps at the boundaries, and when the cutpoint is chosen from the data it inflates the false-positive rate substantially. The opposite error is over-flexibility: enough knots will fit any wiggle in the sample, including the noise.

Clinical example

Question: How does admission blood pressure relate to mortality? Analysis: Model pressure with a restricted cubic spline with four knots and plot the fitted curve, since the relationship is well known to be U-shaped and a linear term would report almost nothing.

Code for this method
Loading…
Recent studies that used this
Searching PubMed…
Related Learn pages
Sources & further reading
  1. Cubic splines to model relationships between continuous variables and outcomes: a guide for clinicians (opens in a new tab) · Bone Marrow Transplant · doi 10.1038/s41409-019-0679-x
  2. Variable selection - A review and recommendations for the practicing statistician (opens in a new tab) · Biom J · doi 10.1002/bimj.201700067
Last source review: 2026-09-06
AI-generated educational content
Mallard uses reputable methodological and reporting sources, but this material may contain errors or omit important context. Verify important methodological decisions with the cited sources and, when appropriate, a qualified research methodologist or statistician.