View source: R/ts_fil_spline.R
| ts_fil_spline | R Documentation |
Fit a cubic smoothing spline to a time series for smooth trend extraction with a tunable roughness penalty.
ts_fil_spline(spar = NULL)
spar |
Smoothing parameter. If |
The spline is fitted against the time index 1:length(data) rather
than against the observed values themselves. This preserves the chronological
order of the series while smoothing the observed values along that time axis.
A ts_fil_spline object.
P. Craven and G. Wahba (1978). Smoothing noisy data with spline functions. Numerische Mathematik.
# Smoothing splines with adjustable roughness penalty
# Load package and example data
library(daltoolbox)
library(tspredit)
data(tsd)
tsd$y[9] <- 2 * tsd$y[9] # inject an outlier
# Fit spline smoother and transform
filter <- ts_fil_spline(spar = 0.5)
filter <- daltoolbox::fit(filter, tsd$y)
y <- transform(filter, tsd$y)
# Compare original vs smoothed series
plot_ts_pred(y = tsd$y, yadj = y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.