1、R语言代码试题答案步骤R version (2017-11-30) - Kite-Eating TreeCopyright (C) 2017 The R Foundation for Statistical ComputingPlatform: x86_64-w64-mingw32/x64 (64-bit)R是自由软件,不带任何担保。在某些条件下你可以将其自由散布。用license()或licence()来看散布的详细条件。R是个合作计划,有许多人为之做出了贡献.!用contributors()来看合作者的详细情况用citation()会告诉你如何在出版物中正确地引用R或R程序包。用demo(
2、)来看一些示范程序,用help()来阅读在线帮助文件,或用()通过HTML浏览器来看帮助文件。用q()退出R.原来保存的工作空间已还原 h=(,header=true).Error in (file = file, header = header, sep = sep, quote = quote, : 找不到对象true h=(,header=TRUE) h 地区 x1 x2 x3 x4 x5 x6 x7 x8 x9 y1 北京 7535 2639 1971 1658 3696 84742 87475 240462 天津 7344 1881 1854 1556 2254 61514 9317
3、3 200243 河北 4211 1542 1502 1047 1204 38658 36584 125314 山西 3856 1529 1439 906 1506 44236 33628 122125 内蒙古 5463 2730 1584 1354 1972 46557 63886 17717|6 辽宁 5809 2042 1433 1310 1844 41858 56649 165947 吉林 4635 2045 1594 1448 1643 38407 43415 146148 黑龙江 4687 1807 1337 1181 1217 36406 35711 129849 上海 9656
4、 2111 1790 1017 3724 78673 85373 2625310 江苏 6658 1916 1437 1058 3078 50639 68347 1882511 浙江 7552 2110 1552 1228 2997 50197 63374 2154512 安徽 5815 1541 1397 1143 1933 44601 28792 1501213 福建 7317 1634 1754 773 2105 44525 52763 1859314 江西 5072 1477 1174 671 1487 38512 28800 1277615 山东 5201 2197 1572 100
5、5 1656 41904 51768 15778-16 河南 4607 1886 1191 1085 1525 37338 31499 1373317 湖北 5838 1783 1371 1030 1652 39846 38572 1449618 湖南 5442 1625 1302 918 1738 38971 33480 1460919 广东 8258 1521 2100 1048 2954 50278 54095 2239620 广西 5553 1146 1377 884 1626 36386 27952 1424421 海南 6556 865 1521 993 1320 39485 32
6、377 1445722 重庆 6870 2229 1177 1102 1471 44498 38914 1657323 四川 6074 1651 1284 773 1587 42339 29608 1505024 贵州 4993 1399 1014 655 1396 41156 19710 1258625 云南 5468 1760 974 939 1434 37629 22195 13884!26 西藏 5518 1362 845 467 550 51705 22936 1118427 陕西 5551 1789 1322 1212 2079 43073 38564 1533328 甘肃 460
7、2 1631 1288 1050 1388 37679 21978 1284729 青海 4667 1512 1232 906 1097 46483 33181 1234630 宁夏 4769 1876 1193 1063 1516 47436 36394 1406731 新疆 5239 2031 1167 1028 1281 44576 33796 13892 lm=lm(yx1+x2+x3+x4+x5+x6+x7+x8+x9,data=h) lmCall::lm(formula = y x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9, data = h
8、)Coefficients:(Intercept) x1 x2 x3 x4 x5 x6 x7 x8 x9 summary(lm)Call:。lm(formula = y x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9, data = h)Residuals: Min 1Q Median 3Q Max Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) +02 +03 x1 +00 *x2 +00 *x3 +00 *x4 x5 +00 *x6 x7 x8 +01 +01 x9 +01 +
9、02 -。Signif. codes: 0 * * * . 1Residual standard error: on 21 degrees of freedomMultiple R-squared: , Adjusted R-squared: F-statistic: on 9 and 21 DF, p-value: pre=(lm) res=residuals(lm) sd(res)1 。 res=residuals(lm) dy=step(lm)Start: AIC=y x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 Df Sum of Sq RSS
10、AIC- x4 1 21 3184326 - x9 1 17149 3201454 - x7 1 17700 3202005 ;- x8 1 54295 3238599 - x6 1 89586 3273891 3184305 - x3 1 2662593 5846898 - x2 1 4561056 7745361 - x5 1 9377500 - x1 1 Step: AIC=y x1 + x2 + x3 + x5 + x6 + x7 + x8 + x9 Df Sum of Sq RSS AIC- x9 1 17428 3201754 - x7 1 18563 3202889 - x8 1
11、 54437 3238763 - x6 1 91813 3276139 3184326 - x3 1 2936130 6120456 - x2 1 5467941 8652267 - x5 1 9393345 |- x1 1 Step: AIC=y x1 + x2 + x3 + x5 + x6 + x7 + x8 Df Sum of Sq RSS AIC- x7 1 34634 3236387 - x6 1 74800 3276554 - x8 1 82150 3283904 3201754 $- x3 1 3055353 6257107 - x2 1 5725836 8927590 - x5
12、 1 9382624 - x1 1 Step: AIC=y x1 + x2 + x3 + x5 + x6 + x8 Df Sum of Sq RSS AIC- x8 1 70813 3307201 - x6 1 152777 3389165 3236387 - x3 1 5501284 8737672 - x2 1 8895049 - x5 1 9458098 - x1 1 Step: AIC=y x1 + x2 + x3 + x5 + x6 Df Sum of Sq RSS AIC- x6 1 137540 3444741 3307201 - x3 1 5771063 9078264 - x
13、2 1 8871193 - x5 1 9473521 - x1 1 Step: AIC=y x1 + x2 + x3 + x5 Df Sum of Sq RSS AIC 3444741 - x3 1 5717883 9162624 - x2 1 - x5 1 - x1 1 summary(dy)Call:lm(formula = y x1 + x2 + x3 + x5, data = h)Residuals: Min 1Q Median 3Q Max Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) * x1 *)x2
14、*x3 *x5 *-Signif. codes: 0 * * * . 1Residual standard error: 364 on 26 degrees of freedomMultiple R-squared: , Adjusted R-squared: F-statistic: on 4 and 26 DF, p-value: newdata=(x1=5200,x2=2000,x3=1100,x4=1000,x5=1300,x6=45000,x7=34000,x8=,x9= predict(dy,newdata,interval=confidence) fit lwr upr1 h=t
15、s(,header=TRUE) hTime Series:Start = 1 .End = 56 Frequency = 1 X78 1, -58 2, 53 3, -63 4, 13 5, -6 6, -16 7, -14; 8, 3 9, -7410, 8911, -4812, -1413, 3214, 5615, -8616, -6617, 50:18, 2619, 5920, -4721, -8322, 223, -124, 12425, -10626, 11327, -76&28, -4729, -3230, 3931, -3032, 633, -7334, 1835, 236, -
16、2437, 23 plot(h,type=o): local(pkg adf=(h),type=c(drift),selectlags=c(AIC) summary(adf)# )# Augmented Dickey-Fuller Test Unit Root Test # # Test regression drift Call:lm(formula = + 1 + Min 1Q Median 3Q Max Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) * -Signif. codes: 0 * * * . 1Re
17、sidual standard error: on 51 degrees of freedomMultiple R-squared: , Adjusted R-squared: F-statistic: on 2 and 51 DF, p-value: acf(h) pacf(h) ar=sarima(h,1,0,4,details=F) ar$fitCall:stats:arima(x = xdata, order = c(p, d, q), seasonal = list(order = c(P, D, Q), period = S), xreg = xmean, = FALSE, = l
18、ist(trace = trc, REPORT = 1, reltol = tol)Coefficients: ar1 ma1 ma2 ma3 ma4 xmean . sigma2 estimated as 1850: log likelihood = , aic = 、$degrees_of_freedom1 50$ttable Estimate SE ar1 ma1 ma2 ma3 ma4 xmean $AIC1 $AICc1 $BIC1 ma=sarima(h,0,1,1,details=F) ma$fitCall:stats:arima(x = xdata, order = c(p,
19、d, q), seasonal = list(order = c(P, D, Q), period = S), xreg = constant, = list(trace = trc, REPORT = 1, reltol = tol)Coefficients: ma1 constant . sigma2 estimated as 3412: log likelihood = , aic = $degrees_of_freedom1 53、$ttable Estimate SE ma1 constant $AIC1 $AICc1 $BIC1 arma=sarima(h,1,1,1,detail
20、s=F) arma$fitCall:stats:arima(x = xdata, order = c(p, d, q), seasonal = list(order = c(P, D, Q), period = S), xreg = constant, = list(trace = trc, REPORT = 1, reltol = tol)Coefficients: ar1 ma1 constant . sigma2 estimated as 2548: log likelihood = , aic = $degrees_of_freedom1 52$ttable Estimate SE a
21、r1 ma1 constant $AIC|1 $AICc1 $BIC1 res=residuals(ar$fit) (res) Box-Pierce testdata: resX-squared = , df = 1, p-value = plot(res*res) res resTime Series:Start = 1 End = 56 Frequency = 1 1 +01 +01 +01 +00 +00 +00 +01 +01 +02 +01 +00 +01 +01 +01 +0117 +01 +01 +01 +01 +01 +00 +00 +02 +02 +02 +01 +01 +01 +01 +01 +0133 +01 +01 +00 +01 +01 +01 +01 +01 +01 +00 +01 +01 +02 +02 +0149 +01 +01 +01 +01 +02 +01 +01 (res)# Box-Pierce testdata: resX-squared = , df = 1, p-value = yc=(h,10,1,1,1) yc$predTime Series:Start = 57 End = 66 Frequency = 1 1
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1