R语言做如何做多元回归分析(逐步回归)之 提取回归结果参数-调整R方,标准化回归系数

setwd(“D:\R\myrfile”)
getwd()

–逐步回归提取回归结果参数-调整R方,标准化回归系数—-

read.table("demo.csv",header=TRUE,sep=",")->demo
demo
scale.demo<-scale(demo[,c("a1","a2","a3","a4","a5","a6","y")],center = T,scale = T)#标准化数据
scale.demo
cbind.scale.demo<-cbind.data.frame(demo[1:6],scale.demo,deparse.level = 1)#合并基本信息和标准化数据
cbind.scale.demo
lm.demo<-lm(y~a1+a2+a3+a4+a5+a6,data=cbind.scale.demo)#多元回归
summary(lm.demo)
lm.step<-step(lm.demo)#逐步回归
summary(lm.step)

提取回归R方

summary(lm.step)$r.square #提取R方

lm.step$coeff #提取首列-回归系数
lm.step$coefficients#默认提取首列回归系数
lmResults<-summary(lm.step)#将逐步回归结果赋值给a
lmResults
lmResults$r.squared#提取R方
lmResults$adj.r.squared#提取调整R方Adjusted R-squared
lmResults$fstatistic#F统计量
lmResults$
a<-summary(lm.step)$coefficients#将逐步回归结果赋值给矩阵
a

a$coeff[,1]#提取首列-回归系数
a$coefficients[,2]#提取标准误
a$coefficients[,3]#提取t值 t value
a$coefficients[,4]#提取取Pr
b<-a$coefficients
b
mode(b)#numeric
class(b)#matrix
b[,1]#提取首列-回归系数
b[,2]#提取标准误
b[,3]#提取t值 t value
b[,4]#提取Pr

你可能感兴趣的:(R语言)