当有两个及以上的X变量时,线性回归不能用了,此时要做多重线性回归。
上代码
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),
tail=c(1.2,1.5,2.1,2.1,1,2,1.3,1.8,1.9))
##看一下
mouse.data

2. 看一下数据情况
plot(mouse.data)

3. 拟合多重线性回归
multiple.regression<-lm(mouse.data$size~mouse.data$weight+mouse.data$tail)
4. 查看拟合指标
summary(multiple.regression)

如果你不知道怎么读,请移步https://www.jianshu.com/p/178190a5e8e3
网友评论