Skip to main content

SpecificationTests

Struct SpecificationTests 

Source
pub struct SpecificationTests;
Expand description

Specification tests for regression models

Implementations§

Source§

impl SpecificationTests

Source

pub fn white_test( residuals: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, x: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ) -> Result<(f64, f64, usize), String>

White’s Test for Heteroskedasticity

Tests H₀: Homoskedasticity (constant variance) vs H₁: Heteroskedasticity

§Arguments
  • residuals - Residuals from OLS regression
  • x - Design matrix (n × k)
§Returns

Tuple of (LM_statistic, p_value, degrees_of_freedom)

§Interpretation
  • If p < 0.05: Reject H₀, heteroskedasticity is present (use robust SE)
  • If p > 0.05: Fail to reject H₀, homoskedasticity is plausible
use greeners_diagnostics::specification_tests::SpecificationTests;
use ndarray::{Array1, Array2};

// ... the rest of your original example here ...
let (lm_stat, p_value, df) = SpecificationTests::white_test(&residuals, &x)?;
Source

pub fn reset_test( y: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, x: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, fitted_values: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, power: usize, ) -> Result<(f64, f64, usize, usize), String>

Ramsey RESET Test for Functional Form Misspecification

Tests H₀: Model is correctly specified vs H₁: Functional form misspecification

§Arguments
  • y - Dependent variable
  • x - Design matrix (n × k)
  • fitted_values - Fitted values from original regression
  • power - Maximum power of fitted values to include (typically 2, 3, or 4)
§Returns

Tuple of (F_statistic, p_value, df_num, df_denom)

§Interpretation
  • If p < 0.05: Reject H₀, functional form misspecification detected
  • If p > 0.05: Fail to reject H₀, functional form appears adequate
use greeners_diagnostics::specification_tests::SpecificationTests;
use ndarray::{Array1, Array2};

let (f_stat, p_value, _, _) = SpecificationTests::reset_test(&y, &x, &fitted, 2)?;
Source

pub fn breusch_godfrey_test( residuals: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, x: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, lags: usize, ) -> Result<(f64, f64, usize), String>

Breusch-Godfrey Test for Autocorrelation

Tests H₀: No autocorrelation up to lag p vs H₁: Autocorrelation present

§Arguments
  • residuals - Residuals from OLS regression
  • x - Design matrix (n × k)
  • lags - Number of lags to test (typically 1 for AR(1))
§Returns

Tuple of (LM_statistic, p_value, degrees_of_freedom)

§Interpretation
  • If p < 0.05: Reject H₀, autocorrelation detected
  • If p > 0.05: Fail to reject H₀, no evidence of autocorrelation
§Examples
use greeners_diagnostics::specification_tests::SpecificationTests;
use ndarray::{Array1, Array2};

// The visible example starts here:
let (lm_stat, p_value, df) = SpecificationTests::breusch_godfrey_test(&residuals, &x, 1)?;
Source

pub fn goldfeld_quandt_test( residuals: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 1]>>, split_fraction: f64, ) -> Result<(f64, f64, usize, usize), String>

Goldfeld-Quandt Test for Heteroskedasticity

Tests H₀: Homoskedasticity vs H₁: Variance increases with ordering variable

§Arguments
  • residuals - Residuals from OLS regression (should be ordered by suspected variable)
  • split_fraction - Fraction of middle observations to drop (typically 0.2 to 0.33)
§Returns

Tuple of (F_statistic, p_value, df1, df2)

§Interpretation
  • If p < 0.05: Reject H₀, heteroskedasticity detected
  • If p > 0.05: Fail to reject H₀, homoskedasticity plausible
Source

pub fn print_test_result( test_name: &str, statistic: f64, p_value: f64, null_hypothesis: &str, alternative_hypothesis: &str, )

Pretty print specification test results

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SendAlias for T

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> SyncAlias for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V