statspai.timeseries¶
timeseries ¶
Time series methods for causal inference contexts.
Provides VAR (vector autoregression), structural break tests, Granger causality, and cointegration analysis.
VARResult ¶
StructuralBreakResult ¶
Results from structural break tests.
CointegrationResult ¶
Results from cointegration test.
ARIMAResult
dataclass
¶
conf_int ¶
Confidence intervals for each parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
|
0.05
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Indexed by parameter name with |
granger_causality ¶
granger_causality(var_result: VARResult = None, data: DataFrame = None, caused: str = None, causing: str = None, lags: int = None) -> Dict[str, Any]
Granger causality test.
Tests whether causing variable Granger-causes caused variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var_result
|
VARResult
|
Pre-estimated VAR model. |
None
|
data
|
DataFrame
|
Data (if var_result not provided). |
None
|
caused
|
str
|
Variable being tested for causation. |
None
|
causing
|
str
|
Variable hypothesized to cause. |
None
|
lags
|
int
|
Number of lags (if fitting new VAR). |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Keys: 'F_stat', 'p_value', 'df1', 'df2', 'caused', 'causing'. |
irf ¶
irf(var_result: VARResult, periods: int = 20, impulse: str = None, response: str = None, orthogonal: bool = True) -> Dict[str, Any]
Compute impulse response functions from VAR.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
var_result
|
VARResult
|
Estimated VAR model. |
required |
periods
|
int
|
Number of periods for IRF. |
20
|
impulse
|
str
|
Impulse variable (if None, all). |
None
|
response
|
str
|
Response variable (if None, all). |
None
|
orthogonal
|
bool
|
Orthogonalized (Cholesky) IRF. |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
Keys: 'irf' (dict of arrays), 'periods'. |
cusum_test ¶
CUSUM test for parameter stability.
Tests H0: parameters are stable vs H1: parameter shift.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
|
required |
y
|
str
|
Dependent variable. |
required |
x
|
list of str
|
Regressors. |
None
|
alpha
|
float
|
|
0.05
|
Returns:
| Type | Description |
|---|---|
dict
|
Keys: 'cusum', 'critical_value', 'reject', 'n_obs'. |
engle_granger ¶
engle_granger(data: DataFrame, variables: List[str] = None, lags: int = None, trend: str = 'c', alpha: float = 0.05) -> CointegrationResult
Engle-Granger (1987) two-step cointegration test.
Step 1: OLS regression of y on x Step 2: ADF test on residuals
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
|
required |
variables
|
list of str
|
Variables to test (first is dependent). |
None
|
lags
|
int
|
Lags for ADF test. If None, uses AIC selection. |
None
|
trend
|
str
|
|
'c'
|
alpha
|
float
|
|
0.05
|
Returns:
| Type | Description |
|---|---|
CointegrationResult
|
|
johansen ¶
johansen(data: DataFrame, variables: List[str] = None, lags: int = 1, trend: str = 'c', test: str = 'trace', alpha: float = 0.05) -> CointegrationResult
Johansen (1991) cointegration test.
Tests for the cointegration rank using the trace or maximum eigenvalue test statistic.
Equivalent to Stata's vecrank and R's ca.jo().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
|
required |
variables
|
list of str
|
Variables to test. |
None
|
lags
|
int
|
Number of lags in the VECM. |
1
|
trend
|
str
|
'n' (none), 'c' (constant), 'ct' (constant + trend). |
'c'
|
test
|
str
|
'trace' or 'maxeig' (maximum eigenvalue). |
'trace'
|
alpha
|
float
|
|
0.05
|
Returns:
| Type | Description |
|---|---|
CointegrationResult
|
|
Examples: