Var model
polars_ts.var_model
Vector Autoregression (VAR) for multivariate time series. Closes #50.
VARResult
dataclass
Fitted VAR model.
var_fit(df, target_cols, p=1, time_col='ds')
Fit a VAR(p) model via OLS.
Parameters
df Input DataFrame with all target columns and a time column. Should represent a single multivariate series (no id_col grouping). target_cols List of column names to model jointly. p Number of lags. time_col Column with timestamps for ordering.
Returns
VARResult Fitted model containing coefficient matrix and residuals.
var_forecast(model, horizon, time_col='ds')
Produce multi-step VAR forecasts.
Parameters
model
A fitted :class:VARResult.
horizon
Number of steps to forecast.
time_col
Column name for the step index in the output.
Returns
pl.DataFrame
DataFrame with columns [time_col, target_col_1, ..., target_col_k]
where each target column contains the "y_hat" forecast.
granger_causality(df, cause_col, effect_col, max_lag=5, time_col='ds')
Test whether cause_col Granger-causes effect_col.
Uses an F-test comparing a restricted model (effect's own lags only) to an unrestricted model (effect's lags + cause's lags).
Parameters
df Input DataFrame. cause_col Potential causal variable. effect_col Variable to predict. max_lag Maximum lag to test. time_col Column with timestamps.
Returns
pl.DataFrame
DataFrame with columns ["lag", "f_stat", "p_value"].