统计建模与R软件薛毅第六章答案

上传人:汽*** 文档编号:561774084 上传时间:2022-07-23 格式:DOC 页数:19 大小:276KB
返回 下载 相关 举报
统计建模与R软件薛毅第六章答案_第1页
第1页 / 共19页
统计建模与R软件薛毅第六章答案_第2页
第2页 / 共19页
统计建模与R软件薛毅第六章答案_第3页
第3页 / 共19页
统计建模与R软件薛毅第六章答案_第4页
第4页 / 共19页
统计建模与R软件薛毅第六章答案_第5页
第5页 / 共19页
点击查看更多>>
资源描述

《统计建模与R软件薛毅第六章答案》由会员分享,可在线阅读,更多相关《统计建模与R软件薛毅第六章答案(19页珍藏版)》请在金锄头文库上搜索。

1、第六章6.1#输入数据并运行得:x-c(5.1,3.5,7.1,6.2,8.8,7.8,4.5,5.6,8.0,6.4)y-c(1907,1287,2700,2373,3260,3000,1947,2273,3113,2493)plot(x,y)分析结果:由散点图可得x,y线性相关lm.sol|t|) (Intercept) 140.95 125.11 1.127 0.293 x 364.18 19.26 18.908 6.33e-08 *-Signif. codes: 0 * 0.001 * 0.01 * 0.05 . 0.1 1 Residual standard error: 96.42

2、 on 8 degrees of freedomMultiple R-squared: 0.9781, Adjusted R-squared: 0.9754 F-statistic: 357.5 on 1 and 8 DF, p-value: 6.33e-08分析结果:由上述结果可得y关于x的一元线性回归方程为y=140.95+364.18x;并由F检验和t检验,可得回归方程通过了回归方程的显著性检验#对数据进行预测,并且给相应的区间估计new-data.frame(x=7)lm.pred-predict(lm.sol,new,interval=prediction,level=0.95)lm

3、.pred fit lwr upr1 2690.227 2454.971 2925.484分析结果:预测值为2690.227,估计区间为2454.971 ,2925.4846.2#输入数据并运行x1-c(0.4,0.4,3.1,0.6,4.7,1.7,9.4,10.1,11.6,12.6,10.9,23.1,23.1,21.6,23.1,1.9,26.8,29.9)x2-c(52,23,19,34,24,65,44,31,29,58,37,46,50,44,56,36,58,51)x3-c(158,163,37,157,59,123,46,117,173,112,111,114,134,73,

4、168,143,202,124)y-c(64,60,71,61,54,77,81,93,93,51,76,96,77,93,95,54,168,99)lm.sol|t|) (Intercept) 43.65007 18.05442 2.418 0.02984 * x1 1.78534 0.53977 3.308 0.00518 *x2 -0.08329 0.42037 -0.198 0.84579 x3 0.16102 0.11158 1.443 0.17098 -Signif. codes: 0 * 0.001 * 0.01 * 0.05 . 0.1 1 Residual standard

5、error: 19.97 on 14 degrees of freedomMultiple R-squared: 0.5493, Adjusted R-squared: 0.4527 F-statistic: 5.688 on 3 and 14 DF, p-value: 0.009227 分析结果:由上述结果可得y关于x1,x2,x3的多元线性回归方程为y=43.65007+1.78534x1-0.08329x2+0.16102x3;通过F检验,但回归方程的t检验并不显著。#调用函数step()作逐步回归lm.step-step(lm.sol)Start: AIC=111.27y x1 + x

6、2 + x3 Df Sum of Sq RSS AIC- x2 1 15.7 5599.4 109.32 5583.7 111.27- x3 1 830.6 6414.4 111.77- x1 1 4363.4 9947.2 119.66Step: AIC=109.32y x1 + x3 Df Sum of Sq RSS AIC 5599.4 109.32- x3 1 833.2 6432.6 109.82- x1 1 5169.5 10768.9 119.09从程序运行结果可以看到,用全部变量作回归方程时,AIC的值为111.27,如果去掉X2,AIC的值会从降到109.3,由于去掉X2使A

7、IC得值达到最小,因此R软件自动去掉X2进行下一轮计算。#分析计算结果,调用函数summary()提取相关信息summary(lm.step)Call:lm(formula = y x1 + x3)Residuals: Min 1Q Median 3Q Max -29.713 -11.324 -2.953 11.286 48.679 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 41.4794 13.8834 2.988 0.00920 *x1 1.7374 0.4669 3.721 0.00205 *x3 0.15

8、48 0.1036 1.494 0.15592 -Signif. codes: 0 * 0.001 * 0.01 * 0.05 . 0.1 1 Residual standard error: 19.32 on 15 degrees of freedomMultiple R-squared: 0.5481, Adjusted R-squared: 0.4878 F-statistic: 9.095 on 2 and 15 DF, p-value: 0.002589从显示结果看到:变量X1和X3t检验的显著性水平仍然不理想。#用drop1()计算drop1(lm.step)Single term

9、 deletionsModel:y x1 + x3 Df Sum of Sq RSS AIC 5599.4 109.32x1 1 5169.5 10768.9 119.09x3 1 833.2 6432.6 109.82从运算结果来看,如果去掉X3,AIC的值会从109.3增加到109.8,是增加的最少的。另外,除AIC准则外,残差的平方和也是逐步回归的重要指标之一,从直观上看,拟合越好的方程,残差的平方和应该越小,去掉X3残差的平方和上升833.2也是最少的,因此应该再去掉X3。lm.opt|t|) (Intercept) 59.2590 7.4200 7.986 5.67e-07 *x1

10、1.8434 0.4789 3.849 0.00142 * -Signif. codes: 0 * 0.001 * 0.01 * 0.05 . 0.1 1 Residual standard error: 20.05 on 16 degrees of freedomMultiple R-squared: 0.4808, Adjusted R-squared: 0.4484 F-statistic: 14.82 on 1 and 16 DF, p-value: 0.001417结果理想,所有检验均是显著的。所以得到“最优”的回归方程y=59.2590+1.8434x16.3#输入数据,作线性回归

11、模型x-c(1,1,1,1,2,2,2,3,3,3,4,4,4,5,6,6,6,7,7,7,8,8,8,9,11,12,12,12)y-c(0.6,1.6,0.5,1.2,2.0,1.3,2.5,2.2,2.4,1.2,3.5,4.1,5.1,5.7,3.4, 9.7,8.6,4.0,5.5,10.5,17.5,13.4,4.5,30.4,12.4,13.4,26.2,7.4)plot(x,y)lm.sol|t|) (Intercept) -1.4519 1.8353 -0.791 0.436 x 1.5578 0.2807 5.549 7.93e-06 *-Signif. codes: 0 *

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 工作计划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号