5
$\begingroup$

I am new to the use of cubic splines for regression purposes and wanted to find out

1) What is a good source (besides ESL which I read but am still uncertain) to learn about splines for regression?
2) How would you calculate the basis of a given natural cubic spline solution on new data? Specifically if one were to do the following:

data(iris)
colnames(iris)
Sepal.Length.ns<-ns(iris$Sepal.Length,df=5)
Sepal.Length.ns

How would you take the information in Sepal.Length.ns (knots, boundaries) and compute the values for a new observation? The reason is to code this process outside of R, once fit in R initially (i.e. to put a regression model using cubic splines into a production system).

For example I can do this in R, but want to understand the calculation:

#three new observations to predict
newVector<-c(4.45,3.35,2.2)
pred.new<-predict(Sepal.Length.ns,newVector)

Thanks!

$\endgroup$
  • $\begingroup$ try ?splinefun $\endgroup$ – David LeBauer Apr 8 '11 at 2:20
4
$\begingroup$

Wikipedia has a nice explanation of spline interpolation

I posted the code to create cubic Bezier splines on Rosettacode a while ago.

Also, you can have a look at this discussion on SO about spline extrapolation.

$\endgroup$
  • $\begingroup$ Do these show how to calculate the new variables from new data (i.e what predict() is doing)? $\endgroup$ – B_Miner Apr 8 '11 at 13:07
  • $\begingroup$ @B_Miner: yes, the SO link does. $\endgroup$ – nico Apr 8 '11 at 13:09
  • $\begingroup$ Why the downvote? $\endgroup$ – nico Apr 8 '11 at 14:25
  • $\begingroup$ Sorry Nico, I went to click on the other button! It wont let me change it. I will try to edit your answer ever so slightly and then vote it up. I am still trying to figure out how exactly to use compute the variables, seems there must be a simple formula that I am just not seeing in the SO post. $\endgroup$ – B_Miner Apr 8 '11 at 17:07
  • $\begingroup$ @B_Miner: don't worry, no problem. PS: depending on the type/amount of data you have, you may want to have a look at LOESS regression. $\endgroup$ – nico Apr 9 '11 at 6:20
1
$\begingroup$

I learnt about the use of splines in regression from the book "Regression Modeling Strategies" by Frank Harrell. Harrell's R package rms allows you to easily fit regression models in which some predictor variables are represented as splines.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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