从 plot_acf 中获取超过置信区间的特定滞后

get specific lags from plot_acf that are over the confidence interval

我如何从这个情节中得到

import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm

dta = sm.datasets.sunspots.load_pandas().data
dta.index = pd.Index(sm.tsa.datetools.dates_from_range('1700', '2008'))
del dta["YEAR"]
sm.graphics.tsa.plot_acf(dta.values.squeeze(), lags=40)
plt.show()

over/under 置信区间的特定滞后?

您可以使用acf而不是绘图界面来获取数值。关键步骤是通过从置信区间中减去 ACF 来使置信区间居中,使其以 0 为中心。从 acf 返回的 CI 以估计的 ACF 值为中心。

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm
from statsmodels.tsa.stattools import acf

dta = sm.datasets.sunspots.load_pandas().data
dta.index = pd.Index(sm.tsa.datetools.dates_from_range('1700', '2008'))
nlags = 40
alpha = 0.05
fft=True
adjusted = False
missing = "none"
bartlett_confint = True
x = dta.SUNACTIVITY
a, ci = acf(x, nlags=40, alpha=0.05)
# Key step
centered_ci = ci - a[:,None]
outside = np.abs(a) >= centered_ci[:,1]
inside = ~outside

print(outside)

显示

[ True  True  True False  True  True  True False False  True  True  True
  True False False  True  True  True False False  True  True  True False
 False False  True  True False False False False False False False False
 False False False False False]