Quantile Regression
The engine for Distributional Discovery. Quantile Regression audits relationships at any point in the outcome spectrum (e.g., Median, 90th percentile), revealing how predictors behave differently for 'High' vs. 'Low' performers.
What is it?
Quantile Regression models specific conditional quantiles of the outcome variable (e.g. 10th, 50th, or 90th percentile) rather than the average conditional mean.
When to use it
- Heteroscedasticity: Noise spreads out or funnels across predictor values.
- Percentile Targeting: Investigate changes at extreme ends (e.g. growth limits).
- Outlier Defense: Median quantile is robust against extreme values.
Quantile vs OLS Mean
Under heteroscedastic funnel noise, OLS (amber line) only fits the mean. Quantile regression fits specific levels (e.g. 90th percentile):
Quantile Regression Live Laboratory
Increase the heteroscedastic funnel noise and switch quantiles to see target slope divergence.
Hypotheses
Pragmatic null and alternative hypotheses defined in mathematical notation.
H₀: βτ = 0 (predictor has no effect at quantile τ)
Hₐ: βτ ≠ 0 (predictor has an effect at quantile τ)
Tests can be performed at any quantile τ ∈ (0,1). Median regression tests τ = 0.5. Can test whether slopes differ across quantiles using Wald or F-tests.
Assumptions
The core mathematical criteria needed to ensure that statistical testing remains unbiased and valid.
Diagnostics
Checking residual plots and indices to examine model deviations and ensure standard error integrity.
- Plot coefficients across multiple quantiles (0.1, 0.25, 0.5, 0.75, 0.9) to visualize heterogeneous effects
- Check quantile crossing: verify predicted quantiles maintain proper ordering across X range
- Residual plots at each quantile to check for patterns or heteroscedasticity
- Bootstrap confidence intervals for coefficient stability
- Compare quantile regression to OLS to highlight distributional differences
- Check VIF for multicollinearity (VIF > 10 problematic)
- Specification tests (e.g., Zheng test) for functional form
- Plot conditional quantile functions at representative X values
Applied Minds
Review concrete study examples, data layout guidelines, and copy executable syntax scripts.
Income Returns to Education (Heterogeneous Effects Across Distribution)
Research question: Does the relationship between years of education and income vary across the income distribution? Design: Cross-sectional observational data (n=500). Outcome: Annual income (continuous, right-skewed). Predictor: Years of education. Quantile regression reveals education benefits high earners more than low earners.
# Quantile Regression: Income returns to education across distribution
# Demonstrates heterogeneous effects that OLS misses
library(quantreg) # For quantile regression
library(ggplot2) # For visualization
library(dplyr)
# Simulate realistic income data (right-skewed, heterogeneous education effects)
set.seed(2025)
n <- 500
data <- data.frame(
education = rnorm(n, 14, 3) # Years of education, M=14, SD=3
)
data$education <- pmax(8, pmin(22, data$education)) # Bound 8-22 years
# Experience (correlated with education)
data$experience <- pmax(0, rnorm(n, 15 - 0.5*data$education + 20, 5))
# Income: heterogeneous returns (larger effect for high earners)
data$income <- 15 +
2.5 * data$education + # Base education effect
0.3 * data$experience + # Experience effect
0.15 * data$education * data$experience/10 + # Interaction
exp(rnorm(n, 0.8, 0.6)) # Right-skewed errors
# === STEP 1: Compare OLS vs Quantile Regression ===
# OLS regression (standard approach)
ols_model <- lm(income ~ education + experience, data = data)
summary(ols_model)
# Median regression (τ = 0.5)
median_model <- rq(income ~ education + experience, tau = 0.5, data = data)
summary(median_model, se = "boot") # Bootstrap SE for inference
# === STEP 2: Quantile Regression at Multiple Quantiles ===
taus <- c(0.1, 0.25, 0.5, 0.75, 0.9)
qr_models <- rq(income ~ education + experience, tau = taus, data = data)
summary(qr_models, se = "boot", R = 1000) # 1000 bootstrap replicates
# Extract coefficients
coefs <- coef(qr_models)
print(round(coefs, 3))
# === STEP 3: Visualize Heterogeneous Effects ===
# Plot education coefficient across quantiles
qr_full <- rq(income ~ education + experience, tau = seq(0.05, 0.95, 0.05), data = data)
qr_summary <- summary(qr_full, se = "boot", R = 500)
# Extract education coefficients and CIs
edu_coefs <- sapply(qr_summary, function(x) x$coefficients["education", "Value"])
edu_lower <- sapply(qr_summary, function(x) x$coefficients["education", "lower bd"])
edu_upper <- sapply(qr_summary, function(x) x$coefficients["education", "upper bd"])
taus_full <- seq(0.05, 0.95, 0.05)
plot_data <- data.frame(tau = taus_full, coef = edu_coefs,
lower = edu_lower, upper = edu_upper)
ggplot(plot_data, aes(x = tau, y = coef)) +
geom_line(color = "blue", size = 1) +
geom_ribbon(aes(ymin = lower, ymax = upper), alpha = 0.2, fill = "blue") +
geom_hline(yintercept = coef(ols_model)["education"],
linetype = "dashed", color = "red", size = 1) +
labs(title = "Education Returns Across Income Distribution",
subtitle = "Blue: Quantile regression coefficients | Red: OLS coefficient",
x = "Income Quantile(τ)",
y = "Education Coefficient($/year)") +
theme_classic() +
annotate("text", x = 0.5, y = coef(ols_model)["education"] + 0.5,
label = "OLS(constant)", color = "red")
# === STEP 4: Check Quantile Crossing ===
# Predict quantiles at different education levels
edu_range <- seq(10, 20, by = 2)
pred_data <- expand.grid(education = edu_range, tau = taus)
pred_data$experience <- mean(data$experience) # Hold experience at mean
# Get predictions
predictions <- NULL
for (tau in taus) {
temp <- data.frame(
education = edu_range,
experience = mean(data$experience)
)
temp$income_pred <- predict(rq(income ~ education + experience, tau = tau, data = data),
newdata = temp)
temp$tau <- tau
predictions <- rbind(predictions, temp)
}
ggplot(predictions, aes(x = education, y = income_pred, color = factor(tau), group = tau)) +
geom_line(size = 1) +
labs(title = "Predicted Income Quantiles by Education",
subtitle = "Lines should not cross(monotonicity check)",
x = "Years of Education",
y = "Predicted Income($1000s)",
color = "Quantile(τ)") +
scale_color_brewer(palette = "RdYlBu") +
theme_classic()
# === STEP 5: Test for Coefficient Equality Across Quantiles ===
# Wald test: Are education effects equal across quantiles?
anovatest <- anova(qr_models, test = "Wald", joint = FALSE)
print(anovatest)
# === APA-Style Reporting ===
cat("\n=== Results Summary ===\n")
cat("Quantile regression revealed heterogeneous education returns across the\n")
cat("income distribution. At the 10th percentile, each additional year of\n")
cat("education was associated with $", round(coefs["education", "tau= 0.10"], 2),
"k higher income.\n")
cat("At the 90th percentile, the return increased to $",
round(coefs["education", "tau= 0.90"], 2), "k per year(95% CI [X, X]).\n")
cat("Wald tests confirmed coefficients differed significantly across quantiles\n")
cat(", highlighting distributional heterogeneity missed by OLS(constant\n")
cat("effect = $", round(coef(ols_model)["education"], 2), "k).\n")Quantile regression reveals education returns vary substantially across the income distribution (τ=0.1: β=2.1k, τ=0.9: β=4.2k per year, both p<.001). OLS estimates constant effect (β=2.8k), masking this heterogeneity. High-income earners benefit ~2x more from additional education than low-income earners. Wald tests confirm coefficients differ significantly across quantiles (χ²=45.3, p<.001). Findings support human capital theory's prediction of complementarity between education and unobserved ability.
Alternatives
Structured fallback pathways for choosing alternative tests when normality or slopes requirements fail.
- OLS Regression — Return to the mean-based path if the effect is consistent across all quantiles (homoscedasticity).
- Quantile Smoothing Splines (QGAM) — Apply non-parametric smoothing to the quantile link function to stabilize estimates.
- Multiple Imputation QR — Resample the distribution to fill gaps before the quantile strike.
Post-hoc
Group mean comparisons and correction controls (e.g. Tukey HSD, Bonferroni) to protect against Family-Wise Error Rates.
Post-hoc pairwise tests defined for this model.
No specific guidelines provided.
Effect Size
Understanding effect sizes (e.g., Cohen's d, Partial Eta-Squared) and clinical impact benchmarks.
Interpret βτ as the change in the τth conditional quantile of Y for a 1-unit increase in X, holding other variables constant. Example: β0.75 = 2.5 means 1-unit increase in X raises the 75th percentile of Y by 2.5 units. Compare coefficients across quantiles to assess heterogeneous effects
R1 (Koenker & Machado, 1999) analogous to R² but for quantile regression. Ranges 0-1. Interpretation less straightforward than OLS R². Values typically lower than OLS R²
Difference β0.75 - β0.25 shows how effect varies between upper and lower quartiles. Large differences indicate heterogeneous treatment effects across distribution
0.2
0.5
0.8
Sample Size
Guidelines for minimum sample requirements and power analysis parameters.
The 'Tau Buffer': A minimum of 100 participants is essential for modelling quantiles beyond the median. Extremity discovery (e.g., 90th percentile) requires enough participants in the 'Tail' to stabilize the coefficient.
| Effect Size | Parameters | Required n |
|---|---|---|
| Small Effect | Median Shift (Small) | n ≈ 600 total |
| Medium Effect | Median Shift (Medium) | n ≈ 110 total |
| Large Effect | Median Shift (Large) | n ≈ 50 total |
The 'Tail Penalty': When your discovery target is at the 90th percentile (the high performers), you are only 'Listening' to 10% of your data. You must quadruple your sample size to ensure the high-quantile estimate isn't just measuring random noise.
Reporting
How to compile statistical results into publication prose matching APA and journal style guides.
Quantile regression was conducted to examine the relationship between predictor and outcome across the outcome distribution. If applicable: Due to [right-skewed distribution / outliers / heterogeneous effects, quantile regression was preferred over OLS.] Models were estimated at quantiles τ = 0.1, 0.25, 0.5, 0.75, 0.9. Bootstrap standard errors (B = 1000) were used for inference. At the Xth percentile, each unit increase in predictor was associated with β unit change in outcome (95% CI X, X, p = .XXX). Coefficients varied significantly across quantiles (Wald χ² = X.XX, p < .001), with describe pattern: e.g., 'stronger effects at upper quantiles'. If comparing to OLS: In contrast, OLS estimated a constant effect of β = X.XX, masking this distributional heterogeneity.
- Quantile-specific coefficients (βτ) with 95% CIs
- p-values for each quantile
- Bootstrap specifications (number of replicates B)
- Test of coefficient equality across quantiles (Wald test)
- Comparison to OLS if relevant
- Sample size and quantiles examined
Manuscript Lab
Copy standard summary tables and forensic reporting grids to outline analysis details.
| Predictor | OLS (Mean) | p | Q50 (Median) | p | Q90 (High) | p |
|---|---|---|---|---|---|---|
| Age | 45.2 | .004 | 38.5 | .012 | 112.4 | < .001 |
| Chronic Condition | 1205 | < .001 | 850 | < .001 | 4520 | < .001 |
The 'Upper Bound' Audit. Measures the effect of the predictor on the highest 10% of spenders. Vital for healthcare resource planning.
While OLS looks at the 'Average' person, Quantile regression looks at different 'Profiles' (e.g., low-performers vs high-performers).
Command Center
Syntax libraries and function parameters for executing calculations in stats packages.
# 1. Fit Quantile Regression (Median)
model_q50 <- quantreg::rq(expenditure ~ age + condition, data = df, tau = 0.5)
# 2. Fit Multiple Quantiles Simultaneously
model_multi <- quantreg::rq(expenditure ~ age + condition, data = df, tau = c(0.1, 0.5, 0.9))
# 3. Visualize Coefficients across Quantiles
plot(summary(model_multi))OLS is the regression of the 'Average'. Quantile regression is the regression of 'Reality'. It is robust to outliers and reveals unequal effects across the population.
# Execute Wald Test to see if coefficients differ significantly across quantiles
anova(model_q10, model_q50, model_q90)Common Mistakes
Analytical caveats and corrections to maintain modeling integrity.
References
Scholarly lineage and citation keys grounding the statistical framework.