R应用-多元线性回归
来源:互联网 发布:蚌埠巨人网络 编辑:程序博客网 时间:2024/05/16 16:19
#准备好数据,看看pv与uv、cindex、hsindex之间的关系 pv uv cindex hsindex
pv uv cindex hsindex
Min 1Q Median 3Q Max
Estimate Std. Error t value Pr(>|t|)
f<-c[,c(-3,-5)]
head(f)
1 5531 3279 1458 2296
2 6439 4070 1425 2280
3 5404 3253 1477 2291
4 6121 4137 1458 2286
5 6654 4532 1473 2268
6 6226 4266 1446 2212
#检测二变量关系
cor(f)
pv 1.0000 0.6094186 -0.2195932 0.6523
uv 0.6094 1.0000000 0.0002991 0.3587
cindex -0.2196 0.0002991 1.0000000 -0.6506
hsindex 0.6523 0.3586755 -0.6505730 1.0000
#绘制因变量与自变量的散点图矩阵
library(car)
scatterplotMatrix(f,spread=F,lty.smooth=2,main="scatter plot matrix")
#大多数预测变量都一定程度上出现了偏斜,pv随着uv的上升而上升,pv随着cindex的下降而下降,pv随着hsindex的上升而上升。
#拟合多元线性回归模型
lmpv1<-lm(pv~uv+cindex+hsindex,data=f)
summary(lmpv1)
Call:
lm(formula = pv ~ uv + cindex + hsindex, data = f)
Residuals:
-2315.3 -463.6 43.5 466.1 2863.6
Coefficients:
(Intercept) -2.04e+04 5.44e+03 -3.76 0.00042 ***
uv 4.80e-01 1.22e-01 3.93 0.00024 ***
cindex 2.71e+00 1.58e+00 1.72 0.09090 .
hsindex 8.90e+00 1.73e+00 5.15 3.7e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 809 on 55 degrees of freedom
Multiple R-squared: 0.608, Adjusted R-squared: 0.587
F-statistic: 28.5 on 3 and 55 DF, p-value: 3.01e-11
#所有的预测变量解释了pv 60.8%的方差
#选择最佳的回归模型
全子集回归,即所有可能的模型都被评价了。
#基于调整R平方,不同子集大小的三个最佳模型
library(leaps)leaps<-regsubsets(pv~uv+cindex+hsindex,data=f,nbest=3)
plot(leaps,scale="adjr2")
含uv、cindex、hsindex的模型调整R平方值为0.59最高,三预测变量模型是最佳模型。
#基于Mallows Cp统计量,不同子集大小的三个最佳模型
library(car)
subsets(leaps,statistic="cp",main="cp plot for all subsets regression")
abline(1,1,lty=2,col="red")#画截距项和斜率均为1的直线
#越好的模型离截距项和斜率均为1的直线越近——即u-c-h三预测变量模型lm(pv~uv+cindex+hsindex,data=f)
0 0
- R应用-多元线性回归
- R多元线性回归
- R语言多元线性回归
- R语言多元线性回归
- R语言多元线性回归
- R语言多元线性回归
- 7.4 多元线性回归应用
- 利用R进行多元线性回归分析
- R语言多元线性回归分析
- 多元线性回归和Python应用举例
- 回归:多元线性回归
- R语言:多元线性回归和模型检验
- 用R进行多元线性回归分析建模
- 如何用R实现多元线性回归分析
- 用多元线性回归预测网页访问量(R语言)
- R语言如何做多元线性回归?以例子说明?
- 关于多元线性回归
- 多元线性回归分析
- Android快速开发之设计通用的ListView,GridView的适配器
- 自动朗读(TTS)
- No mapping found for HTTP request with URI [/operation-platform/js/displaytag.js] in DispatcherServl
- 圆形背景TextView
- Visual Studio 2013 Professional Key
- R应用-多元线性回归
- 考取PMP的价值何在?
- java设计模式之代理模式
- JAVA 对象拷贝
- Behavior of Active Dataguard(ADG) When Apply Node Aborts/Crash (文档 ID 1613719.1)
- Java Web---HTTP应用层协议
- Spring Tool Suite
- (转)URI和URL及URN的区别
- python做考勤统计