as.dierckx {DierckxSpline} | R Documentation |
Translate a spline object of another class into DierckxSpline (class
dierckx
) format.
as.dierckx(x) ## S3 method for class 'fd': as.dierckx(x)
x |
an object to be converted to class dierckx .
|
The behavior depends on the class
and nature of x
. In
particular, the DierckxSpline
package only supports splines of
order between 2 and 6, degree between 1 and 5, for linear through
quintic splines. Other packages, e.g., fda
support splines
over a wider range and non-spline basis functions such as finite
Fourier series. When these are encountered, as.dierckx
throws
an error.
dierckx
object are constructed from a spline object of a different class:
as.fd.dierckx
converts an object of class 'dierckx' into one of
class fd
.
Spencer Graves
Dierckx, P. (1991) Curve and Surface Fitting with Splines, Oxford Science Publications.
Ramsay, James O., and Silverman, Bernard W. (2006), Functional Data Analysis, 2nd ed., Springer, New York.
Ramsay, James O., and Silverman, Bernard W. (2002), Applied Functional Data Analysis, Springer, New York.
x <- 0:24 y <- c(1.0,1.0,1.4,1.1,1.0,1.0,4.0,9.0,13.0, 13.4,12.8,13.1,13.0,14.0,13.0,13.5, 10.0,2.0,3.0,2.5,2.5,2.5,3.0,4.0,3.5) curfit.xy <- curfit(x, y, s=0) if(require(fda)) { curfit.fd <- as.fd(curfit.xy) plot(curfit.fd) # as an 'fd' object points(x, y) # Curve goes through the points. x. <- seq(0, 24, length=241) pred.y <- predict(curfit.xy, x.) lines(x., pred.y, lty="dashed", lwd=3, col="blue") # dierckx and fd objects match. all.equal(knots(curfit.xy, FALSE), knots(curfit.fd, FALSE)) all.equal(coef(curfit.xy), as.vector(coef(curfit.fd))) curfit2 <- as.dierckx(curfit.fd) pred.y2 <- predict(curfit2, x.) sum(abs(pred.y-pred.y2))/(sum(abs(pred.y)+abs(pred.y2))/2) # 1.3e-7 all.equal(knots(curfit.xy, FALSE), knots(curfit2, FALSE)) # TRUE all.equal(coef(curfit.xy), coef(curfit2)) # "Mean relative difference: 4.5e-7 preserved <- c("from", "to", "n", "g", "periodic", "xlim","ylim") all.equal(curfit.xy[preserved], curfit2[preserved]) # TRUE # Other components are NOT preserved in translation # and so can NOT be restored. }