Created
November 22, 2015 21:03
-
-
Save BERENZ/e9b581a4b7160357934e to your computer and use it in GitHub Desktop.
Variable importance for Mixed Models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
calc.relip.mm <- function(model,type='lmg') { | |
if (!isLMM(model) & !isGLMM(model)) { | |
stop('Currently supports only lmer/glmer objects', call. = FALSE) | |
} | |
require(lme4) | |
X <- getME(model,'X') | |
X <- X[,-1] | |
Y <- getME(model,'y') | |
s_resid <- sigma(model) | |
s_effect <- getME(model,'theta')*s_resid | |
s2 <- sum(s_resid^2,s_effect^2) | |
V <- Diagonal(x = s2,n=nrow(X)) | |
YX <- cbind(Y,X) | |
cov_XY <- solve( t(YX) %*% solve(V) %*% as.matrix(YX)) | |
colnames(cov_XY) <- rownames(cov_XY) <- colnames(YX) | |
importances <- calc.relimp(as.matrix(cov_XY),rela=T,type=type) | |
return(importances) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment