statsmodels AR模型回答错误
statsmodel AR model answers wrong
我正在尝试在 Python
中复制以下 R 代码
set.seed(1)
x<-w<-rnorm(100)
for (t in 2:100) x[t] = 0.6 * x[t-1] + w[t]
x.ar = ar(x, method="mle")
x.ar$ar
[1] 0.5231187
在python中我有以下代码。
import scipy.stats as stats
import matplotlib.pylab as plt
import statsmodels.tsa.ar_model as ar_model
x = w = stats.norm.rvs(loc=0, scale=1, size=100)
for i in range(1,100):
x[i] = 0.6* x[i-1] + w[i]
ar = ar_model.AR(x)
model_ar = ar.fit(method='mle')
print(model_ar.params)
[ 9.26969930e-04 8.58915676e-01 2.74538400e+00 -1.49505968e+00
-3.47150385e+00 9.64130378e-02 2.68088493e+00 1.64061441e+00
-1.38189445e+00 -1.65265872e+00 6.33895141e-01 5.68494490e-01
-2.23487269e-01]
在 python 中,它似乎适合 13 阶模型。我怎样才能让它适合最简单的模型?
参见docs:对于statsmodels.tsa.ar_model.AR.fit()
,您可以select一个信息标准(参数ic
)来确定滞后数:
Criterion used for selecting the optimal lag length. aic - Akaike
Information Criterion bic - Bayes Information Criterion t-stat - Based
on last lag hqic - Hannan-Quinn Information Criterion If any of the
information criteria are selected, the lag length which results in the
lowest value is selected. If t-stat, the model starts with maxlag and
drops a lag until the highest lag has a t-stat that is significant at
the 95 % level.
或提供 maxlag
值。如果缺少后者,statsmodels
使用默认值 round(12*(nobs/100.)**(1/4.))
来确定要使用的滞后数。
我正在尝试在 Python
中复制以下 R 代码set.seed(1)
x<-w<-rnorm(100)
for (t in 2:100) x[t] = 0.6 * x[t-1] + w[t]
x.ar = ar(x, method="mle")
x.ar$ar
[1] 0.5231187
在python中我有以下代码。
import scipy.stats as stats
import matplotlib.pylab as plt
import statsmodels.tsa.ar_model as ar_model
x = w = stats.norm.rvs(loc=0, scale=1, size=100)
for i in range(1,100):
x[i] = 0.6* x[i-1] + w[i]
ar = ar_model.AR(x)
model_ar = ar.fit(method='mle')
print(model_ar.params)
[ 9.26969930e-04 8.58915676e-01 2.74538400e+00 -1.49505968e+00
-3.47150385e+00 9.64130378e-02 2.68088493e+00 1.64061441e+00
-1.38189445e+00 -1.65265872e+00 6.33895141e-01 5.68494490e-01
-2.23487269e-01]
在 python 中,它似乎适合 13 阶模型。我怎样才能让它适合最简单的模型?
参见docs:对于statsmodels.tsa.ar_model.AR.fit()
,您可以select一个信息标准(参数ic
)来确定滞后数:
Criterion used for selecting the optimal lag length. aic - Akaike Information Criterion bic - Bayes Information Criterion t-stat - Based on last lag hqic - Hannan-Quinn Information Criterion If any of the information criteria are selected, the lag length which results in the lowest value is selected. If t-stat, the model starts with maxlag and drops a lag until the highest lag has a t-stat that is significant at the 95 % level.
或提供 maxlag
值。如果缺少后者,statsmodels
使用默认值 round(12*(nobs/100.)**(1/4.))
来确定要使用的滞后数。