Skip to main content

adf_test

Function adf_test 

Source
pub fn adf_test(
    data: &[f64],
    model: AdfModel,
    max_lags: Option<usize>,
) -> Option<AdfResult>
Expand description

Augmented Dickey-Fuller (ADF) unit root test for stationarity.

Tests H₀: unit root (non-stationary) vs H₁: stationary.

§Algorithm

  1. Constructs Δyₜ = α + γyₜ₋₁ + Σδᵢ·Δyₜ₋ᵢ + εₜ
  2. Estimates via OLS
  3. Tests t-ratio for γ against Dickey-Fuller critical values

When max_lags is None, lag length is selected by AIC (Schwert rule for maximum). When Some(p), exactly p lags are used.

Reference: Dickey & Fuller (1979), “Distribution of the Estimators for Autoregressive Time Series with a Unit Root”

§Returns

None if fewer than 10 data points, non-finite values, or OLS fails.

§Examples

use u_analytics::testing::{adf_test, AdfModel};

// Stationary series: strong mean-reversion
let mut data = vec![0.0_f64; 40];
for i in 1..40 {
    data[i] = 0.3 * data[i - 1] + [0.5, -0.8, 0.3, -0.6, 0.9,
        -0.4, 0.7, -0.2, 0.1, -0.5][i % 10];
}
let r = adf_test(&data, AdfModel::Constant, None).unwrap();
assert!(r.statistic.is_finite());
assert_eq!(r.critical_values.len(), 3);