is there a way to know the knots used by spline()?

133 views Asked by At

I use the function spline() to have a spline between x and y, as output I have a list of 2 elements (x e y), is there a way to know the knots used by spline()??

1

There are 1 answers

6
agenis On

See the help page for ?spline, it explains it quite well that the default default number of knots is three times the number of x points

spline(x, y = NULL, n = 3*length(x), method = "fmm", xmin = min(x), xmax = max(x), xout, ties = mean)

"n" if xout is left unspecified, interpolation takes place at n equally spaced points spanning the interval [xmin, xmax].

Lets check it out:

sp <- spline(x=1:3, y=rnorm(3))
print(sp$x)
#### [1] 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00
seq(from=1, to=3, length.out=3*3)
#### [1] 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00