ex10.1
1.代码实现
点击查看代码
import numpy as np
import statsmodels.api as sm
import pylab as plt
def check(d):
x0=d[0]
y0=d[1]
d={'x':x0,'y':y0}
re=sm.formula.ols('y~x',d).fit()
print(re.summary())
print(re.outlier_test())
pre=re.get_prediction(d)
df=pre.summary_frame(alpha=0.05)
dfv=df.values
low,upp=dfv[:,4:].T
r=(upp-low)/2
num=np.arange(1,len(x0)+1)
plt.errorbar(num,re.resid,r,fmt='o')
plt.show()
a=np.loadtxt('data10_1.txt')
plt.rc('font',size=15)
plt.plot(a[0],a[1],'o')
plt.figure()
check(a)
a2=a
a2=np.delete(a2,8,axis=1)
check(a2)
a3=a2
a3=np.delete(a3,4,axis=1)
check(a3)
2.运行结果