先声明,本博客为个人作业不一定为标准答案,仅供参考
9.1 题目如下
各模型结果汇总:
> model1<-lm(y1~x1,data=anscombe)
> summary(model1)
Call:
lm(formula = y1 ~ x1, data = anscombe)
Residuals:
Min 1Q Median 3Q Max
-1.92127 -0.45577 -0.04136 0.70941 1.83882
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.0001 1.1247 2.667 0.02573 *
x1 0.5001 0.1179 4.241 0.00217 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.237 on 9 degrees of freedom
Multiple R-squared: 0.6665, Adjusted R-squared: 0.6295
F-statistic: 17.99 on 1 and 9 DF, p-value: 0.00217
> model2<-lm(y2~x2,data=anscombe)
> summary(model2)
Call:
lm(formula = y2 ~ x2, data = anscombe)
Residuals:
Min 1Q Median 3Q Max
-1.9009 -0.7609 0.1291 0.9491 1.2691
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.001 1.125 2.667 0.02576 *
x2 0.500 0.118 4.239 0.00218 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.237 on 9 degrees of freedom
Multiple R-squared: 0.6662, Adjusted R-squared: 0.6292
F-statistic: 17.97 on 1 and 9 DF, p-value: 0.002179
> model3<-lm(y3~x3,data=anscombe)
> summary(model3)
Call:
lm(formula = y3 ~ x3, data = anscombe)
Residuals:
Min 1Q Median 3Q Max
-1.1586 -0.6146 -0.2303 0.1540 3.2411
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.0025 1.1245 2.670 0.02562 *
x3 0.4997 0.1179 4.239 0.00218 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.236 on 9 degrees of freedom
Multiple R-squared: 0.6663, Adjusted R-squared: 0.6292
F-statistic: 17.97 on 1 and 9 DF, p-value: 0.002176
> model4<-lm(y4~x4,data=anscombe)
> summary(model4)
Call:
lm(formula = y4 ~ x4, data = anscombe)
Residuals:
Min 1Q Median 3Q Max
-1.751 -0.831 0.000 0.809 1.839
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.0017 1.1239 2.671 0.02559 *
x4 0.4999 0.1178 4.243 0.00216 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 1.236 on 9 degrees of freedom
Multiple R-squared: 0.6667, Adjusted R-squared: 0.6297
F-statistic: 18 on 1 and 9 DF, p-value: 0.002165
比较可知:各模型基本相同
散点图:
> par(mfrow=c(2,2),cex=0.8,cex.main=0.7)
> plot(anscombe$x1,anscombe$y1,pch=19,col="green4",xlab="x1",ylab="y1")
> abline(lm(anscombe$y1~anscombe$x1),lwd=2,col="red")
> plot(anscombe$x2,anscombe$y2,pch=19,col="green4",xlab="x2",ylab="y2")
> abline(lm(anscombe$y2~anscombe$x2),lwd=2,col="red")
> plot(anscombe$x3,anscombe$y3,pch=19,col="green4",xlab="x3",ylab="y3")
> abline(lm(anscombe$y3~anscombe$x3),lwd=2,col="red")
> plot(anscombe$x4,anscombe$y4,pch=19,col="green4",xlab="x4",ylab="y4")
> abline(lm(anscombe$y4~anscombe$x4),lwd=2,col="red")
散点图显示,只有模型1和模型4是正确的,其余的都不正确,应考虑建立非线性模型
9.2 题目如下
(1)
> example9_2<-read.csv("D:/作业/统计学R/《统计学—基于R》(第4版)—例题和习题数据(公开资源)/exercise/chap09/exercise9_2.csv")
> model<-lm(投诉次数~航班准点率,data=example9_2)
> summary(model)
Call:
lm(formula = 投诉次数 ~ 航班准点率, data = example9_2)
Residuals:
Min 1Q Median 3Q Max
-24.678 -11.412 -2.078 16.322 24.615
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 430.1892 72.1548 5.962 0.000337 ***
航班准点率 -4.7006 0.9479 -4.959 0.001108 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 18.89 on 8 degrees of freedom
Multiple R-squared: 0.7545, Adjusted R-squared: 0.7239
F-statistic: 24.59 on 1 and 8 DF, p-value: 0.001108
回归系数=-4.7006表示,航班准点率每增加1%,投诉次数平均减少4.7次
(2)
H₀:β₁=0(自变量对因变量的影响不显著) H₁:β₁=0(自变量对因变量的影响显著)
见第一题中p=0.001108<0.05,拒绝原假设,回归系数显著
(3)
> x0<-data.frame(航班准点率=80)
> predict(model,newdata=x0)
1
54.13942
估计的投诉次数为54.13942
9.3 题目如下
回归模型如下:
> example9_3<-read.csv("D:/作业/统计学R/《统计学—基于R》(第4版)—例题和习题数据(公开资源)/exercise/chap09/exercise9_3.csv")
> model<-lm(销售额.万元~广告费支出.万元,data=example9_3)
> summary(model)
Call:
lm(formula = 销售额.万元 ~ 广告费支出.万元, data = example9_3)
Residuals:
1 2 3 4 5 6 7
-11.9466 -0.4941 8.4110 1.3160 7.1261 1.9362 -6.3487
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 29.3991 4.8073 6.116 0.00169 **
广告费支出.万元 1.5475 0.4635 3.339 0.02058 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 7.878 on 5 degrees of freedom
Multiple R-squared: 0.6903, Adjusted R-squared: 0.6284
F-statistic: 11.15 on 1 and 5 DF, p-value: 0.02058
模型各项检验显著,R²=69.03%,拟合程度较好
诊断图如下:
> plot(model)
诊断图显示,残差满足正态性,方差齐性可能需要进一步分析。。
本次记录就到这。