Use a unit root function to determine the minimum number of differences necessary to obtain a stationary time series.
unitroot_ndiffs( x, alpha = 0.05, unitroot_fn = ~unitroot_kpss(.)["kpss_pvalue"], differences = 0:2, ... ) unitroot_nsdiffs( x, alpha = 0.05, unitroot_fn = ~feat_stl(., .period)[2] < 0.64, differences = 0:2, .period = 1, ... )
x | A vector to be tested for the unit root. |
---|---|
alpha | The level of the test. |
unitroot_fn | A function (or lambda) that provides a p-value for a unit root test. |
differences | The possible differences to consider. |
... | Additional arguments passed to the |
.period | The period of the seasonality. |
A numeric corresponding to the minimum required differences for stationarity.
Note that the default 'unit root function' for unitroot_nsdiffs()
is based
on the seasonal strength of an STL decomposition. This is not a test for the
presence of a seasonal unit root, but generally works reasonably well in
identifying the presence of seasonality and the need for a seasonal
difference.