概念
- 在表3.4中,“电视”的零假设是,在存在广播广告和报纸广告的情况下,电视广告对销售没有影响。“广播”的零假设是,在电视和报纸广告存在的情况下,广播广告对销售没有影响。“报纸”的零假设是,在电视和广播广告存在的情况下,报纸广告对销售没有影响。
电视和广播的低p值表明出现零假设正确的概率比较小,我们有理由拒绝零假设,认为电视和广播对销售产生影响。而报纸的p值较大,说明我们没有理由拒绝零假设,认为报纸对销售基本没有影响。 - KNN分类器的输出结果是定性变量;KNN回归的输出结果是定量变量。
- Y = 50 + 20 G P A + 0.07 I Q + 35 G e n d e r + 0.01 ( G P A ∗ I Q ) − 10 ( G P A ∗ G e n d e r ) Y=50+20GPA+0.07IQ+35Gender+0.01(GPA*IQ)-10(GPA*Gender) Y=50+20GPA+0.07IQ+35Gender+0.01(GPA∗IQ)−10(GPA∗Gender)
(a)
male:gender=0, Y = 50 + 20 G P A + 0.07 I Q + 0.01 ( G P A ∗ I Q ) = 50 + 20 G P A + 0.07 I Q + 0.01 ( G P A ∗ I Q ) Y=50+20GPA+0.07IQ+0.01(GPA*IQ)=50+20GPA+0.07IQ+0.01(GPA*IQ) Y=50+20GPA+0.07IQ+0.01(GPA∗IQ)=50+20GPA+0.07IQ+0.01(GPA∗IQ)
female:gender=1, Y = 50 + 20 G P A + 0.07 I Q + 35 + 0.01 ( G P A ∗ I Q ) − 10 G P A = 85 + 10 G P A + 0.07 I Q + 0.01 ( G P A ∗ I Q ) Y=50+20GPA+0.07IQ+35+0.01(GPA*IQ)-10GPA=85+10GPA+0.07IQ+0.01(GPA*IQ) Y=50+20GPA+0.07IQ+35+0.01(GPA∗IQ)−10GPA=85+10GPA+0.07IQ+0.01(GPA∗IQ)
当GPA足够高时,男性的平均收入高于女性。
(b)
Y(Gender = 1, IQ = 110, GPA = 4.0)= 50 + 20 * 4 + 0.07 * 110 + 35 + 0.01 (4 * 110) - 10 * 4=137.1
©
该命题不正确。
必须通过回归系数的p值来确定交互项是否具有统计意义。
(a)
多项式回归比线性回归具有更低的训练RSS,因为它可以更紧密地拟合与更广泛的不可约误差匹配的数据。
(b)
多项式回归具有更高的测试RSS,因为训练的过度拟合比线性回归具有更多的误差。
©
多项式回归比线性拟合具有更低的训练RSS,因为它具有更高的灵活性:无论潜在的真实关系是什么,更灵活的模型都会更接近跟踪点并减少训练RSS。
(d)
由偏差-方差权衡:尚不清楚哪种程度的灵活性更适合数据。
如果问题更接近线性而不是立方,则线性回归检验RSS可能低于立方回归检验RSS。如果问题更接近三次而不是线性,三次回归测试RSS可能低于线性回归测试RSS。
应用
library(MASS)
install.packages("ISLR")
library(ISLR)
library(car)
Auto=read.csv("Auto.csv",header=T,na.strings="?")
Auto=na.omit(Auto)
attach(Auto)
summary(Auto)
mpg cylinders displacement horsepower weight
Min. : 9.00 Min. :3.000 Min. : 68.0 Min. : 46.0 Min. :1613
1st Qu.:17.00 1st Qu.:4.000 1st Qu.:105.0 1st Qu.: 75.0 1st Qu.:2225
Median :22.75 Median :4.000 Median :151.0 Median : 93.5 Median :2804
Mean :23.45 Mean :5.472 Mean :194.4 Mean :104.5 Mean :2978
3rd Qu.:29.00 3rd Qu.:8.000 3rd Qu.:275.8 3rd Qu.:126.0 3rd Qu.:3615
Max. :46.60 Max. :8.000 Max. :455.0 Max. :230.0 Max. :5140
acceleration year origin name
Min. : 8.00 Min. :70.00 Min. :1.000 Length:392
1st Qu.:13.78 1st Qu.:73.00 1st Qu.:1.000 Class :character
Median :15.50 Median :76.00 Median :1.000 Mode :character
Mean :15.54 Mean :75.98 Mean :1.577
3rd Qu.:17.02 3rd Qu.:79.00 3rd Qu.:2.000
Max. :24.80 Max. :82.00 Max. :3.000
(a)
lm.fit=lm(mpg~horsepower)
summary(lm.fit)
Call:
lm(formula = mpg ~ horsepower)
Residuals:
Min 1Q Median 3Q Max
-13.5710 -3.2592 -0.3435 2.7630 16.9240
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 39.935861 0.717499 55.66 <2e-16 ***
horsepower -0.157845 0.006446 -24.49 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 4.906 on 390 degrees of freedom
Multiple R-squared: 0.6059, Adjusted R-squared: 0.6049
F-statistic: 599.7 on 1 and 390 DF, p-value: < 2.2e-16
- 由于F-statistic值远大于1,p值接近于0,拒绝原假设,则horsepower和mpg具有统计显著关系。
- mpg的平均值为23.45,线性回归的RSE为4.906,有20.9248%的相对误差。R-squared为0.6059,说明60.5948%的mpg可以被horsepower解释
- 线性回归系数小于零,说明mpg与horsepower负相关
>predictor=mpg
> response=horsepower
> lm.fit2=lm(predictor~response)
> predict(lm.fit2,data.frame(response=c(98)),interval="confidence")
fit lwr upr
1 24.46708 23.97308 24.96108
> predict(lm.fit2,data.frame(response=c(98)),interval="prediction")
fit lwr upr
1 24.46708 14.8094 34.12476
(b)
plot(response,predictor)
abline(lm.fit2,lwd=3,col="red")
( c )
par(mfrow=c(2,2)