as.dierckx: Convert a spline object to class 'dierckx'

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Translate a spline object of another class into DierckxSpline (class dierckx) format.

Usage

1
2
3
as.dierckx(x)
## S3 method for class 'fd'
as.dierckx(x)

Arguments

x

an object to be converted to class dierckx.

Details

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.

Value

as.fd.dierckx converts an object of class 'dierckx' into one of class fd.

Author(s)

Spencer Graves

References

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.

See Also

as.fd fd curfit

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)) {
#  as.fd was not exported;  now it is,
#  but I need fda:::as.fd temporarily
  curfit.fd <- fda:::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.
}

DierckxSpline documentation built on May 2, 2019, 6:30 p.m.