Skip to course content
Free R statistics course

Statistical Data Analytics with R

Unit 09.03: Only as good as the variables you measured

'Adjusted for' is a strong claim. It is only as good as the variables you thought to measure.

Comparing units that match on the other predictors

Adjusting for a variable means comparing observations that share the same value of it. When a confounder drives both the predictor and the outcome, the unadjusted association carries the confounder's effect as well, and adjustment separates them.

The technique works, and it works only for confounders that are in the model. Anything you did not measure continues to contaminate the estimate, silently and by an unknown amount.

This is the central limitation of observational analysis, and no amount of modelling sophistication removes it. It is why a randomised experiment is worth so much.

This block builds data where experience drives both training hours and salary.

suppressPackageStartupMessages(library(broom))
set.seed(604)
n <- 300
# Experience drives both the training hours and the salary.
experience <- runif(n, 0, 25)
training   <- 5 + 1.8 * experience + rnorm(n, 0, 6)
salary     <- 30000 + 1800 * experience + 50 * training + rnorm(n, 0, 4000)
d <- data.frame(salary, training, experience)

cat("Unadjusted: salary ~ training\n")
print(tidy(lm(salary ~ training, data = d))[, c("term", "estimate", "p.value")])

cat("\nAdjusted for experience: salary ~ training + experience\n")
print(tidy(lm(salary ~ training + experience, data = d))[, c("term", "estimate", "p.value")])

unadj <- coef(lm(salary ~ training, data = d))["training"]
adj   <- coef(lm(salary ~ training + experience, data = d))["training"]
cat("\nTraining coefficient:", round(unadj), "->", round(adj), "\n")
cat("The true value used to build the data was 50.\n")
cat("The unadjusted estimate is", round(unadj / 50, 1),
    "times too large because it also carries experience.\n")
cat("'Adjusted for' means: comparing units that share the same value of the\n")
cat("other predictor. It is only as good as the variables you measured.\n")

Unadjusted, the training coefficient is 853. Adjusted for experience it is 52 — and the value actually used to build the data was 50. The unadjusted estimate was 17.1 times too large, because it was carrying experience's effect as well as training's. Adjustment recovered the truth here precisely because the confounder was measured.

The mistake this prevents

The mistake is treating an adjusted estimate as causal. It is adjusted for what you measured; the confounders you never thought of are still in there.

Takeaway

Say 'adjusted for X, Y' rather than 'controlling for confounders', and list the confounders you could not measure in the limitations. Treat a large shift between unadjusted and adjusted estimates as evidence that more may be lurking.