LZG
LZG

Reputation: 59

Natural spline basis in R

Hi all, I hope you can help me on this problem. I am using the ns(...) command in R to generate a base of natural splines, including

Let's say as an example, ns(1:20, knots=9, Boundary.knots=c(1,15), intercept=T). I have some questions that I'm struggling a lot to solve by myself, namely:

  1. R returns a basis of 3 polynomials: why 3?
  2. What is the equation of the 3 polynomials of this basis?
  3. Natural splines provide the constraint that after the boundary knots the extrapolation is linear (which is not exactly what I would like for my purpose): how should I instead impose the constraint that the extrapolation is actually constant (i.e. flat) after my rightmost boundary knot?

Thank you very much for all your help with this, you would help me a lot!

Best, EM

Upvotes: 0

Views: 1565

Answers (1)

Paco
Paco

Reputation: 1

For a natural spline the number of basis is equal to the number of knots. Useful reference https://stats.stackexchange.com/questions/172217/why-are-the-basis-functions-for-natural-cubic-splines-expressed-as-they-are-es

The natural spline constraint is that s''(first knot)=0 and s''(last knot)=0

To enforce s' = 0 as you want - would not be a natural spline

Upvotes: 0

Related Questions