回归诊断的r语言代码
来源:互联网 发布:如何查询别人淘宝id 编辑:程序博客网 时间:2024/05/29 21:33
shuju<-data.frame(x=c(825,215,1070,550,480,920,1350,325,670,1215),y=c(3.5,1,4,2,1,3,4.5,1.5,3,5))
shuju.reg<-lm(y~x)
#方差齐性检验
#1.残差图
shuju.res<-residuals(shuju.reg)
par(mfrow=c(1,1)) #设置画图为1*1的格式
plot(shuju.res~x) #按照书上作以X为横坐标的残差图
#2.Spearman等级相关系数
cor.test(x,abs(shuju.res),method="spearman")
#3.ncvTest
library(car)
ncvTest(shuju.reg)
#4.spreadLevelPlot
library(car)
spreadLevelPlot(shuju.reg)
#5.gvlma综合诊断
#install.packages("gvlma")
library(gvlma)
gvlma(shuju.reg)
#自相关性
#图形诊断自相关性
shuju.res1<-shuju.res[1:length(shuju.res)-1]
shuju.res2<-shuju.res[2:length(shuju.res)]
plot(shuju.res1,shuju.res2) #e(t)与e(t-1)作图
#统计量诊断自相关性
library(car)
durbinWatsonTest(shuju.reg)
#异常值与强影响点
#残差
shuju.stdres<-rstudent(shuju.reg);shuju.stdres
#中心化杠杆值
ch<-hatvalues(shuju.reg)-1/10;ch
#Cook距离
shuju.cooks<-cooks.distance(shuju.reg);shuju.cooks
#找异常值
isoutlier<-abs(shuju.stdres3)>3;isoutlier
isch<-ch>2*1/10;isch
iscooks<-shuju.cooks>1;iscooks
isch*iscooks
#正态性检验
plot(shuju.reg,2) #qq plot
qqPlot(shuju.reg) #这个qq plot含有更多的信息
shuju.reg<-lm(y~x)
#方差齐性检验
#1.残差图
shuju.res<-residuals(shuju.reg)
par(mfrow=c(1,1)) #设置画图为1*1的格式
plot(shuju.res~x) #按照书上作以X为横坐标的残差图
#2.Spearman等级相关系数
cor.test(x,abs(shuju.res),method="spearman")
#3.ncvTest
library(car)
ncvTest(shuju.reg)
#4.spreadLevelPlot
library(car)
spreadLevelPlot(shuju.reg)
#5.gvlma综合诊断
#install.packages("gvlma")
library(gvlma)
gvlma(shuju.reg)
#自相关性
#图形诊断自相关性
shuju.res1<-shuju.res[1:length(shuju.res)-1]
shuju.res2<-shuju.res[2:length(shuju.res)]
plot(shuju.res1,shuju.res2) #e(t)与e(t-1)作图
#统计量诊断自相关性
library(car)
durbinWatsonTest(shuju.reg)
#异常值与强影响点
#残差
shuju.stdres<-rstudent(shuju.reg);shuju.stdres
#中心化杠杆值
ch<-hatvalues(shuju.reg)-1/10;ch
#Cook距离
shuju.cooks<-cooks.distance(shuju.reg);shuju.cooks
#找异常值
isoutlier<-abs(shuju.stdres3)>3;isoutlier
isch<-ch>2*1/10;isch
iscooks<-shuju.cooks>1;iscooks
isch*iscooks
#正态性检验
plot(shuju.reg,2) #qq plot
qqPlot(shuju.reg) #这个qq plot含有更多的信息
0 0
- 回归诊断的r语言代码
- R语言中的回归诊断
- R语言线性回归诊断
- 主成分回归的r语言代码
- 分位数回归的r语言代码
- 岭回归和lasso回归的r语言代码
- 岭回归和lasso回归的r语言代码
- 自相关性的诊断以及修正方法r语言代码
- 线性回归诊断--R
- 非线性回归模型、多项式回归、局部回归的r语言代码
- R语言回归模型预测绘图plot,predict,回归诊断,模型评价
- 一元回归分析r语言代码
- 多元回归分析r语言代码
- 异常点与强影响点的诊断r语言代码
- R 语言与简单的回归分析
- 分位数回归的R语言实现
- R 语言与简单的回归分析
- R语言评测回归模型的性能
- 构建需求响应式亿级商品详情页
- 技能系统设计笔记 4
- Redis运行流程源码解析
- HDU 5072 容斥原理 + 质因数分解
- 技能系统设计笔记 5
- 回归诊断的r语言代码
- bootloader概述
- HDU 5073 思维
- 技能系统设计笔记 6
- 被问到的面试题
- 关于背景色颜色重置
- HDU 5112 水
- UVa1585 Score
- Spark Shuffle系列-----2. Spark Shuffle map端的原理和实现