Method · Statistics Library

Ridge regression

Ridge regression adds an L2 penalty to ordinary least squares that shrinks every coefficient toward (but never exactly to) zero, trading a small amount of bias for a large reduction in variance when predictors are correlated or numerous.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

When predictors are correlated with each other, ordinary regression's coefficients can become wildly unstable: tiny changes in the data can swing an estimated effect from strongly positive to strongly negative, because the model cannot cleanly separate what each correlated predictor is contributing on its own. Ridge regression fixes this by adding a penalty for having large coefficients at all, which shrinks every coefficient toward zero (though, unlike lasso, never exactly to zero; every predictor stays in the model, just with a smaller weight).

This is a genuine trade-off, not a free lunch: shrinking coefficients introduces a small, deliberate BIAS (the estimates are no longer exactly unbiased in the classical sense), but it buys a large reduction in VARIANCE (the estimates stop swinging wildly with small changes in the data). On correlated or noisy data, this trade usually comes out ahead: the overall prediction error often drops even though no individual coefficient is technically 'correct' anymore.

A subtle but important reading trap: because ridge never drops any predictor, EVERY row in its coefficient table is there by construction, whether or not that predictor is actually useful. A small ridge coefficient is not proof a predictor doesn't matter: the penalty pulls hardest on predictors with the least independent variation, so a real effect can get absorbed into a small-looking number just as easily as a genuinely weak one can.

Ridge regression uses L2 regularization, also called Tikhonov regularization: a penalty on the squared size of the coefficients that shrinks them toward zero without dropping any.

Practitioner explanation

KernelStats minimizes sum((y-y-hat)^2) + alpha*sum(beta_j^2), standardizing predictors by default (the penalty depends on each predictor's scale, so an unscaled predictor in large units would be unfairly protected) and reporting coefficients per one-SD change. The penalty strength alpha is chosen by CROSS-VALIDATION by default, specifically efficient LEAVE-ONE-OUT cross-validation via RidgeCV (the same idea as glmnet's cv.glmnet), scoring a grid of alpha values and keeping the one minimizing out-of-sample error, with the validation curve and chosen alpha shown on the card. This is explicitly what prevents the classic failure mode where an arbitrarily chosen fixed alpha happens to shrink every coefficient toward an unhelpfully small value.

The product states three specific, non-obvious reading cautions about ridge coefficients rather than leaving them implicit: (1) a small ridge coefficient is NOT evidence of 'no effect': the penalty pulls hardest on predictors with the LEAST independent variation, so a near-zero coefficient can reflect either a genuinely weak effect or a real effect the penalty absorbed, and the two look identical in the output; (2) correlated predictors SPLIT the shared signal between them (unlike lasso, which tends to keep one and drop the rest): each correlated predictor in a group can look roughly half as important as the group collectively really is, so correlated predictors should be read together, not ranked individually; (3) ridge estimates are BIASED ON PURPOSE and should never be compared directly to OLS coefficients, or to a ridge fit at a different alpha, since they buy stability with bias rather than being unbiased effect estimates.

As with lasso and elastic net, this penalized estimator produces NO valid classical p-values or standard errors: the bias introduced by the penalty breaks the sampling-theory assumptions ordinary least-squares inference depends on, and the product's explicit guidance for formal inference is to refit OLS on the selected predictors if needed, with the post-selection-inference caveat that reusing the same data to select and test understates true uncertainty.

When to use it

Consider it when

Predictors are correlated with each other or numerous relative to the sample size, causing ordinary least squares to produce unstable, high-variance coefficients, and you want every predictor retained (no feature selection) with stabilized estimates.

Use caution when

You want a sparse model that drops unhelpful predictors entirely (use lasso or elastic net instead), or you need valid p-values and confidence intervals on individual coefficients (refit ordinary least squares, with the post-selection-inference caveat if predictors were chosen based on this fit, or use linear regression from the start).

Formulas and symbols

Ridge objective

∑i(yi−y^i)2+α∑jβj2\sum_i (y_i - \hat y_i)^2 + \alpha \sum_j \beta_j^2

alpha the penalty strength, chosen by leave-one-out cross-validation by default. The L2 penalty (sum of squared coefficients) shrinks every coefficient toward, but never exactly to, zero.

R-squared and RMSE

R2=1−SSresSStot,RMSE=SSresnR^2 = 1 - \dfrac{SS_{res}}{SS_{tot}}, \qquad RMSE = \sqrt{\dfrac{SS_{res}}{n}}

Descriptive fit measures reported alongside the shrunken coefficients; not accompanied by p-values.

Assumptions and checks

  • Linearity. Ridge regression models the outcome as a LINEAR function of the (possibly transformed) predictors; genuine curvature in the true relationship is not captured and biases predictions systematically in regions where the relationship bends.

    In KernelStats: Not checked by KernelStats: no residual or linearity diagnostic is run for this method, unlike Linear Regression's diagnostics; inspect residual plots manually or compare against a nonlinear alternative (e.g. Generalized Additive Model (GAM), Spline Regression).

  • Normality (of residuals, not of the raw data). Any informal reading of the coefficient magnitudes implicitly leans on the same normal-errors assumption as ordinary least squares; non-normal or heteroscedastic residuals are not flagged here the way they are for Linear Regression.

    In KernelStats: Not checked by KernelStats: no residual normality or homoscedasticity diagnostic is computed for this method.

  • No (severe) multicollinearity. Ridge is specifically chosen to stabilize coefficients among correlated predictors by shrinking them together (rather than selecting among them as lasso does); with alpha set too low, severely collinear predictors can still produce unstable, poorly-determined individual coefficients even though the overall fit and predictions remain fine.

    In KernelStats: Not checked by KernelStats as a formal assumption row: no VIF or collinearity diagnostic is computed for this method; the chosen alpha and resulting coefficients are reported directly.

  • The regularization strength (alpha) is chosen by the analyst or by an internal cross-validation search; a poorly chosen or poorly validated alpha can under- or over-shrink the coefficients, changing how much they are pulled toward zero.

    In KernelStats: Not checked by KernelStats as a formal assumption row: the chosen alpha and the resulting coefficients are reported directly; compare against Cross-Validated Model Comparison for an honest cross-validated comparison across model families.

Alternatives

  • Lasso Regression. You want automatic feature selection (coefficients driven to exactly zero) rather than retaining every predictor with shrunken weights.
  • Elastic Net Regression. You want both shrinkage and some feature selection combined, especially with groups of correlated predictors.
  • Linear Regression. Predictors are not meaningfully collinear and valid p-values/confidence intervals on individual coefficients are needed.

Worked example

Scenario

Predicting penguin body mass from three correlated measurements (bill length, bill depth, flipper length), standardized, with alpha chosen by leave-one-out cross-validation over a grid from 0.001 to 1000.

Result

Cross-validation selects a small alpha = 0.81; all three standardized coefficients remain nonzero (flipper length +701 g per SD, bill depth +37 g, bill length +25 g) and R-squared = 0.76, essentially the OLS fit.

Interpretation

With only three predictors and 342 rows the collinearity is mild, so leave-one-out cross-validation picks almost no shrinkage and ridge lands on nearly the OLS answer. That is itself informative: ridge only earns its keep when predictors are strongly entangled or numerous relative to n. The small bill coefficients here are small because flipper length already carries the signal, not because the penalty absorbed them.

Dataset: penguins.csv

Common misconceptions

Misconception

A ridge coefficient close to zero proves that predictor has no real effect on the outcome.

Correction

The ridge penalty pulls EVERY coefficient toward zero, and it pulls hardest on predictors with the LEAST independent variation (often exactly the predictors most entangled with others). A near-zero ridge coefficient can reflect a genuinely weak effect, OR a real effect that the penalty happened to absorb because that predictor shared variation with others in the model; the two look identical in the reported table, so a small coefficient alone is not evidence of 'no effect'.

Read more: Misconception: a high R-squared means the model will predict accurately on new data

Misconception

When two correlated predictors both get modest, similar-sized ridge coefficients, that means each one individually has a modest effect.

Correction

Ridge SPLITS shared signal between correlated predictors rather than assigning it to one of them (the opposite of lasso's tendency to keep one and zero the other). Two correlated predictors each showing a moderate coefficient can mean the PAIR together carries a large, important effect that ridge has simply divided between them; correlated predictors should be read together as a group, not ranked as if each coefficient stood alone.

References

  1. Ridge Regression: Biased Estimation for Nonorthogonal Problems, Hoerl, A. E. and Kennard, R. W. (1970), Technometrics, 12(1), 55-67.
  2. An Introduction to Statistical Learning with Applications in R (2nd ed.), Chapter 6, James, G., Witten, D., Hastie, T. and Tibshirani, R. (2021).