Created
March 23, 2023 22:45
-
-
Save bbolker/05a73e36b34178bb1c4c3639d1cb3bc7 to your computer and use it in GitHub Desktop.
demonstration of estimation of OLREs in a Poisson model
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
| N <- 100 | |
| set.seed(101) | |
| dd <- data.frame( | |
| y = rpois(N, exp(rnorm(N))), | |
| f = factor(seq(N)) | |
| ) | |
| dd <- dd[order(dd$y), ] | |
| library(lme4) | |
| m <- glmer(y ~ 1 + (1|f), family = poisson, data = dd) | |
| ## plot | |
| png("shrinkage.png") | |
| par(las = 1, bty = "l") | |
| cvec <- adjustcolor(palette()[1:2], alpha.f = 0.7) | |
| matplot(cbind(dd$y, predict(m, type = "response")), | |
| type = "p", | |
| pch = 16, | |
| ylab = "", | |
| col = cvec) | |
| legend("center", legend = c("obs", "pred"), col = cvec, pch = 16) | |
| dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment