VAR-向量自回归(VAR)
向量自回归模型(Vector Autoregression, VAR)是一类用于刻画多变量时间序列动态联动关系的经典模型。与单方程模型不同,VAR 将每个内生变量都视为系统的一部分,并允许其同时受到自身滞后项与其他变量滞后项的共同影响,因此在宏观经济、金融风险、产业联动与政策评…
60-VAR-向量自回归(VAR)
1. 方法概述
向量自回归模型(Vector Autoregression, VAR)是一类用于刻画多变量时间序列动态联动关系的经典模型。与单方程模型不同,VAR 将每个内生变量都视为系统的一部分,并允许其同时受到自身滞后项与其他变量滞后项的共同影响,因此在宏观经济、金融风险、产业联动与政策评估等场景中具有较强适用性。
设系统包含 \(k\) 个内生变量,样本期为 \(t=1,2,\ldots,T\),记
$$ \mathbf{y}_t=(y_{1t},y_{2t},\ldots,y_{kt})^\top \tag{1} $$
则 \(\mathbf{y}_t\in\mathbb{R}^k\) 表示第 \(t\) 期的多变量观测向量。
2. VAR 模型设定
本文档对应程序支持 VAR\((p)\) 模型,并可选确定性项(无截距、截距、线性趋势、二次趋势)。模型一般形式为
$$ \mathbf{y}_t=\mathbf{d}_t+\mathbf{A}_1\mathbf{y}_{t-1}+\mathbf{A}_2\mathbf{y}_{t-2}+\cdots+\mathbf{A}_p\mathbf{y}_{t-p}+\mathbf{u}_t \tag{2} $$
其中 \(\mathbf{A}_i\in\mathbb{R}^{k\times k}\) 为第 \(i\) 阶滞后系数矩阵,\(\mathbf{u}_t\) 为扰动项,满足
$$ \mathbb{E}(\mathbf{u}_t)=\mathbf{0},\qquad \mathbb{E}(\mathbf{u}_t\mathbf{u}_t^\top)=\boldsymbol{\Sigma}_u. \tag{3} $$
程序中的确定性项 \(\mathbf{d}_t\) 与 trend 选项对应:
$$ \mathbf{d}_t= \begin{cases} \mathbf{0}, & \text{trend}=n\\ \mathbf{c}, & \text{trend}=c\\ \mathbf{c}+\mathbf{g}t, & \text{trend}=ct\\ \mathbf{c}+\mathbf{g}t+\mathbf{h}t^2, & \text{trend}=ctt \end{cases} \tag{4} $$
3. 参数估计
在给定阶数 \(p\) 后,VAR 可写为多元线性回归矩阵形式:
$$ \mathbf{Y}=\mathbf{X}\mathbf{B}+\mathbf{E} \tag{5} $$
其中 \(\mathbf{Y}\) 为被解释变量块,\(\mathbf{X}\) 为由确定性项与各阶滞后变量构成的设计矩阵,\(\mathbf{B}\) 为待估参数矩阵。最小二乘估计为
$$ \hat{\mathbf{B}}=(\mathbf{X}^\top\mathbf{X})^{-1}\mathbf{X}^\top\mathbf{Y} \tag{6} $$
当 \(\mathbf{X}^\top\mathbf{X}\) 不可逆时,可采用广义逆形式。
残差协方差矩阵估计为
$$ \hat{\boldsymbol{\Sigma}}_u=\frac{\hat{\mathbf{E}}^\top\hat{\mathbf{E}}}{n-m} \tag{7} $$
其中 \(n\) 为有效样本数,\(m\) 为每个方程参数个数。
4. 滞后阶选择
程序支持在 \(1\sim p_{\max}\) 范围内按信息准则自动选阶,或手动指定 \(p\)。设 \(\ell=\log|\hat{\Sigma}_u|\),总参数量记为
$$ q=k(kp+d) \tag{8} $$
其中 \(d\) 为确定性项个数(n/c/ct/ctt 分别对应 \(0,1,2,3\))。
AIC、BIC、HQIC 与 FPE 分别为
$$ \mathrm{AIC}=\ell+\frac{2q}{n} \tag{9} $$
$$ \mathrm{BIC}=\ell+\frac{\ln n\,q}{n} \tag{10} $$
$$ \mathrm{HQIC}=\ell+\frac{2\ln(\ln n)\,q}{n} \tag{11} $$
$$ \mathrm{FPE}=|\hat{\Sigma}_u|\left(\frac{n+q}{n-q}\right)^k. \tag{12} $$
通常取准则值最小对应的滞后阶作为最优阶数。
5. 稳定性、平稳性与协整检验
5.1 稳定性条件
构造 VAR 的伴随矩阵 \(\mathbf{F}\),若其全部特征根满足
$$ |\lambda_i(\mathbf{F})|<1, \tag{13} $$
则系统满足稳定性条件。
5.2 ADF 平稳性检验
程序可对各变量(或差分后变量)输出 ADF 检验结果。ADF 的回归形式可写为
$$ \Delta y_t=\mu+\rho y_{t-1}+\sum_{i=1}^{s}\phi_i\Delta y_{t-i}+\varepsilon_t. \tag{14} $$
原假设通常为 \(\rho=0\)(存在单位根)。
5.3 Johansen 协整检验
在多变量水平序列场景下,可用 Johansen 跟踪统计量判定协整秩。跟踪统计量写为
$$ \mathrm{Trace}(r)=-T\sum_{i=r+1}^{k}\ln(1-\hat{\lambda}_i), \tag{15} $$
并与给定显著性水平的临界值比较。
6. 预测与区间估计
6.1 递推预测
给定估计系数后,\(h\) 步预测满足
$$ \hat{\mathbf{y}}_{T+h|T}=\hat{\mathbf{d}}_{T+h}+\sum_{i=1}^{p}\hat{\mathbf{A}}_i\hat{\mathbf{y}}_{T+h-i|T}. \tag{16} $$
6.2 预测误差协方差
设 MA 形式系数矩阵为 \(\{\boldsymbol{\Phi}_j\}\),则 \(h\) 步预测误差协方差可写为
$$ \boldsymbol{\Omega}_h=\sum_{j=0}^{h-1}\boldsymbol{\Phi}_j\hat{\Sigma}_u\boldsymbol{\Phi}_j^\top. \tag{17} $$
对第 \(i\) 个变量,\((1-\alpha)\) 置信区间为
$$ \hat{y}_{i,T+h|T}\pm z_{1-\alpha/2}\sqrt{(\Omega_h)_{ii}}. \tag{18} $$
6.3 差分序列的水平还原
若模型在一阶差分上估计(diff_order=1),水平预测可按累加恢复:
$$ \hat{y}_{T+h}=y_T+\sum_{j=1}^{h}\widehat{\Delta y}_{T+j}. \tag{19} $$
若在二阶差分上估计(diff_order=2),可先恢复一阶差分,再恢复水平序列。
7. 冲击响应与方差分解
7.1 正交化冲击响应函数(IRF)
设 \(\hat{\Sigma}_u=\mathbf{P}\mathbf{P}^\top\)(Cholesky 分解),则正交化冲击响应可表示为
$$ \boldsymbol{\Theta}_h=\boldsymbol{\Phi}_h\mathbf{P},\qquad h=0,1,\ldots,H. \tag{20} $$
其中 \((\Theta_h)_{ij}\) 表示第 \(j\) 个结构冲击在 \(h\) 期后对第 \(i\) 个变量的影响。
7.2 预测误差方差分解(FEVD)
第 \(i\) 个变量在期数 \(h\) 下由第 \(j\) 个冲击解释的方差占比可写为
$$ \mathrm{FEVD}_{ij}(h)= \frac{\sum_{s=0}^{h-1}(\Theta_s)_{ij}^2} {\sum_{m=1}^{k}\sum_{s=0}^{h-1}(\Theta_s)_{im}^2}. \tag{21} $$
8. 残差诊断检验
8.1 Ljung-Box 白噪声检验
$$ Q(m)=n(n+2)\sum_{k=1}^{m}\frac{\hat{\rho}_k^2}{n-k} \tag{22} $$
用于检验残差序列是否存在自相关。
8.2 Jarque-Bera 正态性检验
$$ \mathrm{JB}=\frac{n}{6}\left(S^2+\frac{(K-3)^2}{4}\right) \tag{23} $$
其中 \(S\) 为偏度,\(K\) 为峰度。
8.3 ARCH-LM 异方差检验
以残差平方为被解释变量进行辅助回归,统计量可写为
$$ \mathrm{LM}=nR^2 \tag{24} $$
用于检验条件异方差效应。
9. 符号说明
| 符号 | 含义 |
|---|---|
| \(k\) | 内生变量个数 |
| \(p\) | VAR 滞后阶 |
| \(T\) | 原始样本期数 |
| \(n\) | 有效估计样本数 |
| \(\mathbf{A}_i\) | 第 \(i\) 阶滞后系数矩阵 |
| \(\mathbf{u}_t\) | 扰动向量 |
| \(\Sigma_u\) | 扰动协方差矩阵 |
| \(\Phi_h\) | MA 形式冲击传递矩阵 |
| \(\Theta_h\) | 正交化冲击响应矩阵 |
| \(\alpha\) | 预测区间显著性水平 |
10. 与代码实现的对应关系
程序会在 results/VAR分析结果_时间戳/ 目录下输出 xlsx + png + 复现脚本。其中 Excel 各 sheet 的含义如下:
RawData_Preview:原始数据预览,用于说明输入样本结构。Data_Selected:参与建模的数据(含差分处理后预览)。LagOrder:各候选滞后阶的信息准则结果(式(9)–式(12))。Parameters:各方程参数估计与显著性统计量(式(6)–式(7))。Residuals:残差序列。Diag_LjungBox:白噪声检验结果(式(22))。Diag_JB:正态性检验结果(式(23))。Diag_ARCHLM:ARCH-LM 检验结果(式(24))。Forecast:差分尺度或当前建模尺度下的预测值与区间(式(16)–式(18))。Forecast_Level:当diff_order>0时给出还原到水平序列的预测结果;diff_order=0时该表可能为空。IRF:冲击响应长表数据(式(20))。FEVD:方差分解长表数据(式(21))。Stability:伴随矩阵特征根与是否位于单位圆内(式(13))。Stationarity:ADF 平稳性检验结果(式(14))。Cointegration:Johansen 协整检验结果(式(15))。Run_Parameters:本次运行参数记录。Charts_Index:图表文件名索引,便于论文插图管理。
10.1 程序实际生成的图表
chart_series:多变量历史序列图;chart_forecast:预测图;chart_forecast_level:水平序列还原预测图(差分建模时);chart_irf:IRF 矩阵图;chart_fevd:FEVD 堆叠图;chart_stability:稳定性根图。
10.2 程序实现中应写明的点
- 程序支持在差分域建模,并可额外输出
Forecast_Level; LagOrder、Stationarity、Cointegration已分别落表,适合方法章节逐项引用;- IRF 和 FEVD 使用程序内部正交化结果,不宜在论文里写成“任意顺序无影响”;
Charts_Index与Run_Parameters有助于附录复现与插图管理。
11. 图表含义与论文插图建议
程序默认导出以下图表(文件名带时间戳):
chart_series:多变量历史序列图,用于展示各变量时序特征。chart_forecast:历史尾段与未来预测对比图(含区间)。chart_irf:冲击响应图阵列,展示不同冲击的动态传导。chart_fevd:方差分解堆叠图,展示各冲击来源贡献占比。chart_stability:稳定性根图(单位圆),用于判断系统稳定性。
在论文中,建议按“模型设定 → 选阶结果 → 参数估计 → 诊断检验 → 预测/IRF/FEVD”的顺序组织正文,并将 Charts_Index 与关键图表编号保持一致,以提高结果可追溯性。
12. 论文写作模板
“本文采用向量自回归模型(VAR)刻画多变量时间序列之间的动态关系。首先,根据研究设定选择确定性项并构建 VAR\((p)\) 形式(式(2)–式(4));其次,通过最小二乘法估计参数矩阵与残差协方差(式(6)–式(7)),并基于信息准则选择最优滞后阶(式(9)–式(12));随后对模型进行稳定性、白噪声、正态性与异方差检验(式(13)、式(22)–式(24));最后输出多步预测、冲击响应与方差分解结果(式(16)–式(21)),用于解释系统短期与中长期动态效应。”
13. 结果解释模板段落
“实证结果显示,所选 VAR 模型在信息准则意义下具有较优拟合表现,稳定性检验表明特征根位于单位圆内,模型满足动态稳定条件。残差诊断结果总体支持白噪声假设,且正态性与异方差检验未显示显著异常。进一步地,预测结果揭示了关键变量未来阶段的变化路径,冲击响应函数表明各变量对结构冲击存在明显的时滞传导效应,方差分解结果则量化了不同冲击源对预测误差的贡献结构。”
附录 A:英文摘要(可直接使用)
This study employs a Vector Autoregression (VAR) framework to model the dynamic interactions among multiple endogenous time-series variables. The model structure includes optional deterministic terms (constant, linear trend, and quadratic trend), and the lag order is selected by information criteria (AIC/BIC/HQIC/FPE). Parameters are estimated by ordinary least squares in matrix form, followed by comprehensive diagnostic checks including stability roots, Ljung-Box autocorrelation tests, Jarque-Bera normality tests, and ARCH-LM heteroskedasticity tests.
Based on the estimated system, the study further conducts multi-step forecasting with confidence intervals, orthogonalized impulse response analysis, and forecast error variance decomposition. The empirical output is exported as reproducible multi-sheet Excel tables and figure files, which facilitates transparent reporting and direct integration into academic writing. Overall, the VAR results provide interpretable evidence on short-run transmission effects and medium-term dynamic contribution structures among variables.
附录 B:英文方法段(可直接使用)
B.1 Methodological Framework
Let \(\mathbf{y}_t=(y_{1t},\ldots,y_{kt})^\top\) denote a \(k\)-dimensional endogenous vector at time \(t\). The VAR\((p)\) model is specified as
$$ \mathbf{y}_t=\mathbf{d}_t+\sum_{i=1}^{p}\mathbf{A}_i\mathbf{y}_{t-i}+\mathbf{u}_t, $$
where \(\mathbf{d}_t\) represents deterministic components and \(\mathbf{u}_t\sim(\mathbf{0},\Sigma_u)\).
The lag length \(p\) is determined by minimizing information criteria over a candidate range, and coefficients are estimated by ordinary least squares.
B.2 Estimation and Model Diagnostics
After estimation, model adequacy is evaluated from three aspects. First, system stability is checked through companion-matrix eigenvalues; all roots are required to lie inside the unit circle. Second, residual serial dependence is tested by the Ljung-Box statistic. Third, distributional and volatility assumptions are assessed by Jarque-Bera and ARCH-LM tests, respectively.
In addition, stationarity and long-run equilibrium properties can be examined by ADF and Johansen procedures when applicable, so that differencing settings and long-run interpretations remain econometrically consistent.
B.3 Dynamic Analysis and Forecasting
Given the estimated VAR system, multi-step forecasts are generated recursively, and prediction intervals are constructed from the forecast error covariance matrix under a normal approximation. Dynamic transmission is analyzed using orthogonalized impulse response functions (IRFs), while the relative contribution of shocks is quantified by forecast error variance decomposition (FEVD).
These outputs jointly support both substantive interpretation (direction, magnitude, and persistence of shocks) and reporting requirements in empirical research.
B.4 Reproducible Output for Reporting
For reproducibility, the system exports structured outputs including parameter tables, lag-order comparison, residual diagnostics, forecast tables, IRF/FEVD tables, and indexed figures. This standardized pipeline ensures that methodological statements, quantitative results, and visual evidence are fully aligned in thesis or journal manuscripts.
14. 单篇终审补充
14.1 图题与表题对齐建议
- 本文档应优先对应真实算法目录
具体的算法2/VAR-向量自回归(VAR),代表性结果目录建议绑定具体的算法2/VAR-向量自回归(VAR)/results/window3_baseline_test_window3_timeseries_dynami4_var。 - 表题应直接对应
var_baseline.xlsx的真实工作表:RawData_Preview、Data_Selected、LagOrder、Parameters、Residuals、Diag_LjungBox、Diag_JB、Diag_ARCHLM、Forecast、Forecast_Level、IRF、FEVD、Stability、Stationarity、Cointegration、Run_Parameters、Charts_Index。 - 图题应优先绑定同目录下真实落地的图像族,例如
chart_series_20260329_165444.png、chart_forecast_20260329_165444.png、chart_irf_20260329_165444.png、chart_fevd_20260329_165444.png、chart_stability_20260329_165444.png。 - 由于该目录内既保留
var_baseline.xlsx,也保留多轮VAR复现结果_*.xlsx与配套图像,正文若引用具体文件名,需明确是 baseline 总表还是某次复现时间戳产物,避免把两类结果混写。
14.2 终审说明
- 当前 VAR 文档已经具备较完整的论文证据链:baseline 总表、分项诊断 sheet、IRF/FEVD 图族、复现脚本和
repro_inputs/var_input.csv均已实存。 - 复现脚本可直接引用
repro_var_20260329_165444.py,其SRC_FILE实际写为results/window3_baseline_test_window3_timeseries_dynami4_var/repro_inputs/var_input.csv。 - 因此复现说明应明确为“模块根目录相对路径复现”,而不是简单写成“脚本自动读取当前目录原始 CSV”。这类口径差异在 Windows 打包和论文附录说明里都应保持一致。
14.3 全量强化补充
- 当前 VAR 文档应绑定真实算法目录
具体的算法2/VAR-向量自回归(VAR),代表性主目录为具体的算法2/VAR-向量自回归(VAR)/results/window3_baseline_test_window3_timeseries_dynami4_var。 - 该目录首层主工作簿为
var_baseline.xlsx;同目录还累计保留了多份VAR复现结果_*.xlsx。当前这些工作簿的真实工作表一致,均为RawData_Preview、Data_Selected、LagOrder、Parameters、Residuals、Diag_LjungBox、Diag_JB、Diag_ARCHLM、Forecast、Forecast_Level、IRF、FEVD、Stability、Stationarity、Cointegration、Run_Parameters、Charts_Index。 - 同目录中图文件按时间戳成组平铺保留。若论文只引用当前主轮结果,应优先锁定
20260329_165444这一组:chart_series_20260329_165444.png、chart_forecast_20260329_165444.png、chart_irf_20260329_165444.png、chart_fevd_20260329_165444.png、chart_stability_20260329_165444.png。 - 当前目录同时存在
repro_inputs/var_input.csv与repro_var_20260329_165444.py,脚本关键输入写法为SRC_FILE = 'results/window3_baseline_test_window3_timeseries_dynami4_var/repro_inputs/var_input.csv'。因此 VAR 的复现口径是“模块根目录相对路径回指 baseline 目录内repro_inputs”。 - 由于 baseline 总表、复现结果簿、图文件和 repro 脚本都共存在同一目录,正文和附录应清楚区分
var_baseline.xlsx与VAR复现结果_*.xlsx的角色,不要把它们混写成同一份主结果。
15. 软件实现核查补充(2026-07)
- 当前实现的主结果目录应写作
具体的算法2/VAR-向量自回归(VAR)/results/window3_baseline_test_window3_timeseries_dynami4_var,主工作簿为var_baseline.xlsx。 - 正文应围绕
RawData_Preview、Data_Selected、LagOrder、Parameters、Residuals、Diag_LjungBox、Diag_JB、Diag_ARCHLM、Forecast、Forecast_Level、IRF、FEVD、Stability、Stationarity、Cointegration、Run_Parameters、Charts_Index来写,图则对应chart_series_20260329_165444.png、chart_forecast_20260329_165444.png、chart_irf_20260329_165444.png、chart_fevd_20260329_165444.png、chart_stability_20260329_165444.png。 repro_var_20260329_165444.py + results/window3_baseline_test_window3_timeseries_dynami4_var/repro_inputs/var_input.csv属于模块根目录相对路径回指 baseline 目录的复现口径。- 如果要给用户一条最稳妥复现路径,就把 baseline 总表、复现脚本和输入副本分层写清,不要把
VAR复现结果_*.xlsx和var_baseline.xlsx混成一层。