Part 8 · Module 4

Building a Multivariable Model

Learn how to build a multivariable model from a prespecified objective, candidate parameters, functional forms and validation plan.

Learning outcomes

After completing this lecture, you should be able to:

  • Distinguish explanatory, causal and predictive modelling objectives.
  • Define candidate predictor parameters before fitting.
  • Select variables using subject knowledge rather than univariable screening.
  • Plan functional forms, interactions and missing-data handling.
  • Explain overfitting, shrinkage and internal validation.
  • Use reproducible R code to compare prespecified nested models.

Overview

Building a multivariable model is a scientific design task rather than a sequence of software clicks.

A defensible workflow begins with the objective, estimand, study design, candidate parameters, functional forms, interactions, missing-data strategy, diagnostics and validation.

Why this matters

Automated stepwise selection can produce unstable variables, biased coefficients, underestimated uncertainty and poor reproducibility. Univariable screening is also inadequate because confounding is not defined by a crude p-value [1], [2].

When to use this method

Use the framework whenever several predictors or covariates are considered.

The strategy depends on whether the goal is causal effect estimation, explanatory association or clinical prediction.

Research question and variables

A causal model prioritises confounder control and avoidance of inappropriate mediator adjustment.

An explanatory model prioritises interpretable conditional associations.

A prediction model prioritises calibration, discrimination, prediction error and validation.

Data structure

Prespecified model components

simulated data
ComponentPlanned representation
Baseline blood pressureContinuous
TelemonitoringBinary
AgeContinuous, checked for non-linearity
BMIContinuous
AdherenceContinuous
SexBinary

Statistical assumptions

How the method works

Candidate models may be compared using coefficient precision, residual fit, likelihood, information criteria, calibration or prediction error. A coherent strategy links these quantities to the stated modelling objective rather than treating them as interchangeable ranking scores [3].

AIC is a relative information criterion. It does not determine scientific validity.

Translate the question into a model specification

Before fitting, write a model-specification table containing:

  • outcome and time point;
  • primary exposure or prediction target;
  • candidate variables;
  • coding and units;
  • planned nonlinear terms;
  • planned interactions;
  • reason for inclusion;
  • handling of missing values.

This separates scientific decisions from outcome-driven choices made after software output is seen.

Use causal structure for effect estimation

When the objective is a causal exposure effect, a causal diagram can help identify a sufficient adjustment set. Confounders should precede the exposure and outcome in the assumed causal structure. Mediators are not ordinary confounders, and colliders should generally not be conditioned on.

The smallest valid adjustment set is not necessarily the model with the smallest AIC. Causal identification and statistical efficiency are related but distinct questions.

Preserve clinically meaningful continuous information

Continuous predictors should usually remain continuous. Categorisation can create residual confounding, reduce power and make results depend on arbitrary boundaries.

For a clinically important continuous predictor, allocate parameters for a flexible function when required. A restricted cubic spline with four knots uses more than one parameter and should be counted accordingly during sample-size planning.

Candidate complexity and sample size

Model complexity should be planned using the number of candidate parameters and the information in the outcome. Binary prediction models require enough outcome and non-outcome observations to estimate the overall risk, predictor effects and model performance with acceptable precision.

Simple events-per-variable rules are not universal. They ignore outcome prevalence, anticipated model fit, shrinkage and the number of parameters used by nonlinear terms or interactions.

Variable reduction and penalisation

When candidate complexity must be reduced, clinically implausible or unavailable predictors can be removed before fitting. Highly redundant measurements may be represented by a prespecified composite or one clinically preferable measure.

Penalised methods shrink coefficients towards zero and can reduce overfitting. Ridge regression retains all parameters with shrinkage, whereas lasso can set some coefficients to zero. Selection induced by penalisation still requires validation and transparent reporting.

Internal validation

Apparent performance is evaluated in the same data used to estimate the model and is optimistic. Bootstrap validation repeatedly resamples participants, rebuilds the complete modelling process and estimates optimism.

Validation must repeat every data-dependent step, including transformation selection, predictor selection and tuning. Validating only the final fixed equation understates uncertainty introduced during model development.

Reproducibility

Report the full formula, coding, software version, tuning choices and random seed where applicable. A regression table without the intercept, transformations or category coding is not a reproducible model.

Worked example

Reproducible R analysis

Base R fits the prespecified linear models and compares nested fits using lm() and anova() [4].

make_hypertension_data <- function(n = 180) {
  set.seed(4583)
  i <- seq_len(n)

  data <- data.frame(
    participant_id = sprintf("H%03d", i),
    age = round(runif(n, 30, 80)),
    male = rbinom(n, 1, 0.5),
    bmi = pmin(pmax(round(rnorm(n, 27, 3.5), 1), 18), 40),
    physical_activity = round(runif(n, 2, 7), 1),
    telemonitoring = rbinom(n, 1, 0.5)
  )

  data$adherence <- 4 + runif(n, 0, 5) -
    0.015 * (data$age - 55) + 0.4 * data$telemonitoring
  data$baseline_sbp <- 92 + 0.52 * data$age + 0.85 * data$bmi +
    2.8 * data$male - 1.3 * data$physical_activity + rnorm(n, 0, 4)
  data$followup_sbp <- 58 + 0.47 * data$baseline_sbp +
    0.10 * data$age + 0.52 * data$bmi - 2.0 * data$adherence +
    2.0 * data$male - 4.5 * data$telemonitoring -
    0.55 * data$telemonitoring * (data$bmi - 27) +
    0.006 * (data$age - 55)^2 + rnorm(n, 0, 5)

  data
}

hypertension <- make_hypertension_data()

reduced <- lm(
  followup_sbp ~ baseline_sbp + telemonitoring +
    age + bmi,
  data = hypertension
)

full <- lm(
  followup_sbp ~ baseline_sbp + telemonitoring +
    age + bmi + adherence + male,
  data = hypertension
)

anova(reduced, full)

data.frame(
  model = c("Reduced", "Full"),
  adjusted_r_squared = c(
    summary(reduced)$adj.r.squared,
    summary(full)$adj.r.squared
  ),
  AIC = c(AIC(reduced), AIC(full))
)

Cleaned R output

Comparison                 Parameters added   F       p-value
Reduced versus full model          2          24.14   <0.001

Model      Adjusted R-squared   AIC
Reduced          0.564          1149.6
Full             0.655          1109.3

Interpreting the output

Presenting the results

Present the prespecified candidate model, any accepted simplification, model fit and validation findings transparently.

Suggested reporting

Overfitting and shrinkage MMed extension

Overfitting is excessive adaptation to sample-specific noise. Responses include larger samples, fewer defensible parameters, penalisation, shrinkage and bootstrap optimism correction [2], [3].

Common mistakes

Knowledge check

Why is univariable screening unsuitable for confounder selection?

Answer and reasoning

Confounding depends on causal structure and multivariable relations, not a crude significance threshold.

Why does a four-level factor count as three parameters?

Answer and reasoning

One category is the reference and three indicators represent the remaining categories.

Does lower AIC prove clinical superiority?

Answer and reasoning

No. It is a relative fit criterion and does not assess validity, usefulness or transportability.

What is overfitting?

Answer and reasoning

It is excessive fitting of sample-specific noise, leading to optimistic and unstable performance.

Why state model objective first?

Answer and reasoning

Causal, explanatory and predictive models require different variable roles and evaluation criteria.

Key take-home messages

References

  1. Heinze G, Wallisch C, Dunkler D. Variable selection—a review and recommendations for the practicing statistician. Biom J. 2018;60(3):431–449. https://doi.org/10.1002/bimj.201700067
  2. Babyak MA. What you see may not be what you get: a brief, nontechnical introduction to overfitting in regression-type models. Psychosom Med. 2004;66(3):411–421. https://doi.org/10.1097/01.psy.0000127692.23278.a9
  3. Harrell FE Jr. Regression modeling strategies. 2nd ed. Cham: Springer; 2015. https://doi.org/10.1007/978-3-319-19425-7
  4. R Core Team. Fitting linear models and model comparison. R documentation, package stats version 4.6.1. Vienna: R Foundation for Statistical Computing; 2026. https://stat.ethz.ch/R-manual/R-devel/library/stats/html/anova.lm.html

These notes support learning and research planning and do not replace statistical consultation for a specific study.

Report an error in this lecture