R语言菜鸟练习笔记4.docx

上传人:b****5 文档编号:6791321 上传时间:2023-01-10 格式:DOCX 页数:26 大小:81.53KB
下载 相关 举报
R语言菜鸟练习笔记4.docx_第1页
第1页 / 共26页
R语言菜鸟练习笔记4.docx_第2页
第2页 / 共26页
R语言菜鸟练习笔记4.docx_第3页
第3页 / 共26页
R语言菜鸟练习笔记4.docx_第4页
第4页 / 共26页
R语言菜鸟练习笔记4.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

R语言菜鸟练习笔记4.docx

《R语言菜鸟练习笔记4.docx》由会员分享,可在线阅读,更多相关《R语言菜鸟练习笔记4.docx(26页珍藏版)》请在冰豆网上搜索。

R语言菜鸟练习笔记4.docx

R语言菜鸟练习笔记4

R语言笔记

题目1:

根据MEdata数据集的拟合结果,

预测当GDP依次为6500、7500、8500、10000、12000、15000时的TAX值

并绘制(预测TAX~GDP)散点图

代码:

>abc<-read.csv("D:

/R/MEdata.csv",header=T)

>attach(abc)

>LM<-lm(TAX~GDP)

>gdp<-c(6500,7500,8500,10000,12000,15000)

>tax<-predict(LM,data.frame(GDP=gdp))

>tax

1234

1188.3331375.4631562.5921843.286

56

2217.5452778.933

>plot(tax~gdp)

截图:

题目2:

提取1993-2013年的TAX和GDP,与刚才的TAX~GDP预测值合并

绘制合并后的(TAX~GDP)散点图

代码:

>t<-abc[16:

36,"TAX"]

>tax<-c(t,tax)

>g<-abc[16:

36,"GDP"]

>gdp<-c(g,gdp)

>plot(tax~gdp)

运行结果截图

题目3:

将DataC数据集,使用各种曲线方程进行拟合

找出其最符合哪种曲线类型,并求出其拟合方程

分析其拟合可信度

决定系数、校正决定系数

代码:

>abc<-read.csv("C:

/Users/user/Desktop/DataA-C/DataC.csv",header=T)

>data<-abc[1:

99,]

>x<-c(1:

99)

>lines(x,fitted(lmzb))

>lmpf<-lm(data~exp(x))

>lines(x,fitted(lmpf))

>lmpf<-lm(data~exp(x))

>lines(x,fitted(lmpf))

>lmlg<-lm(data~log(x))

>lines(x,fitted(lmlg))

>lm1<-lm(data~x^2)

>lines(x,fitted(lm1))

>summary(lm1)

Call:

lm(formula=data~x^2)

Residuals:

Min1QMedian3QMax

-4.1099-1.9491-0.20971.75606.6147

Coefficients:

EstimateStd.ErrortvaluePr(>|t|)

(Intercept)-5.6070230.519329-10.80<2e-16

x0.3142770.00901834.85<2e-16

(Intercept)***

x***

---

Signif.codes:

0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residualstandarderror:

2.564on97degreesoffreedom

MultipleR-squared:

0.926,AdjustedR-squared:

0.9253

F-statistic:

1215on1and97DF,p-value:

<2.2e-16

>summary(lmzb)

Call:

lm(formula=data~x)

Residuals:

Min1QMedian3QMax

-4.1099-1.9491-0.20971.75606.6147

Coefficients:

EstimateStd.ErrortvaluePr(>|t|)

(Intercept)-5.6070230.519329-10.80<2e-16

x0.3142770.00901834.85<2e-16

(Intercept)***

x***

---

Signif.codes:

0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residualstandarderror:

2.564on97degreesoffreedom

MultipleR-squared:

0.926,AdjustedR-squared:

0.9253

F-statistic:

1215on1and97DF,p-value:

<2.2e-16

>lm2<-lm(data~x^3)

>lines(x,fitted(lm2))

>summary(lm2)

Call:

lm(formula=data~x^3)

Residuals:

Min1QMedian3QMax

-4.1099-1.9491-0.20971.75606.6147

Coefficients:

EstimateStd.ErrortvaluePr(>|t|)

(Intercept)-5.6070230.519329-10.80<2e-16

x0.3142770.00901834.85<2e-16

(Intercept)***

x***

---

Signif.codes:

0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residualstandarderror:

2.564on97degreesoffreedom

MultipleR-squared:

0.926,AdjustedR-squared:

0.9253

F-statistic:

1215on1and97DF,p-value:

<2.2e-16

>lm3<-lm(data~x^4)

>lines(x,fitted(lm3))

>summary(lm3)

Call:

lm(formula=data~x^4)

Residuals:

Min1QMedian3QMax

-4.1099-1.9491-0.20971.75606.6147

Coefficients:

EstimateStd.ErrortvaluePr(>|t|)

(Intercept)-5.6070230.519329-10.80<2e-16

x0.3142770.00901834.85<2e-16

(Intercept)***

x***

---

Signif.codes:

0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residualstandarderror:

2.564on97degreesoffreedom

MultipleR-squared:

0.926,AdjustedR-squared:

0.9253

F-statistic:

1215on1and97DF,p-value:

<2.2e-16

>lm4<-lm(data~(x^2+x)

+)

>line(x~fitted(lm4))

Call:

line(x~fitted(lm4))

Coefficients:

[1]17.3463.231

>lines(x~fitted(lm4))

>summary(lm4)

Call:

lm(formula=data~(x^2+x))

Residuals:

Min1QMedian3QMax

-4.1099-1.9491-0.20971.75606.6147

Coefficients:

EstimateStd.ErrortvaluePr(>|t|)

(Intercept)-5.6070230.519329-10.80<2e-16

x0.3142770.00901834.85<2e-16

(Intercept)***

x***

---

Signif.codes:

0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residualstandarderror:

2.564on97degreesoffreedom

MultipleR-squared:

0.926,AdjustedR-squared:

0.9253

F-statistic:

1215on1and97DF,p-value:

<2.2e-16

>lm5<-lm(data~(I(x^2)))

>summary(lm5)

Call:

lm(formula=data~(I(x^2)))

Residuals:

Min1QMedian3QMax

-1.9939-0.5952-0.17670.50522.8117

Coefficients:

EstimateStd.ErrortvaluePr(>|t|)

(Intercept)-0.3321010.146471-2.2670.0256

I(x^2)0.0031470.00003395.376<2e-16

(Intercept)*

I(x^2)***

---

Signif.codes:

0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residualstandarderror:

0.9685on97degreesoffreedom

MultipleR-squared:

0.9894,AdjustedR-squared:

0.9893

F-statistic:

9097on1and97DF,p-value:

<2.2e-16

>lm6<-lm(data~x^3)

>summary(lm6)

Call:

lm(formula=data~x^3)

Residuals:

Min1QMedian3QMax

-4.1099-1.9491-0.20971.75606.6147

Coefficients:

EstimateStd.ErrortvaluePr(>|t|)

(Intercept)-5.6070230.519329-10.80<2e-16

x0.3142770.00901834.85<2e-16

(Intercept)***

x***

---

Signif.codes:

0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residualstandarderror:

2.564on97degreesoffreedom

MultipleR-squared:

0.926,AdjustedR-squared:

0.9253

F-statistic:

1215on1and97DF,p-value:

<2.2e-16

>lm7<-lm(data~I(x^3))

>lines(x,fitted(lm7))

>summary(lm7)

Call:

lm(formula=data~I(x^3))

Residuals:

Min1QMedian3QMax

-4.2920-1.35950.01251.12994.6468

Coefficients:

EstimateStd.ErrortvaluePr(>|t|)

(Intercept)1.993e+002.440e-018.171.17e-12

I(x^3)3.278e-056.537e-0750.15<2e-16

(Intercept)***

I(x^3)***

---

Signif.codes:

0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residualstandarderror:

1.817on97degreesoffreedom

MultipleR-squared:

0.9629,AdjustedR-squared:

0.9625

F-statistic:

2515on1and97DF,p-value:

<2.2e-16

>lm8(data~I(x+x^2))

Error:

couldnotfindfunction"lm8"

>lm8<-lm(data~I(x+x^2))

>lines(x,fitted(lm8))

>summary(lm8)

Call:

lm(formula=data~I(x+x^2))

Residuals:

Min1QMedian3QMax

-1.9444-0.5931-0.14100.52662.8217

Coefficients:

EstimateStd.Errortvalue

(Intercept)-3.907e-011.472e-01-2.655

I(x+x^2)3.118e-033.274e-0595.227

Pr(>|t|)

(Intercept)0.00927**

I(x+x^2)<2e-16***

---

Signif.codes:

0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residualstandarderror:

0.97on97degreesoffreedom

MultipleR-squared:

0.9894,AdjustedR-squared:

0.9893

F-statistic:

9068on1and97DF,p-value:

<2.2e-16

截图

题目4:

针对MEdata数据集

分析TAX与EXP、IE、RS、COM、INV、DEP中的哪些变量更为相关?

代码:

>xyz<-read.csv("C:

/Users/user/Desktop/MEdata.csv",header=T)

>xyz

XTAXGDPEXPIE

119785.192836.05611.22093.550

219795.378240.92612.81794.546

319805.717045.92912.28835.700

419816.298950.08811.38417.353

519827.000255.90012.29987.713

619837.755962.16214.09528.601

719849.473573.62717.010212.010

8198520.407990.76720.042520.667

9198620.9073105.08522.049125.804

10198721.4036122.77422.621830.842

11198823.9047153.88624.912138.218

12198927.2740173.11328.237841.560

13199028.2186193.47830.835955.601

14199129.9017225.77433.866272.258

15199232.9691275.65237.422091.196

16199342.5530369.38146.4230112.710

17199451.2688502.17457.9262203.819

18199560.3804632.16968.2372234.999

19199669.0982741.63679.3755241.338

20199782.3404816.58592.3356269.672

21199892.6280865.316107.9818268.497

221999106.8258911.250131.8767298.962

232000125.8151987.490158.8650392.732

242001153.01381090.280189.0258421.836

252002176.36451204.756220.5315513.782

262003200.17311366.134246.4995704.835

272004241.65681609.566284.8689955.391

282005287.78541874.234339.30281169.218

292006348.04352227.125404.22731409.740

302007456.21972665.992497.81351668.637

312008542.23793159.746625.92661799.215

322009595.21593487.751762.99931506.481

332010732.10794028.165898.74162017.222

342011897.38394726.1921092.47792364.020

3520121006.14285293.9921259.52972441.602

3620131105.30705866.7301402.12102582.529

RSCOMINVDEP

115.58617.59108.0082.1060

218.00020.11508.5652.8100

321.40023.31209.1093.9580

423.50026.27909.6105.2370

525.70029.029012.3046.7540

628.49432.311014.3018.9250

733.76437.420018.32912.1470

843.05046.874025.43216.2260

949.50053.021031.20622.3850

1058.20061.261037.91730.8140

1174.40078.681047.53838.2220

1281.01488.126044.10451.9640

1383.00194.509045.17071.1960

1494.156107.306055.94592.4490

15109.937130.001080.801117.5730

16142.704164.1210130.723152.0350

17186.229218.4420170.421215.1880

18236.138283.6970200.193296.6230

19283.602339.5590229.135385.2080

20312.529369.2150249.411462.7980

21333.781392.2930284.062534.0750

22356.479419.2040298.547596.2180

23391.057458.5460329.177643.3240

24430.554494.3590372.135737.6240

25481.359530.5660434.999869.1065

26525.163576.4980555.6661036.1731

27595.010652.1850704.7741195.5539

28671.766729.5870887.7361410.5099

29791.452825.75451099.9821615.8730

30935.716963.32501373.2391725.3419

311148.3011116.70401728.2842178.8535

321326.7841235.84622245.9882607.7166

331569.9841407.58652516.8383033.0249

341839.1861689.56633114.8513436.3589

352103.0701905.84603746.9473995.5104

362378.0992121.87504470.7444607.8504

>attach(xyz)

>lm1<-lm(TAX~GDP)

>summary(lm1)

Call:

lm(formula=TAX~GDP)

Residuals:

Min1QMedian3QMax

-42.459-29.5557.86124.98243.489

Coefficients:

EstimateStd.Errortvalue

(Intercept)-28.0072966.274253-4.464

GDP0.1871290.00306761.015

Pr(>|t|)

(Intercept)8.42e-05***

GDP<2e-16***

---

Signif.codes:

0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1

Residualstandarderror:

29.35on34degreesoffreedom

MultipleR-squared:

0.9909,AdjustedR-squared:

0.9907

F-statistic:

3723on1and34DF,p-value:

<2.2e-16

>lm2<-lm(TAX~EXP)

>summary(lm2)

Call:

lm(formula=TAX~EXP)

Residuals:

Min1QMedian3QMax

-28.316-7.063-1.0191.28951.037

Coefficients:

EstimateStd.ErrortvaluePr(>|t|)

(Intercept)4.1825862.8122521.4870.146

EXP0.8055230.006217129.574<2e-16

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 法律文书 > 调解书

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1