| caps | R Documentation |
Applies a smoothing spline to y with rigidity determined
by two parameters: frequency response f at a wavelength
of nyrs years.
caps(y, nyrs = 32, f = 0.5)
y |
a |
nyrs |
a number greater than zero, affecting the rigidity of the spline. If |
f |
a number between 0 and 1 giving the frequency response at a wavelength of |
This applies the classic smoothing spline from Cook and Peters (1981). The rigidity of the spline has a frequency response of 50% at a wavelength of nyrs. The references, of course, have more information.
This function was introduced to dplR in version 1.7.3 and replaces the now defunct ffcsaps. Where ffcsaps was written entirely in R, caps is a wrapper for a Fortran subroutine from Ed Cook's ARSTAN program that is hundreds of times faster.
The default value of nyrs was changed to 32 from 2/3 length of y in version 1.7.8 based on a suggestion from Klesse (2021).
Note: nyrs is passed to the Fortran subroutine as an
integer, so a fractional nyrs is truncated. This matters
when nyrs is given as a proportion of series length, which
is rarely a whole number. The effect on the fitted curve is small but not
zero; see the “Mathematical Details” vignette for a worked
comparison.
Note: caps stops if there are any NA values in y. A smoothing spline through a series with missing values is not defined, and the caller has to decide what to do about the gap rather than have one chosen silently. Before version 1.8.0 such a call returned a vector of NA, which looked like an answer and was not. See examples, and fill.internal.NA.
A filtered vector.
The mathematical relationship between nyrs,
f and the spline's smoothing parameter, together with an
empirical check of the frequency response and a demonstration that
caps reproduces the deprecated ffcsaps, is
given in the vignette: vignette("math-dplR", package = "dplR").
Fortran code provided by Ed Cook and adapted for dplR by Andy Bunn.
Cook, E. R. and Kairiukstis, L. A., editors (1990) Methods of Dendrochronology: Applications in the Environmental Sciences. Springer. ISBN-13: 978-0-7923-0586-6.
Cook, E. R. and Peters, K. (1981) The Smoothing Spline: A New Approach to Standardizing Forest Interior Tree-Ring Width Series for Dendroclimatic Studies. Tree-Ring Bulletin, 41, 45-53.
Klesse, S. (2021) Critical Note on the Application of the "Two-Third"" Spline. Dendrochronologia Volume 65: 125786
ads
library(graphics)
library(utils)
## Use first series from the Mesa Verde data set
data(co021)
series <- co021[, 1]
series <- series[!is.na(series)]
plot(series, type = "l", ylab = "Ring Width (mm)", col = "grey")
lines(caps(series, nyrs = 10), col = "red", lwd = 2)
lines(caps(series, nyrs = 100), col = "green", lwd = 2)
# The default, a 32-year spline since version 1.7.8
lines(caps(series), col = "blue", lwd = 2)
legend("topright",
c("Series", "nyrs=10", "nyrs=100", "Default nyrs (32)"),
fill=c("grey", "red", "green", "blue"))
## caps() needs a series with no missing values. Note that the example
## above drops the NA padding before fitting. A gap inside the measured
## span has to be dealt with deliberately: drop the series, or close the
## gap with fill.internal.NA().
y <- c(NA, NA, rnorm(100))
try(caps(y))
## fit over the measured values instead
head(caps(y[!is.na(y)]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.