sbp&weight:&age:=lm(sbp~weight)###做线性模型,其模型公式sbp~weight即sbp=β0+β1weight+ε,summary(M1)###模型的计算结果plot(sbp~weight,pch=19,main="sbp=+")abline(M1)##回归线Call:##列出相应的回归模型公式lm(formula=sbp~weight)Residuals:Min1QMedian3QMax---:(>|t|)(Intercept)<2e-16***<2e-16***---:0‘***’‘**’‘*’‘.’‘’1Residualstandarderror:-squared:,AdjustedR-squared:-statistic:216on1and3152DF,p-value:<-16从检验结果可以看出回归方程通过了回归参数的检验和回归方程的检验。M2=lm(sbp~age)summary(M2)plot(sbp~age);abline(M2)boxplot(sbp~age,ylab="sbp")Call:lm(formula=sbp~age)Residuals:Min1QMedian3QMax---:(>|t|)(Intercept)<2e-16***<2e-16***---:0‘***’‘**’‘*’‘.’‘’1Residualstandarderror:-squared:,AdjustedR-squared:-statistic:,p-value:<-16M3=lm(sbp~weight+age)summary(M3)Call:lm(formula=sbp~weight+age)Residuals:Min1QMedian3QMax---:(>|t|)(Intercept)<2e-16***<2e-16***<2e-16***---:0‘***’‘**’‘*’‘.’‘’1Residualstandarderror:-squared:,AdjustedR-squared:-statistic:,p-value:<-16M1回归方程:sbp=+:sbp=+:sbp=++(mfrow=c(2,2),pch=19)plot(M1,which=1)plot(M1,which=2)plot(M2,which=1)plot(M2,which=2)
R语言回归分析和方差分析上机 来自淘豆网m.daumloan.com转载请标明出处.