预测值的Python置信带

预测值的Python置信带,python,statsmodels,Python,Statsmodels,我正在拟合一个线性回归,并希望为超出拟合值范围的点投影置信带 从中,有一个获取拟合范围内值的标注栏的示例: import numpy as np import statsmodels.api as sm from statsmodels.sandbox.regression.predstd import wls_prediction_std #Generate some data n = 20 x = np.sort(np.random.normal(size=n)) e = np.rando

我正在拟合一个线性回归,并希望为超出拟合值范围的点投影置信带

从中,有一个获取拟合范围内值的标注栏的示例:

import numpy as np
import statsmodels.api as sm
from statsmodels.sandbox.regression.predstd import wls_prediction_std

#Generate some data
n = 20
x = np.sort(np.random.normal(size=n))
e = np.random.normal(size=n)
y = 1 + 0.5*x + 1*e
X = sm.add_constant(x)

#Fit the model
re = sm.OLS(y, X).fit()


from statsmodels.stats.outliers_influence import summary_table

st, data, ss2 = summary_table(re, alpha=0.05)

#Get the confidence intervals
fittedvalues = data[:,2]
predict_mean_se  = data[:,3]
predict_mean_ci_low, predict_mean_ci_upp = data[:,4:6].T
predict_ci_low, predict_ci_upp = data[:,6:8].T

#Plot confidence intervals and data points
plt.plot(x, y, 'o')
plt.plot(x, fittedvalues, '-', lw=2)
plt.plot(x, predict_ci_low, 'r--', lw=2)
plt.plot(x, predict_ci_upp, 'r--', lw=2)
plt.plot(x, predict_mean_ci_low, 'r--', lw=2)
plt.plot(x, predict_mean_ci_upp, 'r--', lw=2)
plt.show()

但是,这不允许我将频带扩展到预测值。如何将这些边界扩展到拟合值范围之外的值,例如对于
x=5