Understand the idea
When a scatter of two variables shows a clear bend rather than a straight line, polynomial regression lets the fitted curve bend too, by adding higher powers of the predictor (x-squared for one bend, x-cubed for two bends, and so on). It is still technically a 'linear' model in the statistical sense (linear in the COEFFICIENTS being estimated), so all the familiar regression machinery (R-squared, F-tests, confidence bands) still applies cleanly.
This card does something specific and useful: rather than just handing you a fixed-degree curve and hoping it's right, it builds curves of degree 1, 2, 3, and so on, and tests EACH added degree to see whether it genuinely improves the fit beyond what the previous, simpler degree already achieved. Read that table from the top down and stop adding degrees once a degree stops earning its place: that is the recommended, simplest degree the data actually support.
A crucial warning that applies to every polynomial curve, however well it fits: never trust predictions OUTSIDE the range of your actual data. Polynomials of degree 2 or higher shoot off toward positive or negative infinity as you move away from the observed data, so a prediction just past the edge of what you measured can be wildly, confidently wrong even when the fit inside the data looks excellent.
A degree-2 polynomial fit is called quadratic regression and a degree-3 fit cubic regression. An orthogonal polynomial basis rewrites x, x squared and x cubed as unrelated columns, so the fit is numerically stable and each degree can be tested on its own. A per-degree ANOVA tests whether each added power of x improves the fit, which helps choose the degree.
Practitioner explanation
KernelStats fits on an ORTHOGONAL polynomial basis (the same construction as R's poly()) rather than raw powers x, x^2, x^3, ...: raw powers are highly correlated with each other for positive x, making the fit numerically unstable and individual coefficients uninterpretable. The orthogonal basis is mathematically just a rotation of the same fit, so the fitted curve, R-squared, and overall F-statistic are IDENTICAL to what raw powers would give; what changes is that each term's own t-test becomes a genuine 'does this specific degree add anything beyond the lower ones' test, and the highest-degree term's t-squared is shown to EQUAL the sequential F-test for adding that degree, two different ways of asking the same question that agree exactly by construction.
The per-degree ANOVA fits nested models of degree 1, 2, ..., d and compares each to the one below via a partial F-test on the change in residual sum of squares; a recommended_degree is surfaced directly from this table rather than left for the analyst to eyeball. Over-fitting is flagged explicitly (the overfit flag on the card) using multiple signals together: added high-degree terms that are NOT significant in the per-degree ANOVA, adjusted R-squared that stops rising (or falls) as degree climbs, and a curve with visibly wild wiggles between observed data points.
The predictor needs strictly MORE distinct values than the polynomial degree requested (a degree-3 fit needs at least 4 distinct x values, refused by name otherwise), and the confidence band on the fitted-curve plot is deliberately drawn WIDENING toward the edges of the observed x-range as a visual reminder that polynomial extrapolation is unreliable; the product states plainly that predictions beyond the data's x-range should not be trusted regardless of how good the in-range fit looks, and recommends a mechanistic model instead of extrapolating a polynomial.
When to use it
Consider it when
A scatterplot of a continuous outcome against a single continuous predictor shows a smooth bend a straight line clearly misses, and you want to formally test how many polynomial degrees the data actually justify.
Use caution when
You need to predict OUTSIDE the observed range of the predictor (polynomials explode near and beyond the edges of the data; use a mechanistic model instead), the true relationship is not well described by any low polynomial degree (splines or a GAM handle local flexibility with far less instability), or more than one predictor is involved (this function fits exactly one predictor's curve).
Formulas and symbols
Polynomial regression model
d the polynomial degree (1=line, 2=parabola, 3+=more bends); fit on an orthogonal basis for numerical stability.
Per-degree partial F-test
Tests whether adding degree d significantly improves the fit over degree d-1; a small p-value supports keeping that degree.
Adjusted R-squared
Used alongside the per-degree ANOVA as an over-fitting signal: adjusted R-squared that stops rising (or falls) as degree increases flags an unsupported higher-degree term.
Assumptions and checks
- If the highest-degree term in the fitted polynomial is not itself statistically significant, the chosen degree is likely higher than the data actually supports, and a lower-degree fit would describe the relationship just as well with less risk of over-fitting the noise.
In KernelStats: Checked directly: the card tests the significance of the top-degree term and flags it as a warning when not significant, alongside a per-degree ANOVA recommendation for a lower degree.
- Polynomials of increasing degree can chase noise in the training data (over-fitting) rather than capturing genuine curvature, producing wiggles that do not generalize to new data even as in-sample R-squared keeps climbing.
In KernelStats: Checked directly: a per-degree ANOVA comparison is run and the card flags a warning when the fitted degree exceeds what that comparison actually supports.
- Polynomial curves diverge rapidly outside the range of the predictor actually observed; a prediction for an x-value beyond that range can be wildly wrong even when the fit inside the observed range looks excellent.
In KernelStats: Checked directly: the card states the observed predictor range and warns against trusting predictions or confidence bands beyond it.
Alternatives
- Spline Regression. The relationship needs local flexibility that a single global polynomial degree cannot capture well, without polynomial regression's extrapolation instability.
- Generalized Additive Model (GAM). You want a smooth, data-driven curve combined additively with other predictors in one model, rather than a single explicit polynomial equation for one predictor.
- LOESS (Local Regression Smoothing). You want to explore the shape of the relationship first, without committing to any parametric degree, before deciding whether polynomial regression is the right formal model.
Worked example
Scenario
Fitting body mass as a function of flipper length with a maximum degree of 3, testing whether a cubic term is justified.
Result
The per-degree ANOVA shows degree 2 improves over degree 1 (F = 24.6, p < .001) and degree 3 improves over degree 2 (F = 7.0, p = .009), so recommended_degree = 3; but R-squared only moves from 0.759 (line) to 0.775 (quadratic) to 0.780 (cubic).
Interpretation
With 342 birds, even a two-point gain in R-squared is statistically detectable, so every added degree 'earns its place' by the F-test while changing the practical picture very little. The bends are also likely to reflect the three species being pooled rather than a biological curve; modeling species directly, or staying with the straight line for description, is the more defensible reading than reporting a cubic.
Dataset: penguins.csv
Common misconceptions
Misconception
A polynomial curve that fits the observed data extremely well can be trusted to extrapolate reasonably just past the edge of that data.
Correction
Polynomials of degree 2 or higher mathematically EXPLODE toward positive or negative infinity outside the range they were fit on; a cubic term in particular can shoot off dramatically. However good the fit looks WITHIN the observed data, predictions just beyond its edge can be wildly wrong with high apparent confidence; the widening confidence band near the edges of the plot is a direct visual warning of this, not decoration.
Misconception
Adding more polynomial degrees always makes the fit better and should be preferred when R-squared keeps rising.
Correction
Ordinary R-squared can never decrease as you add more polynomial degrees, even degrees that model pure noise rather than real signal, which is exactly why the per-degree ANOVA and ADJUSTED R-squared exist. Prefer the simplest degree that the per-degree ANOVA actually supports (each added degree earning a significant improvement), not the highest degree with the largest raw R-squared.
References
- An Introduction to Statistical Learning with Applications in R (2nd ed.), Chapter 7, James, G., Witten, D., Hastie, T. and Tibshirani, R. (2021).
- Applied Regression Analysis, Draper, N. R. and Smith, H. (1998).
