Created
October 12, 2015 16:20
-
-
Save guidocor/5cc8692a07028854c0b1 to your computer and use it in GitHub Desktop.
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
# Helper function | |
# gets a fitted glmer model | |
# Example: | |
# m0 <- glmer(acc ~ cond + (0 + rt | subject_nr) + (1 | item) + (1 | subject_nr), family=binomial(link=logit), data = datos.x.rt) | |
# Wald is fast and innacurate, better try the longer "profile" | |
plot.glmer <- function(m0, my.method = "Wald") { | |
# that could take a while | |
confint_m0 <- confint(m0, level = 0.95, method=my.method) | |
# as family is binomial(link=logit), you must convert with plogis() to a human | |
# readable form | |
confint_m0 <- as.data.frame(plogis(confint_m0)) | |
# changes the colnames form the 2.5% and 97.5% to lower and upper | |
colnames(confint_m0) <- c("lower", "upper") | |
# get the effect | |
confint_m0$fixef <- plogis(fixef(m0)) | |
# names the vars | |
confint_m0$vars <- levels(m0@frame$cond) | |
confint_m0 | |
} | |
confint_m0 <- plot.glmer(m0) | |
# Makes the plot | |
(plotm0 <- ggplot(confint_m0, aes( x= vars , y = fixef)) + geom_errorbar(aes(ymin=lower, ymax=upper)) + | |
ggtitle(paste(attr(m0@frame, "formula")[3])) + | |
ylim(0,1) + theme_bw()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment