How can I calculate standardized residuals in python?

ぐ巨炮叔叔 提交于 2021-02-11 12:35:05

问题


How would I calculated standartized residuals from arima model sarimax function?

lets say we have some basic model:

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());

I need standardizer so when we use model_results.plot_diagnostics(figsize = (16, 10)); function and then just basic plot function residuals should look the same.


回答1:


I think you can use the function "internally_studentized_residual" from https://stackoverflow.com/a/57155553/14294235

It should work like this:

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()


来源:https://stackoverflow.com/questions/58666173/how-can-i-calculate-standardized-residuals-in-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!