#一元线性回归的基本步骤
#1.载入数据 给出散点图
x<-c(0.10,0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18,0.20,0.21,0.23) y<-c(42.0,43.5,45.0,45.5,45.0,47.5,49.0,53.0,50.0,55.0,55.0,60.0) plot(x,y)
#2.线性回归 得到回归方程 并查看回归结果
CG<-lm(y~x)
CG
summary(CG)
#所得回归方程为y=130.83x+28.49
#3.线性拟合
abline(CG)#添加拟合直线
#4.预测x0=0.16时相应Y的概率为0.95的预测区间
x0<-data.frame(x=0.16) Pred<-predict(CG,interval="prediction",level=0.95) Pred
#5.回归结果分析 计算残差 并作残差图
Resi<-residuals(CG)
Resi
plot(Resi)
原文:http://www.cnblogs.com/liuzezhuang/p/3717881.html