3

ns() function in R can generate the natural cubic spline basis matrix. I checked the reference but still do not know how to calculate such matrix by hand.

For example, I have x = (-2.377, 0.029, 0.106, 2.184). Using ns function with df =3, I can get:

[1,]  0.0000000 0.0000000  0.0000000
[2,]  0.2534264 0.5250116 -0.2672809
[3,]  0.3119701 0.5053060 -0.2565989
[4,] -0.1665931 0.3393594  0.8272338

attr(,"degree")
[1] 3

attr(,"knots")
33.33333% 66.66667% 
0.029     0.106 

attr(,"Boundary.knots")
[1] -2.377  2.184

attr(,"intercept")
[1] FALSE

attr(,"class")
[1] "ns"     "basis"  "matrix"

Can anybody tell me how to calculate each value in the matrix?

Thank you so much.

Frans Rodenburg
  • 10,376
  • 2
  • 25
  • 58
cow3918
  • 31
  • 4

0 Answers0