library(pacman)
p_load(tidyverse, fpp3)Features
Time Series Features
Statistics computed on time series data are called time series features.
We will examine the time series data in the Tourism dateset.
data(tourism)
tourismtourism |> features(Trips, quantile)Note the list can be used for many statistics.
tourism |> features(Trips, list(mean = mean, median = median, sd = sd, min = min, max = max))Lets look at the first year of the data.
tourism |> filter(Quarter <= yearquarter("1998 Q4")) |>
features(Trips, quantile)ACF features
The correlations in time are all time series features.
tourism |> ACF()Response variable not specified, automatically selected `var = Trips`
tourism |> filter(Region == "Adelaide", State == "South Australia", Purpose == "Holiday") |>
ACF() Response variable not specified, automatically selected `var = Trips`
tourism |> filter(Region == "Adelaide", State == "South Australia", Purpose == "Holiday") |>
ACF() |>
autoplot()Response variable not specified, automatically selected `var = Trips`
tourism |> filter(Region == "Adelaide", State == "South Australia", Purpose == "Holiday") |>
autoplot() Plot variable not specified, automatically selected `.vars = Trips`
Compute most of the features.
tourism |>
features(Trips, feat_stl)tourism |> filter(Region == "Adelaide", State == "South Australia", Purpose == "Holiday") |>
features(Trips, feat_stl) Use the features to identify a time series
We can then use these features in plots to identify what type of series are heavily trended and what are most seasonal.
tourism |>
features(Trips, feat_stl) |>
ggplot(aes(x = trend_strength, y = seasonal_strength_year, col = Purpose)) +
geom_point() +
facet_wrap(vars(State))Find the year with the maximum seasonal strength.
tourism |>
features(Trips, feat_stl) |>
filter(seasonal_strength_year == max(seasonal_strength_year)) |>
left_join(tourism, by = c("State", "Region", "Purpose")) |>
ggplot(aes(x = Quarter, y = Trips)) +
geom_line() +
facet_grid(vars(State, Region, Purpose))Full feature set
tourism_features <- tourism |>
features(Trips, feature_set(pkgs = "feasts"))
tourism_featuresFor the homework we will look at the PBS data.
PBS |> features(Cost, list(mean = mean, sd = sd))