I am running a lot of regressions through this code
vek <- read_excel("h24.xlsx")
filterfile <- read_excel("filterfile.xlsx")
x <- c(filterfile$Column)
sink("D:/test.csv")
for (temp_var in x){
h24 <- filter(vek,KEY == temp_var)
h24 <- na.omit(h24)
frml <- UNITS ~ h36+ z24+ z36+ pr
if (length(unique(h24$`F`)) > 1) frml <- update.formula(frml, ~ F + .)
if (length(unique(h24$`D`)) > 1) frml <- update.formula(frml, ~ D + .)
lmtest <- lm(frml, data = h24)
print(vif(lmtest))
}
sink()
The print(vif(lmtest))
throws some errors: there are aliased coefficients in the model
In case of these erros, I would like to run alias(lmtest)
Even though there are a few threads about trycatch()
I could not fix it. What would be the easiest way to solve this?