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 1 2 3 4 1188.333 1375.463 1562.592 1843.286 5 6 2217.545 2778.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: Min 1Q Median 3Q Max -4.1099 -1.9491 -0.2097 1.7560 6.6147 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -5.607023 0.519329 -10.80 2e-16 x 0.314277 0.009018 34.85 2e-16 (Intercept) *** x *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 2.564 on 97 degrees of freedom Multiple R-squared: 0.926, Adjusted R-squared: 0.9253 F-statistic: 1215 on 1 and 97 DF, p-value: 2.2e-16 summary(lmzb) Call: lm(formula = data ~ x) Residuals: Min 1Q Median 3Q Max -4.1099 -1.9491 -0.2097 1.7560 6.6147 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -5.607023 0.519329 -10.80 2e-16 x 0.314277 0.009018 34.85 2e-16 (Intercept) *** x *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 2.564 on 97 degrees of freedom Multiple R-squared: 0.9

文档评论(0)

1亿VIP精品文档

相关文档