如何在python中计算标准化残差?

时间:2019-11-01 21:33:38

标签: python arima

我将如何根据Arima模型sarimax函数计算标准残差?

让我们说我们有一些基本模型:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style='ticks', context='poster')
from statsmodels.tsa.statespace.sarimax import SARIMAX
from statsmodels.tsa.seasonal import seasonal_decompose
import seaborn as sns
#plt.style.use("ggplot")
import pandas_datareader.data as web
import pandas as pd
import statsmodels.api as sm
import scipy
import statsmodels.stats.api as sms
import matplotlib.pyplot as plt
import datetime

model = SARIMAX(df, order = (6, 0, 0), trend = "c");
model_results = model.fit(maxiter = 500);
print(model_results.summary());

我需要标准化器,因此当我们使用model_results.plot_diagnostics(figsize = (16, 10));函数,然后基本的plot函数残差应该看起来相同。

1 个答案:

答案 0 :(得分:0)

我认为您可以使用https://stackoverflow.com/a/57155553/14294235中的“ internally_studentized_residual”功能

它应该像这样工作:

model = SARIMAX(df, order = (6, 0, 0), trend = "c");

model_results = model.fit(maxiter = 500);

model_fittebd_y = model_results.fittedvalues

resid_studentized = internally_studentized_residual(df,model_fitted_y)
resid_studentized = -resid_studentized 

plt.plot(resid_studentized)
plt.axhline(y=0, color='b', linestyle='--')
plt.show()
相关问题