StatsModels' RegressionResults
has a conf_int()
method. Here an example using it (minimally modified version of their Ordinary Least Squares example):
import numpy as np, statsmodels.api as sm
nsample = 100
x = np.linspace(0, 10, nsample)
X = np.column_stack((x, x**2))
beta = np.array([1, 0.1, 10])
e = np.random.normal(size=nsample)
X = sm.add_constant(X)
y = np.dot(X, beta) + e
mod = sm.OLS(y, X)
res = mod.fit()
print res.conf_int(0.01) # 99% confidence interval
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…