x 54.893 2.350 23.36 2.26e-11 *** ---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 17.59 on 12 degrees of freedom Multiple R-squared: 0.9785, Adjusted R-squared: 0.9767 F-statistic: 545.5 on 1 and 12 DF, p-value: 2.265e-11 线性回归模型为y=523.800+54.893x,通过t检验和F检验。 (2)
> lm.sol<-lm(y~1+x+I(x^2));summary(lm.sol)
Call:
lm(formula = y ~ 1 + x + I(x^2))
Residuals:
Min 1Q Median 3Q Max
-10.6643 -5.6622 -0.4655 5.5000 10.6679
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 502.5560 4.8500 103.619 < 2e-16 *** x 80.3857 3.7861 21.232 2.81e-10 *** I(x^2) -4.2488 0.6063 -7.008 2.25e-05 *** ---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 7.858 on 11 degrees of freedom Multiple R-squared: 0.9961, Adjusted R-squared: 0.9953 F-statistic: 1391 on 2 and 11 DF, p-value: 5.948e-14 多项式回归模型为:
y=502.5560+80.3857x-4.2488x^2,通过t检验和F检验。 (3)作散点图和拟合曲线:
> plot(x,y)
> xfit<-seq(0,6,0.01)
> yfit<-predict(lm.sol,data.frame(x=xfit)) > lines(xfit,yfit)
Ex6.8 读入数据:
> cancer<-read.table(\> cancer
x1 x2 x3 x4 x5 y 1 70 64 5 1 1 1 2 60 63 9 1 1 0 3 70 65 11 1 1 0 4 40 69 10 1 1 0 5 40 63 58 1 1 0 6 70 48 9 1 1 0 7 70 48 11 1 1 0 8 80 63 4 2 1 0 9 60 63 14 2 1 0 10 30 53 4 2 1 0 11 80 43 12 2 1 0 12 40 55 2 2 1 0 13 60 66 25 2 1 1 14 40 67 23 2 1 0 15 20 61 19 3 1 0
16 50 63 4 3 1 0 17 50 66 16 0 1 0 18 40 68 12 0 1 0 19 80 41 12 0 1 1 20 70 53 8 0 1 1 21 60 37 13 1 1 0 22 90 54 12 1 0 1 23 50 52 8 1 0 1 24 70 50 7 1 0 1 25 20 65 21 1 0 0 26 80 52 28 1 0 1 27 60 70 13 1 0 0 28 50 40 13 1 0 0 29 70 36 22 2 0 0 30 40 44 36 2 0 0 31 30 54 9 2 0 0 32 30 59 87 2 0 0 33 40 69 5 3 0 0 34 60 50 22 3 0 0 35 80 62 4 3 0 0 36 70 68 15 0 0 0 37 30 39 4 0 0 0 38 60 49 11 0 0 0 39 80 64 10 0 0 1 40 70 67 18 0 0 1 >
glm.sol<-glm(y~x1+x2+x3+x4+x5,family=binomial,data=cancer);summary(glm.sol)
Call:
glm(formula = y ~ x1 + x2 + x3 + x4 + x5, family = binomial, data = cancer)
Deviance Residuals:
Min 1Q Median 3Q Max
-1.71500 -0.66725 -0.22254 0.09936 2.23936
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) -7.01140 4.47534 -1.567 0.1172 x1 0.09994 0.04304 2.322 0.0202 * x2 0.01415 0.04697 0.301 0.7631 x3 0.01749 0.05458 0.320 0.7486 x4 -1.08297 0.58721 -1.844 0.0651 .
x5 -0.61309 0.96066 -0.638 0.5233 ---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Dispersion parameter for binomial family taken to be 1)
Null deviance: 44.987 on 39 degrees of freedom Residual deviance: 28.392 on 34 degrees of freedom AIC: 40.392
Number of Fisher Scoring iterations: 6 有的系数并不显著。 下面做逐步回归:
> glm.new<-step(glm.sol) Start: AIC=40.39
y ~ x1 + x2 + x3 + x4 + x5
Df Deviance AIC - x3 1 28.484 38.484 - x2 1 28.484 38.484 - x5 1 28.799 38.799
Step: AIC=38.48
y ~ x1 + x2 + x4 + x5
Df Deviance AIC - x2 1 28.564 36.564 - x5 1 28.993 36.993
Step: AIC=36.56 y ~ x1 + x4 + x5
Df Deviance AIC - x5 1 29.073 35.073
相关推荐: