线性回归是模型中最基本的一种,怎么用R做,怎么读懂各项统计指标呢?
上代码
1. 给出数据
mouse.data<-data.frame(
weight=c(1.8,0.9,2.4,3.5,3.9,4.4,5.1,5.6,6.3),
size=c(1.4,2.6,1.0,3.7,5.5,3.2,3.0,4.9,6.3))
##看一下
mouse.data

2.看一下数据分布
plot(mouse.data$weight,mouse.data$size)

3. 拟合线性回归方程
mouse.regression<-lm(size~weight, data=mouse.data)
4. 查看模型拟合情况
summary(mouse.regression)

5. 各项指标解读

1 模型拟合残差:各点到拟合直线的距离
2 两个变量的情况:截距(Intercept)和因变量(weight)
3 两个变量的P值:即显著程度,由于截距的P值是否显著不影响拟合的精确度,所以不看。而因变量的P值小于0.05,很好。*代表显著程度,越多越好
4 Multiple R-squared: 越接近1说明越精准
Adjusted R-squared: 矫正后的R方值,除去过变量自身的干扰,比R方更准确
F值:衡量R方是否显著
P-value:这个方程是否显著
6.显示拟合的直线
abline(mouse.regression)

网友评论