util_singlediff_ts: Single Differencing to Make Time Series Stationary

View source: R/utils-singlediff-stationary.R

util_singlediff_tsR Documentation

Single Differencing to Make Time Series Stationary

Description

This function attempts to make a non-stationary time series stationary by applying single differencing. It iteratively increases the differencing order until stationarity is achieved.

Usage

util_singlediff_ts(.time_series)

Arguments

.time_series

A time series object to be made stationary.

Details

The function calculates the frequency of the input time series using the stats::frequency function. It then applies single differencing incrementally until the Augmented Dickey-Fuller test indicates stationarity (p-value < 0.05) or until the differencing order reaches the frequency of the data.

If single differencing successfully makes the time series stationary, it returns the stationary time series and related information as a list with the following elements:

  • stationary_ts: The stationary time series after differencing.

  • ndiffs: The order of differencing applied to make it stationary.

  • adf_stats: Augmented Dickey-Fuller test statistics on the stationary time series.

  • trans_type: Transformation type, which is "diff" in this case.

  • ret: TRUE to indicate a successful transformation.

If the data requires more single differencing than its frequency allows, it informs the user and returns a list with ret set to FALSE, indicating that double differencing may be needed.

Value

If the time series is already stationary or the single differencing is successful, it returns a list as described in the details section. If additional differencing is required, it informs the user and returns a list with ret set to FALSE.

Author(s)

Steven P. Sanderson II, MPH

See Also

Other Utility: auto_stationarize(), calibrate_and_plot(), internal_ts_backward_event_tbl(), internal_ts_both_event_tbl(), internal_ts_forward_event_tbl(), model_extraction_helper(), ts_get_date_columns(), ts_info_tbl(), ts_is_date_class(), ts_lag_correlation(), ts_model_auto_tune(), ts_model_compare(), ts_model_rank_tbl(), ts_model_spec_tune_template(), ts_qq_plot(), ts_scedacity_scatter_plot(), ts_to_tbl(), util_difflog_ts(), util_doublediff_ts(), util_doubledifflog_ts(), util_log_ts()

Examples

# Example 1: Using a time series dataset
util_singlediff_ts(AirPassengers)

# Example 2: Using a different time series dataset
util_singlediff_ts(BJsales)$ret


spsanderson/healthyR.ts documentation built on Jan. 19, 2024, 10:02 p.m.