Last data update: 2014.03.03

R: Create a Periodic Interpolation Spline
periodicSplineR Documentation

Create a Periodic Interpolation Spline

Description

Create a periodic interpolation spline, either from x and y vectors, or from a formula/data.frame combination.

Usage

periodicSpline(obj1, obj2, knots, period = 2*pi, ord = 4)

Arguments

obj1

either a numeric vector of x values or a formula.

obj2

if obj1 is numeric this should be a numeric vector of the same length. If obj1 is a formula this can be an optional data frame in which to evaluate the names in the formula.

knots

optional numeric vector of knot positions.

period

positive numeric value giving the period for the periodic spline. Defaults to 2 * pi.

ord

integer giving the order of the spline, at least 2. Defaults to 4. See splineOrder for a definition of the order of a spline.

Value

An object that inherits from class spline. The object can be in the B-spline representation, in which case it will be a pbSpline object, or in the piecewise polynomial representation (a ppolySpline object).

Author(s)

Douglas Bates and Bill Venables

See Also

splineKnots, interpSpline

Examples

require(graphics); require(stats)
xx <- seq( -pi, pi, length.out = 16 )[-1]
yy <- sin( xx )
frm <- data.frame( xx, yy )
pispl <- periodicSpline( xx, yy, period = 2 * pi)
pispl
pispl2 <- periodicSpline( yy ~ xx, frm, period = 2 * pi )
stopifnot(all.equal(pispl, pispl2))  # pispl and pispl2 are the same

plot( pispl )          # displays over one period
points( yy ~ xx, col = "brown")
plot( predict( pispl, seq(-3*pi, 3*pi, length.out = 101) ), type = "l" )

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(splines)
> png(filename="/home/ddbj/snapshot/RGM3/R_rel/result/splines/periodicSpline.Rd_%03d_medium.png", width=480, height=480)
> ### Name: periodicSpline
> ### Title: Create a Periodic Interpolation Spline
> ### Aliases: periodicSpline
> ### Keywords: models
> 
> ### ** Examples
> 
> require(graphics); require(stats)
> xx <- seq( -pi, pi, length.out = 16 )[-1]
> yy <- sin( xx )
> frm <- data.frame( xx, yy )
> pispl <- periodicSpline( xx, yy, period = 2 * pi)
> ## No test: 
> pispl
bSpline representation of spline for yy ~ xx
     -3.97935      -3.56047      -3.14159      -2.72271      -2.30383 
           NA            NA            NA            NA  2.747662e-16 
     -1.88496      -1.46608      -1.04720      -0.62832      -0.20944 
-4.188059e-01 -7.651964e-01 -9.792775e-01 -1.024033e+00 -8.917232e-01 
      0.20944       0.62832       1.04720       1.46608       1.88496 
-6.052268e-01 -2.140811e-01  2.140811e-01  6.052268e-01  8.917232e-01 
      2.30383       2.72271       3.14159       3.56047       3.97935 
 1.024033e+00  9.792775e-01  7.651964e-01  4.188059e-01  2.747662e-16 
      4.39823       4.81711 
-4.188059e-01 -7.651964e-01 
> ## End(No test)
> pispl2 <- periodicSpline( yy ~ xx, frm, period = 2 * pi )
> stopifnot(all.equal(pispl, pispl2))  # pispl and pispl2 are the same
> 
> plot( pispl )          # displays over one period
> points( yy ~ xx, col = "brown")
> plot( predict( pispl, seq(-3*pi, 3*pi, length.out = 101) ), type = "l" )
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>