[R] interpolation and numerical differentiation in R ?
Douglas Bates
bates at stat.wisc.edu
Sun Sep 2 17:14:58 CEST 2001
"Robert D. Merithew" <merithew at ccmr.cornell.edu> writes:
> On 1 Sep 2001, Douglas Bates wrote:
>
> > See interpSpline in the splines library.
> >
> > When evaluating the interpolating spline produced by interpSpline you
> > can specify that you want derivatives instead of the function value.
> perfect. I'd use predict.bSpline, it seems.
It would be predict.npolySpline although you do not usually call
methods like this directly. In the object system for the S language
calling predict on an interpolation spline produced by interpSpline
searches for predict.npolySpline, then predict.polySpline, then
predict.spline then predict.default.
> library(splines)
> data(women)
> ispl2 <- interpSpline(weight ~ height, women)
> class(ispl2)
[1] "npolySpline" "polySpline" "spline"
> methods(predict)
[1] "predict.bSpline" "predict.bs" "predict.nbSpline"
[4] "predict.npolySpline" "predict.ns" "predict.pbSpline"
[7] "predict.polySpline" "predict.ppolySpline" "predict.glm"
[10] "predict.lm" "predict.mlm"
> predict(ispl2)
$x
[1] 58.00 58.28 58.56 58.84 59.12 59.40 59.68 59.96 60.24 60.52 60.80 61.08
[13] 61.36 61.64 61.92 62.20 62.48 62.76 63.04 63.32 63.60 63.88 64.16 64.44
[25] 64.72 65.00 65.28 65.56 65.84 66.12 66.40 66.68 66.96 67.24 67.52 67.80
[37] 68.08 68.36 68.64 68.92 69.20 69.48 69.76 70.04 70.32 70.60 70.88 71.16
[49] 71.44 71.72 72.00
$y
[1] 115.0000 115.4908 116.0170 116.6137 117.3153 118.1214 118.9894 119.8747
[9] 120.7384 121.5787 122.4078 123.2380 124.0759 124.9181 125.7601 126.5980
[17] 127.4340 128.2735 129.1220 129.9792 130.8301 131.6572 132.4454 133.2228
[25] 134.0528 135.0000 136.1000 137.2727 138.4090 139.4026 140.2416 141.0276
[33] 141.8690 142.8564 143.9707 145.1507 146.3356 147.4868 148.6046 149.6935
[41] 150.7604 151.8353 152.9613 154.1817 155.5178 156.9329 158.3808 159.8173
[49] 161.2269 162.6180 164.0000
attr(,"class")
[1] "xyVector"
> predict(ispl2, deriv = 1)
$x
[1] 58.00 58.28 58.56 58.84 59.12 59.40 59.68 59.96 60.24 60.52 60.80 61.08
[13] 61.36 61.64 61.92 62.20 62.48 62.76 63.04 63.32 63.60 63.88 64.16 64.44
[25] 64.72 65.00 65.28 65.56 65.84 66.12 66.40 66.68 66.96 67.24 67.52 67.80
[37] 68.08 68.36 68.64 68.92 69.20 69.48 69.76 70.04 70.32 70.60 70.88 71.16
[49] 71.44 71.72 72.00
$y
[1] 1.731918 1.794971 1.984130 2.299394 2.714477 3.016164 3.157722 3.139151
[9] 3.035441 2.973657 2.955882 2.979670 3.002836 3.010095 3.001447 2.985954
[17] 2.988631 3.010927 3.052004 3.060702 3.006831 2.890390 2.759254 2.831848
[25] 3.135101 3.669014 4.123423 4.188163 3.863236 3.219987 2.837113 2.841450
[33] 3.232999 3.789298 4.133397 4.259116 4.176018 4.049060 3.938009 3.842865
[41] 3.799047 3.904315 4.164333 4.575846 4.940126 5.139893 5.175145 5.078116
[49] 4.995859 4.946505 4.930054
attr(,"class")
[1] "xyVector"
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list