Re: [R] smooth.spline

From: <rkevinburton_at_charter.net>
Date: Sat, 19 Jul 2008 20:43:04 -0700


Fair enough. FOr a spline interpolation I can do the following:

> n <- 9
> x <- 1:n
> y <- rnorm(n)
> plot(x, y, main = paste("spline[fun](.) through", n, "points"))
> lines(spline(x, y))

Then look at the coefficients generated as:

> f <- splinefun(x, y)
> ls(envir = environment(f))

[1] "ties" "ux" "z"
> splinecoef <- get("z", envir = environment(f))
> slinecoef

$method
[1] 3

$n
[1] 9

$x
[1] 1 2 3 4 5 6 7 8 9

$y
[1] 0.93571604 0.44240485 0.45451903 -0.96207396 -1.13246522 -0.60032698 [7] -1.77506105 -0.09171419 -0.23262573

$b
[1] -1.53673409 0.22775629 -0.81788209 -1.16966436 0.73558677 -0.68744178 [7] 0.08639287 1.86770869 -2.92992167

$c
[1] 1.3657783 0.3987121 -1.4443504 1.0925682 0.8126830 -2.2357115 3.0095462 [8] -1.2282303 -3.5694000

$d
[1] -0.32235542 -0.61435416 0.84563953 -0.09329507 -1.01613149 1.74841922 [7] -1.41259217 -0.78038989 -0.78038989

WHen I look at ?spline there is even an example of "manually" using these coefficeients:

## Manual spline evaluation --- demo the coefficients : .x <- get("ux", envir = environment(f))
u <- seq(3,6, by = 0.25)
(ii <- findInterval(u, .x))
dx <- u - .x[ii]
f.u <- with(splinecoef,

            y[ii] + dx*(b[ii] + dx*(c[ii] + dx* d[ii]))) stopifnot(all.equal(f(u), f.u))

For the smooth.spline as

spl <- smooth.spline(x,y)

I can also look at the coefficients:

spl$fit
$knot
 [1] 0.000 0.000 0.000 0.000 0.125 0.250 0.375 0.500 0.625 0.750 0.875 1.000 [13] 1.000 1.000 1.000

$nk
[1] 11

$min
[1] 1

$range
[1] 8

$coef
 [1] 0.90345898 0.73823276 0.40777431 -0.08046715 -0.54625461 -0.85205147  [7] -0.96233408 -0.91373830 -0.66529714 -0.47674774 -0.38246971

attr(,"class")
[1] "smooth.spline.fit"

But there isn't an example on how to "manual" use these coefficients. This is what I was asking about. Once I hae the coefficients how do I "manually" interpolate using the coefficients given and x.

Thank you.

Kevin


R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 20 Jul 2008 - 03:54:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 20 Jul 2008 - 15:32:00 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive