资源描述:
《R语言回归分析和方差分析上机》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、建立2wcgs.csv中收缩压与体重,收缩压与年龄,收缩压与体重、年龄的回归方程,进行相关估计和预测。具体处理过程:1.首先得到三种情况下的线性回归方程rm(list=ls())rd=read.csv("2wcgs.csv",head=T)str(rd)##structureofrdattach(rd)##链接rdcor(sbp,weight);cor(sbp,age)####sbp与weight;sbp与age的相关系数LinearRegressionsbp&weight:0.2532496sbp&age:0.1657464M1=lm(sbp~weight)
2、###做线性模型,其模型公式sbp~weight即sbp=β0+β1weight+ε,summary(M1)###模型的计算结果plot(sbp~weight,pch=19,main="sbp=97.78884+0.18148weight")abline(M1)##回归线Call:##列出相应的回归模型公式lm(formula=sbp~weight)Residuals:Min1QMedian3QMax-29.549-10.097-2.4567.72499.544Coefficients:EstimateStd.ErrortvaluePr(>
3、t
4、)(Inter
5、cept)97.788842.1147346.24<2e-16***weight0.181480.0123514.70<2e-16***---Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1Residualstandarderror:14.63on3152degreesoffreedomMultipleR-squared:0.06414,AdjustedR-squared:0.06384F-statistic:216on1and3152DF,p-value:<2.2e-16从检验结果可以看出回归方程通过了回归参数
6、的检验和回归方程的检验。M2=lm(sbp~age)summary(M2)plot(sbp~age);abline(M2)boxplot(sbp~age,ylab="sbp")Call:lm(formula=sbp~age)Residuals:Min1QMedian3QMax-33.042-10.053-2.3628.133101.040Coefficients:EstimateStd.ErrortvaluePr(>
7、t
8、)(Intercept)107.640812.2404748.044<2e-16***age0.453600.048079.436<2e-1
9、6***---Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1Residualstandarderror:14.91on3152degreesoffreedomMultipleR-squared:0.02747,AdjustedR-squared:0.02716F-statistic:89.04on1and3152DF,p-value:<2.2e-16M3=lm(sbp~weight+age)summary(M3)Call:lm(formula=sbp~weight+age)Residuals:Min1QMedi
10、an3QMax-33.553-9.917-2.1337.46599.156Coefficients:EstimateStd.ErrortvaluePr(>
11、t
12、)(Intercept)74.935223.0418324.64<2e-16***weight0.185790.0121515.29<2e-16***age0.478010.0464210.30<2e-16***---Signif.codes:0‘***’0.001‘**’0.01‘*’0.05‘.’0.1‘’1Residualstandarderror:14.39on3151degreesoffree
13、domMultipleR-squared:0.09461,AdjustedR-squared:0.09403F-statistic:164.6on2and3151DF,p-value:<2.2e-16M1回归方程:sbp=97.78884+0.18148weightM2回归方程:sbp=107.64081+0.45360ageM3回归方程:sbp=74.93522+0.18579weight+0.47801age2.残差分析par(mfrow=c(2,2),pch=19)plot(M1,which=1)plot(M1,which=2)plot(M2,which
14、=1)plot(M2,which=2)