Last data update: 2014.03.03

R: Create an Interpolation Spline
interpSplineR Documentation

Create an Interpolation Spline

Description

Create an interpolation spline, either from x and y vectors (default method), or from a formula / data.frame combination (formula method).

Usage

interpSpline(obj1, obj2, bSpline = FALSE, period = NULL,
             na.action = na.fail, sparse = FALSE)

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.

bSpline

if TRUE the b-spline representation is returned, otherwise the piecewise polynomial representation is returned. Defaults to FALSE.

period

an optional positive numeric value giving a period for a periodic interpolation spline.

na.action

a optional function which indicates what should happen when the data contain NAs. The default action (na.omit) is to omit any incomplete observations. The alternative action na.fail causes interpSpline to print an error message and terminate if there are any incomplete observations.

sparse

logical passed to the underlying splineDesign. If true, saves memory and is faster when there are more than a few hundred points.

Value

An object that inherits from (S3) class spline. The object can be in the B-spline representation, in which case it will be of class nbSpline for natural B-spline, or in the piecewise polynomial representation, in which case it will be of class npolySpline.

Author(s)

Douglas Bates and Bill Venables

See Also

splineKnots, splineOrder, periodicSpline.

Examples

require(graphics); require(stats)
ispl <- interpSpline( women$height, women$weight )
ispl2 <- interpSpline( weight ~ height,  women )
# ispl and ispl2 should be the same
plot( predict( ispl, seq( 55, 75, length.out = 51 ) ), type = "l" )
points( women$height, women$weight )
plot( ispl )    # plots over the range of the knots
points( women$height, women$weight )
splineKnots( ispl )

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/interpSpline.Rd_%03d_medium.png", width=480, height=480)
> ### Name: interpSpline
> ### Title: Create an Interpolation Spline
> ### Aliases: interpSpline
> ### Keywords: models
> 
> ### ** Examples
> 
> require(graphics); require(stats)
> ispl <- interpSpline( women$height, women$weight )
> ispl2 <- interpSpline( weight ~ height,  women )
> # ispl and ispl2 should be the same
> plot( predict( ispl, seq( 55, 75, length.out = 51 ) ), type = "l" )
> points( women$height, women$weight )
> plot( ispl )    # plots over the range of the knots
> points( women$height, women$weight )
> splineKnots( ispl )
 [1] 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>