Skip to content
Statistical RethinkingStatistical Rethinking

14.1 Measurement error

Measurement error occurs when predictor variables are observed with noise. A Bayesian model treats the true values as latent variables, absorbing the uncertainty into the posterior rather than ignoring it.

14.1.1 The problem of measurement error

When a predictor xx is measured with error, the observed xobsx_{\text{obs}} differs from the true xtruex_{\text{true}}:

xobs,i∼Normal(xtrue,i,σx,i)x_{\text{obs},i} \sim \text{Normal}(x_{\text{true},i}, \sigma_{x,i})

Ignoring this error attenuates the estimated regression coefficient — the slope is biased toward zero. This is regression dilution.

# Demonstrate measurement error and attenuation
set.seed(42)
n <- 200

# True relationship

x_true <- runif(n, 0, 10)
y <- 1 + 0.5 * x_true + rnorm(n, 0, 1)

# Observed x with measurement error

x_obs <- x_true + rnorm(n, 0, 1.5)

# Model 1: Naive (uses observed x — attenuated slope)

m_naive <- lm(y ~ x_obs)

# Model 2: True (uses true x — correct slope)

m_true <- lm(y ~ x_true)

cat("Measurement error demonstration:\n")
cat(" True slope: 0.5\n")
cat(" Naive slope (x_obs):", round(coef(m_naive)[2], 3), "(attenuated!)\n")
cat(" True slope (x_true):", round(coef(m_true)[2], 3), "(correct)\n")

cat("\n Attenuation factor:", round(coef(m_naive)[2] / coef(m_true)[2], 3), "\n")
cat(" The naive slope is biased toward zero.\n")

# Plot

par(mfrow = c(1, 2))
plot(x_true, y, pch = 16, col = "steelblue",
main = "True x vs y", xlab = "x_true", ylab = "y")
abline(m_true, lwd = 2, col = "firebrick")
plot(x_obs, y, pch = 16, col = "steelblue",
main = "Observed x vs y (noisy)", xlab = "x_obs", ylab = "y")
abline(m_naive, lwd = 2, col = "firebrick")
par(mfrow = c(1, 1))
Click Run to execute this code in your browser with WebR

14.1.2 Bayesian measurement error model

The Bayesian approach treats xtruex_{\text{true}} as a latent variable:

xobs,i∼Normal(xtrue,i,σx,i)x_{\text{obs},i} \sim \text{Normal}(x_{\text{true},i}, \sigma_{x,i}) yi∼Normal(α+β xtrue,i,σ)y_i \sim \text{Normal}(\alpha + \beta \, x_{\text{true},i}, \sigma)

The model estimates both the true values and the regression parameters simultaneously.

# Bayesian measurement error model (concept demonstration)
# We simulate the approach using a simple two-step method

set.seed(42)
n <- 200
x_true <- runif(n, 0, 10)
y <- 1 + 0.5 * x_true + rnorm(n, 0, 1)
x_obs <- x_true + rnorm(n, 0, 1.5)
x_sd <- rep(1.5, n) # known measurement error SD

# Naive model

m_naive <- lm(y ~ x_obs)

# Simple correction: regression calibration

# Step 1: Estimate true x from observed x (shrink toward mean)

x_mean <- mean(x_obs)
x_var_obs <- var(x_obs)
x_var_true <- x_var_obs - mean(x_sd^2)
reliability <- x_var_true / x_var_obs

# Corrected x: shrink observed toward mean

x_corrected <- x_mean + reliability * (x_obs - x_mean)

# Model with corrected x

m_corrected <- lm(y ~ x_corrected)

cat("Measurement error correction:\n")
cat(" Reliability ratio:", round(reliability, 3), "\n")
cat(" Naive slope:", round(coef(m_naive)[2], 3), "\n")
cat(" Corrected slope:", round(coef(m_corrected)[2], 3), "\n")
cat(" True slope: 0.500\n")

cat("\n The corrected slope is closer to the true value.\n")
cat(" Full Bayesian treatment would propagate all uncertainty.\n")
Click Run to execute this code in your browser with WebR
Rethinking

Measurement error is not a nuisance — it is a model. The standard approach to measurement error is to ignore it and hope it does not matter. But it always matters: it attenuates relationships, reduces power, and can reverse conclusions. The Bayesian approach is to model the measurement process: the observed value is a noisy measurement of a true value, and the model estimates both. This is not just about getting better estimates — it is about being honest. If you know your measurements are noisy, pretending they are exact is a modeling decision, and a bad one. The Bayesian model encodes what you actually know: the measurements are noisy, and the noise matters.

Summary of Section 14.1

  • Measurement error in predictors attenuates the slope (biases toward zero).
  • The Bayesian approach treats true values as latent variables.
  • xobs∼Normal(xtrue,σx)x_{\text{obs}} \sim \text{Normal}(x_{\text{true}}, \sigma_x) — model the measurement process.
  • The model estimates true values and regression parameters simultaneously.
  • Ignoring measurement error is a modeling decision — and usually a bad one.