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.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)