Created
December 13, 2022 22:32
-
-
Save bbolker/e6694fef9cdc1e509379faed5b5dc39d to your computer and use it in GitHub Desktop.
plotting sjPlots in a grid
This file contains hidden or 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
| library(lme4) | |
| library(sjPlot) | |
| set.seed(101) | |
| n <- 1e3 ## obs per group | |
| ns <- 4 ## groups | |
| dd <- data.frame(s = rep(1:ns, each= n), | |
| f = factor(sample(1:20, size = n*ns, replace = TRUE)), | |
| x = rnorm(n*ns)) | |
| sims <- lapply(1:ns, | |
| function(i) simulate(~x + (1|f), | |
| family = poisson, | |
| newdata = subset(dd, s==i), | |
| newparams = list(beta = c(1,1), theta = 1))[[1]]) | |
| dd$y <- unlist(sims) | |
| fits <- lapply(1:ns, | |
| function(i) glmer(y~x+(1|f), | |
| family = poisson, | |
| data = subset(dd, s==i))) | |
| plots <- lapply(fits, function(f) plot_model(f, type = "pred")$x) | |
| cowplot::plot_grid(plotlist = plots) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for all your help here!!!