1
$\begingroup$

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:

  1. A spline model with independent variable z (and what is the dependent variable here? exit? end - start?)
  2. A coxph model which then uses the variable x and the output of the spline model (input to the spline model being z), fit using maximum likelihood estimation.

Any help will be appreciated.

$\endgroup$

1 Answer 1

2
$\begingroup$

The second use at the right hand side of the equation is similar to using polynomials in regression. Let the regressor we want to spline be $x$. If the knots are chosen before the fitting, that is, is not seen as parameters to be found in maximizing the likelihood or some other criterion function like sum squares of residuals, this becomes a linear problem. We just use some basis functions for the spline, in R we could use the functions ns for a natural spline basis or bs for a B spline basis, or just a truncated power basis. This has been much discussed at this site, see for instance Spline – basis functions Visualizing a spline basis Is spline basis orthogonal? What is Dimension of basis in splines Deriving the basis functions for natural cubic spline This is no different from the choice you have when using polynomial regression between using the obvious basis $1, x, x^2, \dotsc$ or using some orthogonal polynomials, say.

$\endgroup$
1
  • 1
    $\begingroup$ Thank you. This makes more sense now. $\endgroup$
    – Chaos
    Commented Sep 6, 2020 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.