R语言学习(5)——残差和多重共线性
一:残差:
在前面几次的学习中,我已经接触了残差这个概念,接下来,我来详细的探讨一下残差的相关知识。
这个之前的学习中已经有所接触,所以我们接下来进行新的学习。
残差图的绘制方法:
(1)残差图的绘制方法与前面的方法一致,这里不在赘述;
(2)标准化残差的画法;
(3)外学生化残差的画法;
二:多重共线性
> shujuji<-data.frame(y<-c(10.006,9.737,15.087,8.422,8.625,16.289,5.958,9.313,12.960,5.541,8.756,10.937),
+ x1<-rep(c(8,0,2,0),c(3,3,3,3)),
+ x2<-rep(c(1,0,7,0),c(3,3,3,3)),
+ x3<-rep(c(1,9,0),c(3,3,6)),
+ x4<-rep(c(1,0,1,10),c(1,2,6,3)),
+ x5<-c(0.541,0.130,2.116,-2.397,-0.046,0.365,1.996,0.228,1.380,-0.798,0.257,0.440),
+ x6<-c(-0.099,0.070,0.115,0.252,0.017,1.504,-0.865,-0.055,0.502,-0.399,0.101,0.432)
+ )
> xx<-cor(shujuji[2:7])
> kappa(xx,exact = TRUE)
[1] 2195.908
检验的值大于1000,所以我们可以认为x变量之间有严重的多重共线性。
进一步,为了找出那些变量之间具有多重共线性,计算矩阵的特征值和相应的特征向量。
> eigen(xx)
eigen() decomposition
$values
[1] 2.428787365 1.546152096 0.922077664 0.793984690 0.307892134 0.001106051
$vectors
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] -0.3907189 0.33968212 0.67980398 -0.07990398 0.2510370 -0.447679719
[2,] -0.4556030 0.05392140 -0.70012501 -0.05768633 0.3444655 -0.421140280
[3,] 0.4826405 0.45332584 -0.16077736 -0.19102517 -0.4536372 -0.541689124
[4,] 0.1876590 -0.73546592 0.13587323 0.27645223 -0.0152087 -0.573371872
[5,] -0.4977330 0.09713874 -0.03185053 0.56356440 -0.6512834 -0.006052127
[6,] 0.3519499 0.35476494 -0.04864335 0.74817535 0.4337463 -0.002166594
说明变量x1,x2,x3,x4之间存在严重的多重共线性。