-
Notifications
You must be signed in to change notification settings - Fork 0
/
VIF.R
34 lines (29 loc) · 990 Bytes
/
VIF.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## ==================================================
## R Function by Chanseok Park
## (MTHSC 805-Clemson University, IE-68722-PNU)
##
## VIF (Variance Inflation Factor)
##
## Usage: LM = lm ( y ~ x1 + x2 + x3 )
## vif (LM)
## Note: With the help of Dr. Venables
## ==================================================
vif <- function(object, ...)
UseMethod("vif")
vif.default <- function(object, ...)
stop("No default method for vif. Sorry.")
vif.lm <- function(object, ...) {
V <- summary(object)$cov.unscaled
Vi <- crossprod(model.matrix(object))
nam <- names(coef(object))
if(k <- match("(Intercept)", nam, nomatch = F)) {
v1 <- diag(V)[-k]
v2 <- (diag(Vi)[-k] - Vi[k, -k]^2/Vi[k,k])
nam <- nam[-k]
} else {
v1 <- diag(V)
v2 <- diag(Vi)
warning("No intercept term detected. Results may surprise.")
}
structure(v1*v2, names = nam)
}