Code
library(feasts)
library(tsibble)
library(dplyr)
tourism |>
features(Trips, feature_set(pkgs = "feasts"))feasts R PackageA reference guide to feature-extraction functions for tidy time series
Prepared with Claude
28 September 2026
feasts (Feature Extraction And Statistics for Time Series) is part of the tidyverts ecosystem and works with tsibble objects. Its feature functions condense a time series into a small number of interpretable numbers describing things like trend strength, seasonality, autocorrelation structure, and irregularity. These are typically applied with fabletools::features():
feature_set(pkgs = "feasts") collects every registered feature function in the package, but each one can also be called individually, as shown throughout this report.
The functions fall into a few natural groups:
feat_stl()Decomposes the series into trend T_t, seasonal S_t, and remainder R_t using STL, then computes a set of descriptive statistics from those components. The main quantities are:
| Feature | Definition | Interpretation |
|---|---|---|
trend_strength |
\max\left(0,\ 1 - \dfrac{\mathrm{Var}(R_t)}{\mathrm{Var}(T_t + R_t)}\right) | Close to 1 → strong, dominant trend |
seasonal_strength |
\max\left(0,\ 1 - \dfrac{\mathrm{Var}(R_t)}{\mathrm{Var}(S_t + R_t)}\right) | Close to 1 → strong, dominant seasonality |
seasonal_peak |
Season (e.g. month/quarter) of the maximum of the seasonal component | Timing of the seasonal high point |
seasonal_trough |
Season of the minimum of the seasonal component | Timing of the seasonal low point |
spikiness |
Variance of the leave-one-out variances of R_t | Large value → remainder dominated by a few big spikes |
linearity |
Coefficient on a linear term from an orthogonal-polynomial regression fit to the trend | Positive → strongly increasing/decreasing trend |
curvature |
Coefficient on a quadratic term from the same regression | Large magnitude → trend bends noticeably |
stl_e_acf1 |
First-lag autocorrelation of the remainder | High value → remainder is not white noise |
stl_e_acf10 |
Sum of squares of the first 10 remainder autocorrelations | High value → substantial leftover structure in the remainder |
Spikiness in detail. For remainder series e_t of length n with sample variance \mathrm{Var}(e), the leave-one-out variance for observation i is computed without refitting:
d_i = (e_i - \bar e)^2, \qquad \mathrm{varloo}_i = \frac{\mathrm{Var}(e)(n-1) - d_i}{n-2}
Spikiness is then \mathrm{Var}(\mathrm{varloo}_1, \dots, \mathrm{varloo}_n). If no single point dominates the remainder, all leave-one-out variances are similar and spikiness is near zero; a few extreme spikes make the leave-one-out variances disperse widely, inflating this feature.
These aren’t features themselves but produce the decompositions the features above rely on, or provide alternative decompositions:
STL() — the model-fitting interface to stats::stl(), allowing multiple seasonal periods and Box–Cox transformation (via fabletools::model()).classical_decomposition() — additive/multiplicative decomposition by moving averages (Y_t = T_t + S_t + e_t or Y_t = T_t S_t e_t).X_13ARIMA_SEATS() — wraps the U.S. Census Bureau’s X-13ARIMA-SEATS program (SEATS or X-11 methods) for seasonal adjustment.generate.stl_decomposition() — block-bootstraps new series from a fitted STL decomposition’s residuals.feat_acf()Returns 6 (or 7, if seasonal) values built from the autocorrelation function of the original series, its first difference, and its second difference:
.period > 1), the autocorrelation at the first seasonal lag is also includedHigh sums of squared autocorrelations indicate a series with strong short-term dependence; comparing the values across the original/differenced/twice-differenced versions helps identify how much differencing is needed to reach approximate white noise.
feat_pacf()The partial-autocorrelation analogue of feat_acf(): the sum of squares of the first 5 partial autocorrelations for the original, once-differenced, and twice-differenced series, plus the seasonal partial autocorrelation for seasonal data.
ACF(), PACF(), CCF()Not single-number features but tidy computations of the (partial) autocorrelation or cross-correlation function, returned as a tbl_cf object that can be plotted with autoplot(). Useful for visual inspection alongside the numeric ACF/PACF-based features above.
feat_spectral()Computes the spectral entropy of the series — the Shannon entropy of its (AR-estimated, Burg-method) normalized spectral density f_x(\lambda):
H_s(x_t) = -\int_{-\pi}^{\pi} f_x(\lambda) \log f_x(\lambda) \, d\lambda, \qquad \int_{-\pi}^{\pi} f_x(\lambda)\, d\lambda = 1
Values close to 0 indicate a series that is easy to forecast (its spectral power is concentrated, e.g. a strong single frequency or trend); values closer to 1 indicate a series closer to white noise, where power is spread evenly across frequencies.
coef_hurst()Estimates the Hurst coefficient, reflecting the degree of long-range dependence / fractional differencing in the series. Values above 0.5 suggest persistent, trending behaviour; values below 0.5 suggest anti-persistent, mean-reverting behaviour.
feat_intermittent()Designed for intermittent-demand series (many zeros interspersed with non-zero values):
| Feature | Meaning |
|---|---|
zero_run_mean |
Average interval length between non-zero observations |
nonzero_squared_cv |
Squared coefficient of variation of the non-zero observations |
zero_start_prop |
Proportion of the series that starts with zeros |
zero_end_prop |
Proportion of the series that ends with zeros |
longest_flat_spot()Splits the range of the series into 10 equal-width bins and returns the longest run of consecutive observations sitting in the same bin — a proxy for periods where the series barely changes.
n_crossing_points()Counts how many times the series crosses its own median. Frequent crossings suggest choppier, more mean-reverting behaviour; few crossings suggest sustained runs above or below the median.
var_tiled_mean() and var_tiled_var()Both split the series into non-overlapping (“tiled”) windows and summarise each window with its mean or its variance:
shift_level_max(), shift_var_max(), shift_kl_max()Slide a window across the series and compare consecutive windows, returning both the size of the largest change and the time index at which it occurs:
shift_level_max — largest shift in the mean between adjacent windows (level/step changes)shift_var_max — largest shift in the variance between adjacent windows (volatility changes)shift_kl_max — largest shift in Kullback–Leibler divergence between adjacent windows (distributional changes more general than mean/variance alone)These wrap classical hypothesis tests so their statistics and p-values can be used as machine-learning-style features.
unitroot_kpss — KPSS test statistic; large values point to non-stationarity (rejects the null of stationarity)unitroot_pp — Phillips–Perron test statistic for a unit rootunitroot_ndiffs — minimum number of ordinary differences needed for stationarity, based on repeatedly applying a unit-root test (KPSS by default)unitroot_nsdiffs — minimum number of seasonal differences needed, based by default on whether STL seasonal strength exceeds 0.64Test the null hypothesis that the series (often a residual series) is independently distributed, i.e. shows no autocorrelation up to the specified lag. Both return a statistic and a p-value; Ljung–Box is the small-sample-corrected version of Box–Pierce.
Computes Engle’s ARCH LM statistic — the R^2 from an autoregression of the squared series — as a measure of autoregressive conditional heteroscedasticity (volatility clustering).
cointegration_johansen — Johansen procedure (trace/eigenvalue statistics) for testing cointegration among multiple series, via urca::ca.jo()cointegration_phillips_ouliaris — Phillips–Ouliaris residual-based cointegration test statistic and approximate p-value, via urca::ca.po()Not a descriptive feature but a transformation-parameter selector: chooses the Box–Cox \lambda that minimises the coefficient of variation across subseries of the data (Guerrero’s method).
A typical workflow computes the full built-in feature set, then explores it — e.g. with PCA — to find unusual or clustered series:
Individual functions can also be combined manually for a custom, lighter-weight feature set:
feasts package documentation — https://feasts.tidyverts.org/