I have seen 2 ways of using splines:
Spline as the primary model:
Here, we use a spline to model y as a function of a single covariate x. That is, it is used as a regression model.
The example in the documentation of the R function
smooth.spline from the
stats package makes it very easy to understand. I have copied this below for reference:
# Look at data - dist (y) vs speed (x) plot(dist ~ speed, data = cars, main = "data(cars) & smoothing splines") # Fit a spline model, modelling dist based on speed cars.spl <- with(cars, smooth.spline(speed, dist)) # View regression line on top of actual data points lines(cars.spl, col = "blue")
The Wikipedia article on Smoothing Splines gives an overview of how the spline model is fit. The idea is to optimize a loss function made up of an MSE term as well as a smoothing term.
Spline as used in the right-hand-side of another model:
Here, we use a spline as a supporting model (my understanding). This is commonly seen in survival analysis, for instance, often described as using "smooth estimates of continuous covariates".
An example (taken from here):
fit<-coxph(Surv(start,end,exit) ~ x + pspline(z))
I find it hard to understand what's going on here. There seem to be 2 models being fit here, simultaneously:
- A spline model with independent variable z (and what is the dependent variable here?
end - start?)
- A coxph model which then uses the variable
xand the output of the spline model (input to the spline model being
z), fit using maximum likelihood estimation.
Any help will be appreciated.