Hi r-helpers.
Please forgive my ignorance, but I would like to plot a smoothing spline
(smooth.spline) from package "stats", and show the knots in the plot, and I
can't seem to figure out where smooth.spline has located the knots (when I
use nknots). Unfortunately, I don't know a lot about splines, but I know
that they provide me an easy way to estimate the location of local maxima
and minima on varying time-scales (number of knots) in my original data.
I see there is a fit$knot, but it's not clear to me what those values are:
for some reason I had expected that they would be contained in my original
y values, but they're not. I tried generating nknots equally spaced points
in my x, but when I plotted the points that corresponded to my original y
values at those equally-spaced x values, I found that the spline did not
pass through them, which, perhaps naively, I thought it might.
Also, the manual says that yin comprises "the y values used at the unique y
values" -- should this read "at the unique x values"?
Could someone kindly point to a resource where I can get a slightly fuller
explanation? I looked at the code for smooth.spline, but can't readily
follow it.
Here's a toy example:
> x<-seq(from=0,to=4*pi,length=1002)
> y<-sin(x)
> ss<-smooth.spline(x,y=y,all.knots=F,nknots=25)
> ss
Call:
smooth.spline(x = x, y = y, all.knots = F, nknots = 25)
Smoothing Parameter spar= -0.4573636 lambda= 1.006117e-09 (14 iterations)
Equivalent Degrees of Freedom (Df): 26.99935
Penalized Criterion: 3.027077e-06
GCV: 3.190666e-09
> str(ss)
List of 15
$ x : num [1:1002] 0 0.0126 0.0251 0.0377 0.0502 ...
$ y : num [1:1002] 2.88e-05 1.26e-02 2.51e-02 3.77e-02 5.02e-02 ...
$ w : num [1:1002] 1 1 1 1 1 1 1 1 1 1 ...
$ yin : num [1:1002] 0 0.0126 0.0251 0.0377 0.0502 ...
$ data :List of 3
..$ x: num [1:1002] 0 0.0126 0.0251 0.0377 0.0502 ...
..$ y: num [1:1002] 0 0.0126 0.0251 0.0377 0.0502 ...
..$ w: num [1:1002] 1 1 1 1 1 1 1 1 1 1 ...
$ lev : num [1:1002] 0.2238 0.177 0.1399 0.1111 0.0891 ...
$ cv.crit : num 3.19e-09
$ pen.crit: num 3.03e-06
$ crit : num 3.19e-09
$ df : num 27
$ spar : num -0.457
$ lambda : num 1.01e-09
$ iparms : Named int [1:3] 1 0 14
..- attr(*, "names")= chr [1:3] "icrit" "ispar" "iter"
$ fit :List of 5
..$ knot : num [1:31] 0 0 0 0 0.041 ...
..$ nk : num 27
..$ min : num 0
..$ range: num 12.6
..$ coef : num [1:27] 2.88e-05 1.72e-01 5.19e-01 9.04e-01 1.05 ...
..- attr(*, "class")= chr "smooth.spline.fit"
$ call : language smooth.spline(x = x, y = y, all.knots = F, nknots =
25)
- attr(*, "class")= chr "smooth.spline"
>
Many thanks!
Regards,
Mike Nielsen
[[alternative HTML version deleted]]