Function dickeyfuller_test

Source
pub fn dickeyfuller_test<F: Float + Scalar + RealField>(
    series: &DVector<F>,
    regression: Regression,
) -> Result<Report<F>, Error>
Expand description

Dickey-Fuller test Returns the t-statistic of the Dickey-Fuller test and the size of the sample.

The null hypothesis is that the series is non-stationary.

§Details

Critical values for can obtained from unit_root::prelude::distrib::dickeyfuller::get_critical_value.

  • If $t_{stat} < \mathrm{t_{\mathrm{crit}}(\alpha)}$ then reject $H_0$ at $alpha$ significance level - and thus conclude that the series is stationary.
  • If $t_{stat} > \mathrm{t_{\mathrm{crit}}(\alpha)}$ then fail to reject $H_0$ at $alpha$ significance level - and thus conclude we cannot reject the hypothesis that the series is not stationary.

§Examples:

use unit_root::prelude::distrib::{AlphaLevel, Regression};
use unit_root::prelude::nalgebra::DVector;
use unit_root::prelude::*;

let y = DVector::from_row_slice(&[
    -0.89642362,
    0.3222552,
    -1.96581989,
    -1.10012936,
    -1.3682928,
    1.17239875,
    2.19561259,
    2.54295031,
    2.05530587,
    1.13212955,
    -0.42968979,
]);

let regression = Regression::Constant;

let report = tools::dickeyfuller_test(&y, regression).unwrap();

let critical_value =
    distrib::dickeyfuller::get_critical_value(regression, report.size, AlphaLevel::OnePercent)
        .unwrap();
assert_eq!(report.size, 10);

let t_stat = report.test_statistic;
println!("t-statistic: {}", t_stat);
assert!((t_stat - -1.472691f64).abs() < 1e-6);
assert!(t_stat > critical_value);