2014-10-29 93 views
3

在考慮隨機效應後,兩個/更多的預測變量會變得更低/共線性?考慮到隨機效應/混合效應後的共線性

在我的情況下,我已經測試了建模前的共線性,使用VIF,並且一切都檢查出來。然而,不同模型的排名(使用IC)使我不確定它是否真能區分預測變量。

任何想法?

ps!能否有人比我更高的代表添加更相關的標籤,如共線性?

回答

7

在此處列出了一些解決方案blog post。他們使用一些代碼來創建一個函數,它將分別計算lmer和和nlme R包中的模型對象的VIF。我已經複製下面的函數的代碼。

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 } 

一旦運行該代碼一次,你將能夠R環境中執行了新的功能,vif.lme。我用下面的例子給出了一個隨機數據集和一個無信息的隨機效應。我使用了無效的隨機效應,以便lme的結果在nlme內將生成與基數爲lm的預測變量相同的參數值。然後,我使用上面的代碼來計算方差膨脹因子以及來自carvif functino包用於計算線性模型的VIF,以顯示它們給出相同的輸出。

#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)