Lifting a Weak Regression Fit While Keeping Effect Estimates Honest
Statistics & ExperimentsModel answerLast updated
Plan how to improve a low-R² per-order profit model without corrupting treatment-effect inference: transformations, CV evidence, nested validation, leakage tests, and when low R² is fine.
You have run an experiment on an online grocery platform. A linear regression predicts profit per order from order and customer features plus a treatment indicator, and it reaches only R² = 0.07. The team wants better predictive performance, but also wants to keep an unbiased, honestly calibrated estimate of the average treatment effect (ATE).
Answer the following.
- Improving the model. Describe concrete steps to raise predictive performance without invalidating inference. Cover feature transformations (for example, a flexible curve for basket size), interactions (for example, treatment by time of day), a more suitable error distribution and link (for example, Gamma with a log link), and checks for leakage.
- Is one more covariate enough? Will simply adding another covariate reliably raise out-of-sample R²? Show with cross-validation why or why not. Then propose alternatives (GAMs, quantile regression, gradient boosting) and explain how each fits with the goal of estimating an effect.
- Guarding against p-hacking. Explain how you would use nested cross-validation and target-leakage tests to avoid fooling yourself while you iterate on the model.
- Low R² in context. Explain when a low R² is perfectly acceptable for an unbiased ATE, and when it is unacceptable for accurate individual-level predictions.
Hints
Hint 1
Separate the two goals: out-of-sample prediction of the outcome, and unbiased estimation of one treatment parameter. Tools that help the first should not be allowed to touch the second.
Hint 2
In-sample R² can never fall when you add a regressor to a nested OLS model, but test error includes a variance cost per estimated parameter. Compare models on identical CV folds and look at the paired differences.
Hint 3
Choose specifications using the outcome only (ideally blind to treatment), and nest every data-dependent choice inside the training portion of an outer loop. A label-permutation run of the whole pipeline should give CV R² near zero or below.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Framing
There are two separate goals:
- Prediction: minimize out-of-sample error for profit per order.
- Inference: estimate a treatment effect without bias and with honest uncertainty.
A strong answer improves (1) with tools that cannot contaminate (2). Profit per order is noisy, heavy-tailed and often negative, so R² = 0.07 is unsurprising. In a randomized experiment it does not by itself indicate a problem.
a) Steps to raise predictive performance
Diagnose first. Plot residuals against fitted values, basket size and time. Check skew, heteroskedasticity and the share of negative-profit orders. Often a few extreme orders (large refunds, bulk purchases) dominate the squared error.
Transformations
- Basket size: a natural cubic spline with 4-5 knots placed at fixed quantiles, chosen before looking at outcomes. Profit typically rises, then plateaus.
- Money-like covariates:
log1pplus capping at pre-declared percentiles. - Store, region and week fixed effects to absorb level differences.
Interactions
- Pre-specify a small set, such as treatment x daypart and basket size x delivery distance.
- A declared interaction is a legitimate heterogeneity estimand. One found by searching is a forking path.
Error distribution
- For strictly positive, right-skewed outcomes, a Gamma GLM with log link gives multiplicative effects and variance that grows with the mean.
- Profit is often negative, which rules out Gamma and Tweedie. Options: model revenue and cost separately and combine, or use Huber or quantile loss.
- Use cluster-robust standard errors by customer or store, because orders within a cluster are correlated.
Leakage checks
- Every feature must be available at prediction time and be pre-treatment. Exclude tips, refunds, final substitutions, realized delivery time and post-order promotions.
- Do not adjust for mediators or colliders when the target is a total effect. If treatment changes basket size, adjusting for post-treatment basket size biases the ATE.
- Split by time and group by customer so the same person is never on both sides of a split.
b) Does adding a covariate reliably raise out-of-sample R²?
No.
- In-sample R² for nested OLS models never decreases, since a coefficient can always be zero.
- Out-of-sample, every estimated parameter adds variance. For Gaussian OLS, expected test MSE is roughly σ²(1 + p/n). An irrelevant covariate raises it, and a weak one helps only if its bias reduction exceeds its variance cost. High-cardinality features and small segments make this worse.
Demonstration with paired folds:
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import KFold, cross_val_score
rng = np.random.default_rng(0)
n = 300
Xs = rng.normal(size=(n, 2))
y = Xs[:, 0] + 0.5 * Xs[:, 1] + rng.standard_t(3, size=n) * 4
cv = KFold(10, shuffle=True, random_state=1)
cv_r2 = lambda X: cross_val_score(LinearRegression(), X, y, cv=cv, scoring="r2")
base = cv_r2(Xs)
for k in [1, 10, 40]:
Xa = np.hstack([Xs, rng.normal(size=(n, k))])
aug = cv_r2(Xa)
ins = LinearRegression().fit(Xa, y).score(Xa, y)
print(k, round(ins, 3), round(aug.mean(), 3), round(base.mean(), 3),
round(np.mean(aug - base), 3))
Expected pattern: in-sample R² climbs with each added noise column while CV R² falls, more so as k grows. With heavy tails, fold-level differences are noisy, so report the mean and spread of the paired differences rather than a single number.
Alternatives and how they fit effect estimation
| Method | Predictive benefit | Fit with effect estimation |
|---|---|---|
| GAM | Smooth nonlinear terms for basket size, distance, time | Treatment stays a parametric, interpretable term; smoothness chosen by REML or CV |
| Quantile regression | Robust to tails; models median and upper quantiles | Estimand becomes a quantile effect, not the ATE, so say so explicitly |
| Gradient boosting | Usually the biggest gain in predictive fit | Do not read effects from it. Use it as a nuisance model in Double ML: cross-fit E[Y|X] and E[T|X], regress residual Y on residual T |
The principle: flexible ML improves the nuisance fit, while the causal parameter stays low-dimensional and is estimated on held-out residuals.
c) Nested CV and leakage tests
Nested cross-validation
- Outer loop (for example 5 time-ordered, customer-grouped folds) is used only to estimate generalization.
- Inner loop, run inside each outer training fold, handles every data-dependent choice: spline degrees of freedom, winsorization thresholds, feature selection and boosting hyperparameters.
- Report the outer mean and spread. Selecting and scoring on the same folds inflates performance, which is the predictive analogue of p-hacking.
- Keep a final time-based holdout and score it once, after the pipeline is frozen.
Rules that protect inference
- Select covariates by how well they predict Y, ideally using the control arm or with treatment masked. Never keep a specification because the treatment p-value improved.
- Pre-register the estimand, primary model and interaction set. Label everything else exploratory.
- Log every specification tried and show the spread of ATE estimates (a specification curve).
- Use Double ML or CUPED-style adjustment so tuning affects variance, not identification.
Leakage tests
- Label permutation: shuffle y and rerun the entire pipeline. CV R² should be at or below zero. A clearly positive value means leakage through preprocessing such as scaling, imputation or target encoding fit on all data.
- Single-feature audit: a feature that alone produces a large jump, or dominates importance, needs a timestamp check against checkout.
- Temporal degradation: compare random-split and forward-in-time performance. A large gap suggests leakage or drift.
- Group leakage: compare random and customer-grouped splits.
d) When low R² is acceptable
Acceptable for the ATE. With randomization, the treatment coefficient is unbiased regardless of R². Low R² only means the outcome has large unexplained noise, which widens confidence intervals. With a large sample, the effect can be precisely estimated. Covariate adjustment can narrow intervals but is not needed for validity.
Unacceptable for individual predictions. If decisions are made per order or per customer (pricing, routing, credit-like decisions), R² = 0.07 means prediction errors are nearly as large as the outcome's own spread. Prediction intervals are very wide and rankings are unreliable. Judge such a model by calibration, error on the decision-relevant region, and lift in the top decile, not just R².
Common mistakes
- Judging a model by in-sample R².
- Tuning and evaluating on the same folds.
- Adjusting for post-treatment variables.
- Using Gamma when outcomes can be negative.
- Ignoring clustering in standard errors.
- Treating a boosting feature importance as a causal effect.