pub struct VarModel { /* private fields */ }Expand description
After fitting, the model verifies that the VAR companion matrix has
a spectral radius below stability_threshold
(default: 1.05). Models exceeding this are rejected as unstable.
The QR-based eigenvalue computation correctly captures complex
conjugate eigenvalue pairs (oscillatory dynamics) that power iteration
would miss.
Callers can override the threshold via
new_with_stability_threshold().
Implementations§
Source§impl VarModel
impl VarModel
Sourcepub fn new(lag_order: Option<usize>) -> Self
pub fn new(lag_order: Option<usize>) -> Self
Creates a VAR model with the given lag order (default: 1).
Sourcepub fn new_with_stability_threshold(
lag_order: Option<usize>,
stability_threshold: Option<f64>,
) -> Self
pub fn new_with_stability_threshold( lag_order: Option<usize>, stability_threshold: Option<f64>, ) -> Self
Creates a VAR model with a custom stability threshold.
The stability_threshold controls the maximum allowed spectral
radius of the VAR companion matrix (default: 1.05). Set to a
value > 1.0 to tolerate near-unit-root processes, or closer to
1.0 for stricter stability enforcement.
Source§impl VarModel
impl VarModel
Sourcepub fn granger_causality(
&self,
ctx: &MultiSeriesContext,
) -> Result<Vec<GrangerCausalityResult>, MultivariateError>
pub fn granger_causality( &self, ctx: &MultiSeriesContext, ) -> Result<Vec<GrangerCausalityResult>, MultivariateError>
Perform pairwise Granger causality tests for all series pairs.
For each pair (cause → effect), fits an unrestricted VAR equation (with all series’ lags) and a restricted equation (excluding the cause’s lags), then compares RSS via an F-test.
Requires the model to be fitted first via fit().
§F-test
$$F = \frac{(RSS_r - RSS_u) / p}{RSS_u / (T - k_{full})}$$
where $p$ = lag order (number of excluded regressors), $T$ = number of usable observations, and $k_{full}$ = number of regressors in the unrestricted equation (1 + p × k).
Sourcepub fn granger_causality_robust(
&self,
ctx: &MultiSeriesContext,
) -> Result<Vec<GrangerCausalityResult>, MultivariateError>
pub fn granger_causality_robust( &self, ctx: &MultiSeriesContext, ) -> Result<Vec<GrangerCausalityResult>, MultivariateError>
HC3-robust pairwise Granger causality tests.
Same hypothesis as granger_causality but uses the HC3
(MacKinnon & White 1985) covariance estimator, which is valid
under arbitrary conditional heteroscedasticity.
For each pair (cause → effect) the unrestricted OLS equation is fitted, residuals are obtained, and a Wald test with HC3 sandwich covariance is computed:
$$W = (R\hat\beta)^\top (R,\hat V_{HC3},R^\top)^{-1}(R\hat\beta)$$
where $R$ selects the $p$ coefficients of the candidate cause. $F = W / p$ is compared against $F(p, T - kp - 1)$.
Trait Implementations§
Source§impl MultivariateForecastModel for VarModel
impl MultivariateForecastModel for VarModel
Source§fn fit(
&mut self,
ctx: &MultiSeriesContext,
target_idx: usize,
) -> Result<(), MultivariateError>
fn fit( &mut self, ctx: &MultiSeriesContext, target_idx: usize, ) -> Result<(), MultivariateError>
Source§fn predict(
&self,
horizon: usize,
) -> Result<MultivariateForecastResult, MultivariateError>
fn predict( &self, horizon: usize, ) -> Result<MultivariateForecastResult, MultivariateError>
horizon steps ahead.Source§fn supports_online_learning(&self) -> bool
fn supports_online_learning(&self) -> bool
Auto Trait Implementations§
impl Freeze for VarModel
impl RefUnwindSafe for VarModel
impl Send for VarModel
impl Sync for VarModel
impl Unpin for VarModel
impl UnsafeUnpin for VarModel
impl UnwindSafe for VarModel
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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