Predicted \(y\) at Q1 (3.23): 8.49
Predicted \(y\) at Q3 (7.67): 7.419
Change for IQR increase in \(x\): -1.071
Why IQR? Represents a “typical” change in \(x\)
IQR-change
Restricted Cubic Splines (Natural Splines)
Better than polynomials for flexible modeling
Key idea:
Piecewise cubic polynomials
Joined smoothly at “knots”
Linear beyond boundary knots
Doesn’t oscillate wildly at boundaries
Why Splines?
Problems with high-degree polynomials:
Unstable at boundaries
All coefficients change when you add data
Global influence: one point affects fit everywhere
Advantages of splines:
Local influence: only nearby regions affected
Stable, smooth fits
More degrees of freedom where you need them
Splines: Visual Intuition
Using Splines in R
The splines package provides ns() function
library(splines)# Fit model with natural spline# df = degrees of freedom (flexibility)model_spline <-lm(y ~ns(x, df =4))# Look at coefficientscoef(model_spline)