Collinearity after accounting for random / mixed effects
can two or more predictors become more / less collinear after accounting for random effects?
In my case, I tested collinearity before modeling, for example. using VIF and checks everything. However, the ranking (use of IP) of the different models makes me doubt whether it can actually be shared between the predictors.
Any ideas?
ps! Can someone with a higher rep than I add a more relevant tag like collinearity?
source to share
There are several solutions in this blog post . They use some code to create a function that will compute the VIF for model objects lmer
and lme
from packages lmer
and nlme
R, respectively. I copied the code for the function below.
vif.lme <- function (fit) {
## adapted from rms::vif
v <- vcov(fit)
nam <- names(fixef(fit))
## exclude intercepts
ns <- sum(1 * (nam == "Intercept" | nam == "(Intercept)"))
if (ns > 0) {
v <- v[-(1:ns), -(1:ns), drop = FALSE]
nam <- nam[-(1:ns)] }
d <- diag(v)^0.5
v <- diag(solve(v/(d %o% d)))
names(v) <- nam
v }
Once you run this code once, you can execute a new function vif.lme
in the R environment. Below is an example of using a random dataset and an uninformative random effect. I am using a non-informative random effect so that the results lme
internally nlme
will generate the same parameter values โโfor the predictors as lm
in the base R. Then I use the above code to calculate the variance inflation rates and also the vif
functino from the package car
that is used to calculate the VIF for the linear models to show that they give the same result.
#make 4 vectors- c is used as an uninformative random effect for the lme model
a<-c(1:10)
b1<-c(2,4,6,8,10,100,14,16,18,20)
b2<-c(1,9,2,4,5,6,4,3,2,-1)
c<-c(1,1,1,1,1,1,1,1,1,1)
test<-data.frame(a,b1,b2,c)
#model a as a function of b1 and b2, and c as a random effect
require(nlme)
fit<-lme(a~b1+b2, random=~1|c,data=test)
#see how the model fits
summary(fit)
#check variance inflation factors
vif.lme(fit)
#create a new regular linear regression model and check VIF using the car package.
#answers should be the same, as our random effect above was totally uninformative
require(car)
fit2<- lm(a~b1+b2,data=test)
#check to see that parameter fits are the same.
summary(fit2)
#check to see that variance inflation factors are the same
vif(fit2)
source to share