Joins smooth cubic pieces to bend flexibly through data.
splines(knots, x, y)
Key idea
A knot is a chosen cut point on the x-axis. Fit a gentle cubic curve between each pair of knots, joined smoothly with no kinks. (e.g. 4 knots -> 5 cubic pieces)
More knots = more freedom to follow local wiggles.
Splines avoid the wild edge swings of a single high-power formula.
A smoothing spline puts a knot everywhere but adds a roughness penalty to stay smooth.
Definition
f(x)=β0+β1x+β2x2+β3x3+k∑θk(x−ξk)+3
ξk
the knots (join points)
(x−ξk)+3
a cubic that switches on past the knot
θk
how much the curve bends at knot k
In plain words
Rather than one stiff curve for the whole range, bend several smooth pieces and glue them together seamlessly.
Where you'd use it
Modelling a dose–response curve that bends in a non-straight way.
Smoothing a noisy time trend without assuming a formula.
The building block of GAMs — one flexible spline per feature.
Frequently asked questions
What are splines for?
Flexible curve-fitting using piecewise polynomials joined smoothly at knots.