ts_fil_spline: Smoothing Splines

View source: R/ts_fil_spline.R

ts_fil_splineR Documentation

Smoothing Splines

Description

Fit a cubic smoothing spline to a time series for smooth trend extraction with a tunable roughness penalty.

Usage

ts_fil_spline(spar = NULL)

Arguments

spar

Smoothing parameter. If NULL, it is selected automatically by generalized cross-validation.

Details

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.

Value

A ts_fil_spline object.

References

  • P. Craven and G. Wahba (1978). Smoothing noisy data with spline functions. Numerische Mathematik.

Examples

# 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)

tspredit documentation built on Sept. 9, 2026, 9:08 a.m.