A pure R implementation of CAMPLET, a transparent, adaptive seasonal adjustment method that corrects for seasonality and outliers via arithmetic-progression updates, without model identification or optimisation, and without revising earlier adjusted values when new observations arrive. The method is described in Abeln & Jacobs (2023), Seasonal Adjustment Without Revisions.
Ported from the original VBA macro
(D200603-CampletExcel-v4.2, basCBFherzien.bas)
and validated against its own output (see
tests/testthat/test-camplet.R). A Java port for JDemetra+
v3 lives at jdplus-camplet;
this package has no dependency on it or on Java.
install.packages("camplet")
# development version
# install.packages("remotes")
remotes::install_git("https://gitrepo.service.rug.nl/team-data-science/camplet-r.git")library(camplet)
res <- camplet(AirPassengers)
res$accuracy
head(as.data.frame(res))camplet() is univariate: one series in, one result out.
To adjust many series, loop over them yourself
(e.g. lapply()/purrr::map() over a list of
series, or dplyr::group_by() |> group_modify() on a long
data frame) - the same way you would with seasonal::seas()
or stats::stl().
The returned object’s $data has
raw/sa/seasonal columns;
$diagnostics (or
as.data.frame(res, diagnostics = TRUE), the default) adds
the per-period adaptive-parameter trace that the original VBA tool wrote
to its “Adj_” worksheets (ca, mu,
pa, le, ti, expo_e,
abs_pct_e, years, weight,
growth).
CAMPLET reads observations by position: the k-th value is taken to be
the period after the (k-1)-th. A skipped period therefore shifts every
later observation into the wrong season while still producing
plausible-looking output. To catch this, camplet():
x contains NA,
NaN or Inf (fill or trim the gaps first);dates has duplicated,
out-of-order or irregularly spaced timestamps, e.g. a missing
month;periodicity
contradicts monthly or quarterly data,
e.g. camplet(AirPassengers, periodicity = 4).A plain numeric vector without dates can’t be checked,
so making sure it has no gaps is up to you. See ?camplet,
section “Input checks”.