Learn R Programming

psd (version 1.0-0)

splineGrad: Numerical derivatives of a series based on its smooth-spline representation

Description

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

Usage

splineGrad(dseq, dsig, ...)

## 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).
...
additional arguments passed to smooth.spline
plot.derivs
logical; should the derivatives be plotted?

Value

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

Details

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

See Also

smooth.spline, constrain_tapers

Examples

Run this code
#REX
library(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)
###REX

Run the code above in your browser using DataLab