登录
首页精彩阅读多重线性回归及其R实现
多重线性回归及其R实现
2020-08-24
收藏

作者: 丁点helper

来源: 丁点帮你


今天我们来讲讲多重线性回归及其R实现,希望能给大家更多的灵感,从而很深入的明白多重线性回归


#各变量之间的相关系数(保留3位小数)round(cor(mydata),3)#在同一张图中展示各变量的直方图,各变量间的散点图、相关系数及其假设检验结果library(PerformanceAnalytics)chart.Correlation(mydata, histogram=TRUE, pch=19,method = 'spearman')#拟合模型model<- lm(y ~ x1 +x2 +x3 , data=mydata)summary(model)#回归诊断#fitted vs. residuals; normal Q-Qplot(model)#plot of fitted vs. studentized residuals plot(rstudent(model) ~ model$fitted.values, xlab="Fitted Values",  ylab = "Studentized Residuals",main="Fitted vs. Studentized Residuals") abline(h=0, lwd=3) abline(h=c(3,-3), lty=2, lwd=3, col="blue")#Make a plot of Cook's distances vs. observation orderlibrary(olsrr)ols_plot_cooksd_chart(model)#VIFlibrary(car)vif(fit)
#标准化数据zmydata <- as.data.frame(scale(mydata))#拟合、查看模型zmodel <- lm(y~x1 + x2 + x3 , data=zmydata)summary(zmodel)

参考文献:

Stock J, Watson M. Introduction to Econometrics (3rd edition). Addison Wesley Longman; 2011.

李晓松. 卫生统计学 (第8版).人民卫生出版社;2017.

数据分析咨询请扫描二维码

客服在线
立即咨询