【问题标题】:How to get the variance of a VAR(1) model in statsmodels?如何在 statsmodels 中获取 VAR(1) 模型的方差?
【发布时间】:2021-08-26 12:59:48
【问题描述】:

我在 statsmodels 中估计了一个 VAR(1) 模型(示例代码来自statsmodels user guide)。

import numpy as np
import pandas as pd
import statsmodels.api as sm
from statsmodels.tsa.api import VAR
from statsmodels.tsa.base.datetools import dates_from_str

# prepare the data
mdata = sm.datasets.macrodata.load_pandas().data
dates = mdata[['year', 'quarter']].astype(int).astype(str)
quarterly = dates["year"] + "Q" + dates["quarter"]
quarterly = dates_from_str(quarterly)
mdata = mdata[['realgdp','realcons','realinv']]
mdata.index = pd.DatetimeIndex(quarterly)
data = np.log(mdata).diff().dropna()

# make a VAR model
model = VAR(data)
results = model.fit(1)

我想计算 VAR 模型的方差(单击 here 了解说明)。 VARResults 对象的属性或属性是否可以直接给出方差?

【问题讨论】:

    标签: python statsmodels


    【解决方案1】:

    我找到了答案。

    results.acf(0)
    

    VARResults 对象的acf() 方法计算 VAR 模型的理论自协方差函数。

    【讨论】:

      猜你喜欢
      • 2018-02-18
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 2021-06-05
      • 2019-05-20
      • 2017-06-22
      • 1970-01-01
      • 2016-05-26
      相关资源
      最近更新 更多