Importa pacote mctest
library(mctest)
Importa tabela de exemplo Hald Cement
data(Hald)
Hald
## y X1 X2 X3 X4
## [1,] 78.5 7 26 6 60
## [2,] 74.3 1 29 15 52
## [3,] 104.3 11 56 8 20
## [4,] 87.6 11 31 8 47
## [5,] 95.9 7 52 6 33
## [6,] 109.2 11 55 9 22
## [7,] 102.7 3 71 17 6
## [8,] 72.5 1 31 22 44
## [9,] 93.1 2 54 18 22
## [10,] 115.9 21 47 4 26
## [11,] 83.8 1 40 23 34
## [12,] 113.3 11 66 9 12
## [13,] 109.4 10 68 8 12
Cria modelo linear, que vai ser usado para calcular multicolinearidade.
model <- lm(y~X1+X2+X3+X4, data = as.data.frame(Hald))
model
##
## Call:
## lm(formula = y ~ X1 + X2 + X3 + X4, data = as.data.frame(Hald))
##
## Coefficients:
## (Intercept) X1 X2 X3 X4
## 62.4054 1.5511 0.5102 0.1019 -0.1441
id<-imcdiag(model)
id$idiags[,1]
## X1 X2 X3 X4
## 38.49621 254.42317 46.86839 282.51286
imcdiag(model, method = "VIF", vif = 5)
##
## Call:
## imcdiag(mod = model, method = "VIF", vif = 5)
##
##
## VIF Multicollinearity Diagnostics
##
## VIF detection
## X1 38.4962 1
## X2 254.4232 1
## X3 46.8684 1
## X4 282.5129 1
##
## Multicollinearity may be due to X1 X2 X3 X4 regressors
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
## ===================================
imcdiag(model, method="IND1", ind1=0.01, corr=TRUE)
##
## Call:
## imcdiag(mod = model, method = "IND1", corr = TRUE, ind1 = 0.01)
##
##
## IND1 Multicollinearity Diagnostics
##
## IND1 detection
## X1 0.0087 1
## X2 0.0013 1
## X3 0.0071 1
## X4 0.0012 1
##
## Multicollinearity may be due to X1 X2 X3 X4 regressors
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
## ===================================
##
## Correlation Matrix
## X1 X2 X3 X4
## X1 1.0000000 0.2285795 -0.8241338 -0.2454451
## X2 0.2285795 1.0000000 -0.1392424 -0.9729550
## X3 -0.8241338 -0.1392424 1.0000000 0.0295370
## X4 -0.2454451 -0.9729550 0.0295370 1.0000000
##
## ====================NOTE===================
##
## X1 and X3 may be collinear as |-0.824134|>=0.7
## X2 and X4 may be collinear as |-0.972955|>=0.7
imcdiag(model, method = "CVIF", cvif = 5, corr = TRUE)
##
## Call:
## imcdiag(mod = model, method = "CVIF", corr = TRUE, cvif = 5)
##
##
## CVIF Multicollinearity Diagnostics
##
## CVIF detection
## X1 -0.5846 0
## X2 -3.8635 0
## X3 -0.7117 0
## X4 -4.2900 0
##
## NOTE: CVIF Method Failed to detect multicollinearity
##
##
## 0 --> COLLINEARITY is not detected by the test
##
## ===================================
##
## Correlation Matrix
## X1 X2 X3 X4
## X1 1.0000000 0.2285795 -0.8241338 -0.2454451
## X2 0.2285795 1.0000000 -0.1392424 -0.9729550
## X3 -0.8241338 -0.1392424 1.0000000 0.0295370
## X4 -0.2454451 -0.9729550 0.0295370 1.0000000
##
## ====================NOTE===================
##
## X1 and X3 may be collinear as |-0.824134|>=0.7
## X2 and X4 may be collinear as |-0.972955|>=0.7
imcdiag(model, all = TRUE)
##
## Call:
## imcdiag(mod = model, all = TRUE)
##
##
## All Individual Multicollinearity Diagnostics in 0 or 1
##
## VIF TOL Wi Fi Leamer CVIF Klein IND1 IND2
## X1 1 1 1 1 0 0 0 1 1
## X2 1 1 1 1 1 0 1 1 1
## X3 1 1 1 1 0 0 0 1 1
## X4 1 1 1 1 1 0 1 1 1
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
## X1 , X2 , X3 , X4 , coefficient(s) are non-significant may be due to multicollinearity
##
## R-square of y on all x: 0.9824
##
## * use method argument to check which regressors may be the reason of collinearity
## ===================================
imcdiag(model, method = "VIF", all = TRUE)
##
## Call:
## imcdiag(mod = model, method = "VIF", all = TRUE)
##
##
## VIF Multicollinearity Diagnostics
##
## VIF detection
## X1 38.4962 1
## X2 254.4232 1
## X3 46.8684 1
## X4 282.5129 1
##
## All Individual Multicollinearity Diagnostics in 0 or 1
##
## VIF TOL Wi Fi Leamer CVIF Klein IND1 IND2
## X1 1 1 1 1 0 0 0 1 1
## X2 1 1 1 1 1 0 1 1 1
## X3 1 1 1 1 0 0 0 1 1
## X4 1 1 1 1 1 0 1 1 1
##
## Multicollinearity may be due to X1 X2 X3 X4 regressors
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
## ===================================
imcdiag(model, method = "VIF")[[1]][,1]
## X1 X2 X3 X4
## 38.49621 254.42317 46.86839 282.51286
plot(imcdiag(model, method = "VIF")[[1]][,1]) # vif plot
od<-omcdiag(model)
omcdiag(model, Inter=FALSE)
##
## Call:
## omcdiag(mod = model, Inter = FALSE)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0011 1
## Farrar Chi-Square: 67.2825 1
## Red Indicator: 0.5414 1
## Sum of Lambda Inverse: 622.3006 1
## Theil's Method: 0.9981 1
## Condition Number: 9.4325 0
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
omcdiag(model, detr=0.001, conf=0.99)
##
## Call:
## omcdiag(mod = model, detr = 0.001, conf = 0.99)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0011 0
## Farrar Chi-Square: 67.2825 1
## Red Indicator: 0.5414 1
## Sum of Lambda Inverse: 622.3006 1
## Theil's Method: 0.9981 1
## Condition Number: 249.5783 1
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
omcdiag(model)[1]
## $odiags
## results detection
## Determinant 1.067659e-03 1
## Farrar Chi-Square 6.728248e+01 1
## Red Indicator 5.413857e-01 1
## sum of Lambda Invers 6.223006e+02 1
## Theil Indicator 9.980901e-01 1
## Condition Number 2.495783e+02 1
mctest(model)
##
## Call:
## omcdiag(mod = mod, Inter = TRUE, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0011 1
## Farrar Chi-Square: 67.2825 1
## Red Indicator: 0.5414 1
## Sum of Lambda Inverse: 622.3006 1
## Theil's Method: 0.9981 1
## Condition Number: 249.5783 1
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
mctest(model, Inter=FALSE)
##
## Call:
## omcdiag(mod = mod, Inter = FALSE, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0011 1
## Farrar Chi-Square: 67.2825 1
## Red Indicator: 0.5414 1
## Sum of Lambda Inverse: 622.3006 1
## Theil's Method: 0.9981 1
## Condition Number: 9.4325 0
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
mctest(model, type="i")
##
## Call:
## imcdiag(mod = mod, method = method, corr = FALSE, vif = vif,
## tol = tol, conf = conf, cvif = cvif, ind1 = ind1, ind2 = ind2,
## leamer = leamer, all = all)
##
##
## All Individual Multicollinearity Diagnostics Result
##
## VIF TOL Wi Fi Leamer CVIF Klein IND1 IND2
## X1 38.4962 0.0260 112.4886 187.4811 0.1612 -0.5846 0 0.0087 0.9875
## X2 254.4232 0.0039 760.2695 1267.1158 0.0627 -3.8635 1 0.0013 1.0099
## X3 46.8684 0.0213 137.6052 229.3419 0.1461 -0.7117 0 0.0071 0.9923
## X4 282.5129 0.0035 844.5386 1407.5643 0.0595 -4.2900 1 0.0012 1.0103
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
## X1 , X2 , X3 , X4 , coefficient(s) are non-significant may be due to multicollinearity
##
## R-square of y on all x: 0.9824
##
## * use method argument to check which regressors may be the reason of collinearity
## ===================================
VIF<-mctest(model, type="i", method="VIF")
VIF[[1]][,1] # named VIF values only
## X1 X2 X3 X4
## 38.49621 254.42317 46.86839 282.51286
IND1<-mctest(model, type="i", method="IND1")
IND1[[1]][,1] # named IND1 values only
## X1 X2 X3 X4
## 0.008658861 0.001310153 0.007112115 0.001179887
mctest(model, type="i", corr=TRUE)
##
## Call:
## imcdiag(mod = mod, method = method, corr = TRUE, vif = vif, tol = tol,
## conf = conf, cvif = cvif, ind1 = ind1, ind2 = ind2, leamer = leamer,
## all = all)
##
##
## All Individual Multicollinearity Diagnostics Result
##
## VIF TOL Wi Fi Leamer CVIF Klein IND1 IND2
## X1 38.4962 0.0260 112.4886 187.4811 0.1612 -0.5846 0 0.0087 0.9875
## X2 254.4232 0.0039 760.2695 1267.1158 0.0627 -3.8635 1 0.0013 1.0099
## X3 46.8684 0.0213 137.6052 229.3419 0.1461 -0.7117 0 0.0071 0.9923
## X4 282.5129 0.0035 844.5386 1407.5643 0.0595 -4.2900 1 0.0012 1.0103
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
## X1 , X2 , X3 , X4 , coefficient(s) are non-significant may be due to multicollinearity
##
## R-square of y on all x: 0.9824
##
## * use method argument to check which regressors may be the reason of collinearity
## ===================================
##
## Correlation Matrix
## X1 X2 X3 X4
## X1 1.0000000 0.2285795 -0.8241338 -0.2454451
## X2 0.2285795 1.0000000 -0.1392424 -0.9729550
## X3 -0.8241338 -0.1392424 1.0000000 0.0295370
## X4 -0.2454451 -0.9729550 0.0295370 1.0000000
##
## ====================NOTE===================
##
## X1 and X3 may be collinear as |-0.824134|>=0.7
## X2 and X4 may be collinear as |-0.972955|>=0.7
mctest(model, type="i", method="VIF", corr=TRUE)
##
## Call:
## imcdiag(mod = mod, method = method, corr = TRUE, vif = vif, tol = tol,
## conf = conf, cvif = cvif, ind1 = ind1, ind2 = ind2, leamer = leamer,
## all = all)
##
##
## VIF Multicollinearity Diagnostics
##
## VIF detection
## X1 38.4962 1
## X2 254.4232 1
## X3 46.8684 1
## X4 282.5129 1
##
## Multicollinearity may be due to X1 X2 X3 X4 regressors
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
## ===================================
##
## Correlation Matrix
## X1 X2 X3 X4
## X1 1.0000000 0.2285795 -0.8241338 -0.2454451
## X2 0.2285795 1.0000000 -0.1392424 -0.9729550
## X3 -0.8241338 -0.1392424 1.0000000 0.0295370
## X4 -0.2454451 -0.9729550 0.0295370 1.0000000
##
## ====================NOTE===================
##
## X1 and X3 may be collinear as |-0.824134|>=0.7
## X2 and X4 may be collinear as |-0.972955|>=0.7
mctest(model, type="b")
##
## Call:
## omcdiag(mod = mod, Inter = Inter, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0011 1
## Farrar Chi-Square: 67.2825 1
## Red Indicator: 0.5414 1
## Sum of Lambda Inverse: 622.3006 1
## Theil's Method: 0.9981 1
## Condition Number: 249.5783 1
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
##
## ===================================
##
## Call:
## imcdiag(mod = mod, method = method, corr = FALSE, vif = vif,
## tol = tol, conf = conf, cvif = cvif, ind1 = ind1, ind2 = ind2,
## leamer = leamer, all = all)
##
##
## All Individual Multicollinearity Diagnostics Result
##
## VIF TOL Wi Fi Leamer CVIF Klein IND1 IND2
## X1 38.4962 0.0260 112.4886 187.4811 0.1612 -0.5846 0 0.0087 0.9875
## X2 254.4232 0.0039 760.2695 1267.1158 0.0627 -3.8635 1 0.0013 1.0099
## X3 46.8684 0.0213 137.6052 229.3419 0.1461 -0.7117 0 0.0071 0.9923
## X4 282.5129 0.0035 844.5386 1407.5643 0.0595 -4.2900 1 0.0012 1.0103
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
## X1 , X2 , X3 , X4 , coefficient(s) are non-significant may be due to multicollinearity
##
## R-square of y on all x: 0.9824
##
## * use method argument to check which regressors may be the reason of collinearity
## ===================================
mctest(model, type="b", method="VIF", cor=TRUE)
##
## Call:
## omcdiag(mod = mod, Inter = Inter, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0011 1
## Farrar Chi-Square: 67.2825 1
## Red Indicator: 0.5414 1
## Sum of Lambda Inverse: 622.3006 1
## Theil's Method: 0.9981 1
## Condition Number: 249.5783 1
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
##
## ===================================
##
## Call:
## imcdiag(mod = mod, method = method, corr = FALSE, vif = vif,
## tol = tol, conf = conf, cvif = cvif, ind1 = ind1, ind2 = ind2,
## leamer = leamer, all = all)
##
##
## VIF Multicollinearity Diagnostics
##
## VIF detection
## X1 38.4962 1
## X2 254.4232 1
## X3 46.8684 1
## X4 282.5129 1
##
## Multicollinearity may be due to X1 X2 X3 X4 regressors
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
## ===================================
VIF and CN desired threshold eigenvalues without intercept term
mctest(model, type="b", method="VIF", Inter=FALSE, vif=15, cn=35)
##
## Call:
## omcdiag(mod = mod, Inter = Inter, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0011 1
## Farrar Chi-Square: 67.2825 1
## Red Indicator: 0.5414 1
## Sum of Lambda Inverse: 622.3006 1
## Theil's Method: 0.9981 1
## Condition Number: 9.4325 0
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
##
## ===================================
##
## Call:
## imcdiag(mod = mod, method = method, corr = FALSE, vif = vif,
## tol = tol, conf = conf, cvif = cvif, ind1 = ind1, ind2 = ind2,
## leamer = leamer, all = all)
##
##
## VIF Multicollinearity Diagnostics
##
## VIF detection
## X1 38.4962 1
## X2 254.4232 1
## X3 46.8684 1
## X4 282.5129 1
##
## Multicollinearity may be due to X1 X2 X3 X4 regressors
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
## ===================================
mctest(model, all = TRUE)
##
## Call:
## omcdiag(mod = mod, Inter = TRUE, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0011 1
## Farrar Chi-Square: 67.2825 1
## Red Indicator: 0.5414 1
## Sum of Lambda Inverse: 622.3006 1
## Theil's Method: 0.9981 1
## Condition Number: 249.5783 1
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
mctest(model, method = "VIF", all = TRUE)
## Warning in mctest(model, method = "VIF", all = TRUE):
##
## method or corr argument is required for imcdiag function only
##
## Call:
## omcdiag(mod = mod, Inter = TRUE, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0011 1
## Farrar Chi-Square: 67.2825 1
## Red Indicator: 0.5414 1
## Sum of Lambda Inverse: 622.3006 1
## Theil's Method: 0.9981 1
## Condition Number: 249.5783 1
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
mctest(model, type="b", all = TRUE)
##
## Call:
## omcdiag(mod = mod, Inter = Inter, detr = detr, red = red, conf = conf,
## theil = theil, cn = cn)
##
##
## Overall Multicollinearity Diagnostics
##
## MC Results detection
## Determinant |X'X|: 0.0011 1
## Farrar Chi-Square: 67.2825 1
## Red Indicator: 0.5414 1
## Sum of Lambda Inverse: 622.3006 1
## Theil's Method: 0.9981 1
## Condition Number: 249.5783 1
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
##
## ===================================
##
## Call:
## imcdiag(mod = mod, method = method, corr = FALSE, vif = vif,
## tol = tol, conf = conf, cvif = cvif, ind1 = ind1, ind2 = ind2,
## leamer = leamer, all = all)
##
##
## All Individual Multicollinearity Diagnostics in 0 or 1
##
## VIF TOL Wi Fi Leamer CVIF Klein IND1 IND2
## X1 1 1 1 1 0 0 0 1 1
## X2 1 1 1 1 1 0 1 1 1
## X3 1 1 1 1 0 0 0 1 1
## X4 1 1 1 1 1 0 1 1 1
##
## 1 --> COLLINEARITY is detected by the test
## 0 --> COLLINEARITY is not detected by the test
##
## X1 , X2 , X3 , X4 , coefficient(s) are non-significant may be due to multicollinearity
##
## R-square of y on all x: 0.9824
##
## * use method argument to check which regressors may be the reason of collinearity
## ===================================