Learn R Programming

psd (version 0.4-1)

splineGrad: Numerical derivatives of a series based on a weighted, smooth spline representation.

Description

splineGrad computes the numerical derivatives of a spline representation of the input series; differentiation of spline curves is numerically efficient.

With smoothing, the numerical instability for "noisy" data can be drastically reduced, since spline curves are inherently (at least) twice differentiable. See the Examples for an illustration of this.

Usage

splineGrad(dseq, dsig, plot.derivs = FALSE, ...)

## S3 method for class 'default': splineGrad(dseq, dsig, plot.derivs = FALSE, ...)

Arguments

dseq
numeric; a vector of positions for dsig.
dsig
numeric; a vector of values (which will have a spline fit to them).
plot.derivs
logical; should the derivatives be plotted?
...
additional arguments passed to smooth.spline.

Value

  • A matrix with columns representing $x, f(x), f'(x), f''(x)$.

See Also

smooth.spline

Examples

Run this code
#RDEX#\dontrun{
require(psd)
##
## Spline gradient
##
set.seed(1234)
x <- seq(0,5*pi,by=pi/64)
y <- cos(x) #**2
splineGrad(x, y, TRUE)
y <- y + rnorm(length(y), sd=.1)
# unfortunately, the presence of
# noise will affect numerical derivatives
splineGrad(x, y, TRUE)
# so change the smoothing used in smooth.spline
splineGrad(x, y, TRUE, spar=0.2)
splineGrad(x, y, TRUE, spar=0.6)
splineGrad(x, y, TRUE, spar=1.0)
##
#RDEX#}

Run the code above in your browser using DataLab