R语言代码试题答案步骤_第1页
R语言代码试题答案步骤_第2页
R语言代码试题答案步骤_第3页
R语言代码试题答案步骤_第4页
R语言代码试题答案步骤_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、R version 3.4.3 (2017-11-30) - Kite -Eating TreeCopyright (C) 2017 The R Foundation for Statistical Computing Platform: x86_64 -w64-mingw32/x64 (64 -bit)R 是自由软件,不带任何担保。 在某些条件下你可以将其自由散布。用lice nse()或lice nce()来看散布的详细条件。R 是个合作计划,有许多人为之做出了贡献 .用 contributors() 来看合作者的详细情况用 citation() 会告诉你如何在出版物中正确地引用R 或 R

2、 程序包。用demo()来看一些示范程序,用help。来阅读在线帮助文件,或用help.start()通过HTML浏览器来看帮助文件。用 q() 退出 R.原来保存的工作空间已还原h=read.csv(F:/1.csv,header=true)Error in read.table(file = file, header = header, sep = sep, quote = quote, :找不到对象 trueh=read.csv(F:/1.csv,header=TRUE)h地区 x1 x2 x3 x4 x5 x6 x7 x8 x9 y 1 北京 7535 2639 1971 1658 3

3、696 84742 87475 106.5 1.3 24046天津 7344 1881 1854 1556 2254 61514 93173 107.5 3.6 20024河北 4211 1542 1502 1047 1204 38658 36584 104.1 3.7 12531山西 3856 1529 1439 906 1506 44236 33628 108.8 3.3 12212内蒙古 5463 2730 1584 1354 1972 46557 63886 109.6 3.7 17717辽宁 5809 2042 1433 1310 1844 41858 56649 107.7 3.6

4、 16594吉林 4635 2045 1594 1448 1643 38407 43415 111.0 3.7 14614黑龙江 4687 1807 1337 1181 1217 36406 35711 104.8 4.2 12984上海 9656 2111 1790 1017 3724 78673 85373 106.0 3.1 26253江苏6658 1916 1437 1058 3078 50639 68347 112.6 3.1 18825浙江7552 2110 1552 1228 2997 50197 63374 104.5 3.0 21545安徽5815 1541 1397 114

5、3 1933 44601 28792 105.3 3.7 15012福建7317 1634 1754 773 2105 44525 52763 104.6 3.6 18593江西5072 1477 1174 671 1487 38512 28800 106.7 3.0 12776山东5201 2197 1572 1005 1656 41904 51768 106.9 3.3 15778河南4607 1886 1191 1085 1525 37338 31499 106.8 3.1 13733湖北5838 1783 1371 1030 1652 39846 38572 105.6 3.8 144

6、96湖南5442 1625 1302 918 1738 38971 33480 105.7 4.2 1460919广东8258 1521 2100 1048 2954 50278 54095 107.9 2.5 22396广西555311461377 884 1626 36386 27952 107.5 3.4 14244海南6556865 1521 993 1320 39485 32377 107.02.0 14457四川607416511284773 1587 42339 29608105.9 4.0 15050贵州499313991014655 1396 41156 19710105.5

7、 3.3 12586云南 5468 仃60974 939 1434 37629 22195 108.9 4.0 13884西藏 5518 1362845 467 550 51705 22936 109.5 2.6 11184重庆687022291177 1102 1471 44498 38914107.83.3 16573陕西555117891322 1212 2079 43073 38564109.43.2 15333甘肃460216311288 1050 1388 37679 21978108.62.7 12847青海 4667 1512 1232 906 1097 46483 33181

8、 110.6 3.4 12346宁夏476918761193 1063 1516 47436 36394105.54.2 14067新疆523920311167 1028 1281 44576 33796114.83.4 13892 Im=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)Coefficie nts:(In tercept)x1x2x3x4x5x6x7 x8x9320.6409481.3165881.6

9、498592.178660-0.0056091.6842830.010320 0.003655 -19.130576 50.515575 summary(lm)Call:lm(formula = y x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9, data = h)Residuals:Min 1Q Media n 3Q Max -940.13 -195.24 3.42 239.00 476.06Coefficie nts:Estimate Std. Error t value Pr(|t|)(In tercept) x1x2x3x4x5x600003.2

10、06e+02 31.317e+01.650e+02.179e+0-5.609e -031.684e+01.032e-02.952e+031.062e-0 13.008e-015.199e-014.766e-012.142e-0 11.343e-00.081 0.93609712.400 3.97e-115.484 1.93e-05 *4.190 0.000412-0.012 0.9907207.864 1.08e-07 *0.769 0.450665x73.655e-031.070e-020.342 0.736006x8-1.913e+013.197e+01-0.598 0.555983x95

11、.052e+011.502e+020.3360.739986Signif. codes: 0 *0.001 * 0.01 * 0.050.1 1Residual sta ndard error: 389.4 on 21 degrees of freedomMultiple R -squared: 0.9923,Adjusted R-squared: 0.9889F-statistic: 298.9 on 9 and 21 DF, p-value: pre=fitted.values(lm)res=residuals(lm)sd(res)1 325.7967res=residuals(lm) d

12、y=step(lm)Start: AIC=377.73y x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9Df Sum of SqRSS AIC-x41213184326 375.73-x91171493201454 375.90-x71177003202005 375.90-x81542953238599 376.26-x61895863273891 376.59377.73-x312662595846898 394.573 456105-x2167745361 403.29-x519377500 12561805 418.28-x1123314547 2

13、6498852 441.42Step: AIC=375.73y x1+ x2 + x3 + x5 + x6 + x7 + x8 + x9Df Sum of SqRSS AIC-x91174283201754 373.90-x71185633202889 373.91-x81544373238763 374.26-x61918133276139 374.61375.73293613-x316120456 393.990 546794-x218652267 404.72-x519393345 12577671 416.32-x1 1 25886086 29070412 442.29Step: AI

14、C=373.9y x1 + x2 + x3 + x5 + x6 + x7 + x8Df Sum of SqRSS AIC-x71346343236387 372.24-x61748003276554 372.62-x81821503283904 372.69vnone320175430553533 5725836373.90-x316257107 392.67-x218927590 403.69-x519382624 12584378 414.33-x1125868832 29070586 440.29Step: AIC=372.24y x1 + x2 + x3 + x5 + x6 + x8D

15、f Sum of SqRSS AIC-x81708133307201 370.91-x611527773389165 371.67vnone3236387-x31550128372.2448737672 401.02-x218895049 12131436 411.20-x519458098 12694485 412.60-x1127733098 30969486 440.25Step: AIC=370.91 y x1 + x2 + x3 + x5 + x6Df Sum of Sq-x6 vnone1137540RSS AIC3444741370.173307201 370.91-x3-x2-

16、x5-x113 5771069078264 400.2113 88711912178394 409.323 9473521, 94735212780722 410.811128248162 31555363 438.83Step: AIC=370.17 y x1 + x2 + x3 + x5Df Sum of SqRSS AICvnone3444741 370.17-x35717883 9162624 398.50 x2x5x110249815 13694556410998313 1444305443325*8637 36703378 summary#)52Call:lm(formula =

17、y x1 + x2 + x3 + x5, data = h)MinResiduals:-943.18 -161.051Q Media n12.74250.933Q566.25MaxSig n if. codes: 0 (In tercept) -1694.6269x1x2x3x51.36420.08615.844 7.11e-15 *1.76791 0.20108.796*2.86e-090.3486.5695.76e-072.28945*1.74240.19129.1111.42e-09Coefficie nts:Estimate Std. Error t value Pr(|t|)0.10

18、.001 * 0.01 * 0.05562.9773-3.0100.00574 *Residual sta n dard error: 364 on 26 degrees offfeedomMultiple R -squared: 0.9916, Adjusted R-squared: 0.9903F-statistic: 769.2 on 4 and 26 DF, p-value: n ewdata=data.frame(x 仁5200,x2=2000,x3=1100,x4=1000,x5=1300,x6=45000,x7=34000,x8=115.0 ,x9=3.8)predict(dy

19、,n ewdata,i n terval=c on fide n ee)fitlwrupr1 13718.67 13468.98 13968.361、乘杵俣羞项,模空堆式为y=AKaLfiec対:ft性i灵北顷,Bt型可通过两边垠炖数转化成城世稅型In y = In A In K + /?ln L + f=lny,=哥=ln心=1仇则转化为线性回0方程以卜我们用线性化的乘杵误无额枝里拟合C-D牛产用数? y-|36243962.9 4124.2 4330.6 46235()8().2 5977.3 68363 7305.4 7983.2 8385.9 8049.79653.5 11179.9

20、12673.0 13786.9 14724.3 15782.8 16840.6 17861.6 18975.9 20604.7 22256.0 242470T :? K= 1377.9 1446.7 1451 5 1408.1 1536.9 1716.4 2057.7 2582.2 2754.0 2884.3 3086.8 2901.53356.8 4044.2 5487.9 5679.0 6012.0 6246.5 6436.0 67367098.9 7510.5 85673 V764.9J ;? L=|4OI52 41024 42361 43725 45295 46436 48197 49

21、873 51282 52783 54334 55329 6474965491 66152 668()8 67455 68065 68950 69820 7()637 71394 72085 73025 73740f;? y 卜 log(y);? x1=kig(K);? x2=log(L);? x=(o nes(25J) xl x2J;?b.bi nt.r.ri nhstats二rcgrcss(ykx;? b,b in t.stats,rcoplot(r,ri nt)b =-1.78540.80110.4016bint =-4.76871.19780.6X550.91670.04780.7554

22、stats = 1.0c ? 003 玄0.00101.8055exp(-1.7854)ans =0.1677? y-136243962 9 4124.2 4330.6 4623.1 5080.2 5977.3 6836.3 7305.4 7983.2 8385.9 8049.785643 9653.5 11179.9 12673.0 13786.9 14724.3 15782.8 16840.6 17861.6 18975.9 20604.722256.0 24247.0:? yl=-1.785440.8011 妆 1+0.4016X2;? y2 二 cxp(yl):? c=y? y2().

23、25020.1X390.1X16().2274(Kl3 *-0俪0(-0.10也 6690.33640.CM6I -0.13450.0283-0.039-1.7H7-1.0550-0.8671-037750.20510.5268(J.81956 536参数参数估计值参数的置倍区间A-1.7854476879780.95590.5003)1a0.801110.6855,0.91670.40160.()478,0.75541R2 = 1.0000F = 1 805.5p = 0.0000得两个弹性系数为a 0.8011 ? “-0. 4016,资金的贡献率大于劳动者的贡献率t规模报酬U + 0 二

24、 1? 20271表示规模报酬递增,效率系数A二f ?加二0? 1677c其中系数的显苦性概 =0.1677A(HGl书 P 位二()()()()?0.4016显著忤较強.得乘性误年项的(T)牛产困数为2、加性误差项,模型形式为y二AKZ?+ 对加性误差项模型,不能通过变量变换转化成线性模型面乘性谋差项的参数为初值做非线性最小二乘首先编写一个M文件Huaxuel.m.只能用非线性最小一乘求解未知参数。以上fun cti on yhat二huaxuel (beta,x) bl=beta( 1 );b2=bcta(2);b3=beta(3);xl=x(:):x2 二 x(: ? 2);yhat-b

25、 1*(x1 Ab2)*(x2 Ab3)然后在MATI AB命令窗输入:? xl =1377.9 1446.7 1451 5 1408.1 1536.9 1716.4 2057.7 2582.2 2754.0 2884.3 3086.8 2QO1.53356.8 4044.2 5487.9 5679.0 60120 6246.5 6436.0 67367098.9 7510.5 8567.3 9764.9;? x2-4O152 41024 42361 43725 45295 46436 48197 49873 51282 52783 54334 55329 64749 65491 661526

26、68()8 67455 68()65 68950 69820 70637 71394 72085 73025 7374():? y-3624.1 3962.9 4124.2 4330.6 46235080.2 5977.3 6836.3 7305.4 7983.2 8385.9 8049.7 85643 9653.511179.9 12073.0 13786.9 14724.3 15782.8 16840.6 17861.6 18975.9 20604.7 22256.0 24247.0;? x=xl x2;? beta 二卜 1.7X54 0.8011 ().4016J;? |bctahat

27、.fj|-nlin fit(x.y/huaxuelbcta);DW检验第一步:计算出回归估计式的残差 cr第二步:定义DW统计星为DW二 (勺勺-|)2,其中v =V,-人(t=l,2, .,n) aI)W y (-p )? ci=l.0c+(X)3C|-(X25IO-0.1014紡?()? (X)37().2502().18390.18160.22740.1560-0.14000.16690.03640.04610.13450.02830.0396-1.71171.05500.8671-0.37750.20510.52680.81951.53610.9559;? ej=l?0e+003 *-

28、0.1014-0.00370.18390.25020.18160.2274-0.1560-0.14000.16690.03640.0461-0.13450.0283-0.0396.1.7117-1.0550-0.8671?0.37750.20510.52680.81951.53610.9559认为与工近似相等.得 l)W V 2 I 一 -e2r?2InnL r=2L e:/=2O.5DO3I ;?sca ncr(ei,cj)sum(ei *ej)/sum(ei. A2) ans =0.72122*( I -sum(ei.*ej)/sum(ei. a2)an0.5576? sum( (ei-e

29、j).八2)/sum(ei. A2)ans =0.5772H杳农得出:当 n=25, k=2时,血=1.29,血=1.45即有OWDM二0.5772S仏=1.29,可以认为误荃顶存在 iE 口相关 .h=ts(read.csv(F:/3.csv,header=TRUE)hTime Series:Start = 1End = 56Freque ncy = 1X781,-582,3,3-634,5,-66,-167,-148,9,10-74-48 -1416-86 -662o-47-1062223425 62728-83-1 124113-76 -473o由1-323435,36,-2437,23

30、8,33839,940,*641,-5842,143,144,4 -45,4 746,71247,7 948,7 149,0-2850,-1751,252,3 -53,2 454,81355,1 656,5 -17 plot(h,type=o)K R Srapliicv Clever 2 (A 牙!VE|= |bd世local(pkg summary(adf)II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II II

31、 II II II II II II IIa a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a# Augme nted Dickey -Fuller Test Unit Root Test #a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a

32、 a a a a a a a a a a a a a a a a a a a a a a a a aTest regressi on driftCall:lm(formula = z. diff z. lag.1 + 1 + z. diff.lag)Residuals:Min 1Q Media n 3Q Max-96.191 -23.390 -0.581 18.446 133.241Coefficie nts:(In tercept)-9.43817.0489-1.3390.187乙 lag.1-1.78370.2386-7.476 9.65e-10 *z. diff.lag0.19560.1

33、3791.4180.162Sig nif. codes:0 * 0.001c* 0.01 * 0.05Estimate Std. Error t value Pr(|t|).0.1Residual sta ndard error: 50.89 on 51 degrees of freedomMultiple R -squared: 0.7589,Adjusted R-squared: 0.7494F-statistic: 80.25 on 2 and 51 DF, p-value: acf(h)X7flM A0 co 匹f(h)Series hJ 4oo oMlJrir Fr15L 9ar=s

34、arima(h,1,0,4,details=F)ar$fitCall:stats:arima(x = xdata, order = c(p, d, q), seas onal = list(order = c(P , D,Q), period = S), xreg = xmea n, in clude.mea n = FALSE, optim.c on trol = list(trace = trc, REPORT =1, reltol = tol)Coefficie nts:ar1mama2ma3ma4xmea-0.09571-0.7605-0.051-0.25910.0706n-5.088

35、6s.e0.73180.72440.6370.2010.19390.42523sigma A2 estimated as 1850:log likelihood = -291.97, aic = 597.95$degrees_of_freedom1 50 $ttableEstimateSE t.value p.valuear1-0.0957 0.7318-0.13080.8965ma1-0.7605-1.0490.298ma2ma30.7035108 -0.0808 0.936輕910 -1.28750.203ma4。皱张50.36418 0.71xmea0.琥88611.9668730.0000n0.4252$AIC1 8.73734$AICc1 8.814721$BIC1 7.954342ma=sarima(h,0,1,1,details=F)ma$fitCall:stats:arima(x = xdata, order = c(p, d, q), seas onal = list(order = c(P, D, Q), period = S), xreg = constant, optim.control = list(trace = trc, REPORT = 1, reltol = tol)Coefficie nts

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论