I have composed a function to calculate VIF for nls regression models. It looks like this:
function (a,b,c,d,e,f,g) {
VIFa <- 1/(1- (R2 <- summary(lm(a ~ b + c + d + e + f + g))$r.square))
PMa <- ifelse (sqrt(VIFa) > 2, "JE", "NI")
VIFb <- 1/(1- (R2 <- summary(lm(b ~ a + c + d + e + f + g))$r.square))
PMb <- ifelse (sqrt(VIFb) > 2, "JE", "NI")
VIFc <- 1/(1- (R2 <- summary(lm(c ~ a + b + d + e + f + g))$r.square))
PMc <- ifelse (sqrt(VIFc) > 2, "JE", "NI")
VIFd <- 1/(1- (R2 <- summary(lm(d ~ a + b + c + e + f + g))$r.square))
PMd <- ifelse (sqrt(VIFd) > 2, "JE", "NI")
VIFe <- 1/(1- (R2 <- summary(lm(e ~ a + b + c + d + f + g))$r.square))
PMe <- ifelse (sqrt(VIFe) > 2, "JE", "NI")
VIFf <- 1/(1- (R2 <- summary(lm(f ~ a + b + c + d + e + g))$r.square))
PMf <- ifelse (sqrt(VIFf) > 2, "JE", "NI")
VIFg <- 1/(1- (R2 <- summary(lm(g ~ a + b + c + d + e + f))$r.square))
PMg <- ifelse (sqrt(VIFg) > 2, "JE", "NI")
rezultat <- data.frame(c(VIFa, VIFb, VIFc, VIFd, VIFe, VIFf, VIFg),
c(PMa, PMb, PMc, PMd, PMe, PMf, PMg))
names(rezultat) <- c("VIF", "Multikolinearnost")
return(as.matrix.data.frame(rezultat))
}
Where a,b,c,d,e,f,g are variables that are used in certain model. VIFa is Variance Inflation Factor of 'a' variable, and PMa is a logical value showing whether variance inflation can cause major discrepancy in model (JE = yes) or not (NO = not).
My question is how to make this function suitable for any number of arguments? I already tried to use lapply function, however I could not find a way to use each variable once as dependent and all others as independent (for any number of variables).