Created
June 1, 2022 02:02
-
-
Save tomsing1/9701d638e6cd2287e1307ffb280f1ac5 to your computer and use it in GitHub Desktop.
R script demonstrating how to plot rootograms in R
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(vcd) | |
library(patchwork) | |
set.seed(123) | |
# we make 4 independent draws from a poisson | |
# distribution, fit the poisson distribution | |
# and then draw the rootogram to compare observed | |
# and fitted values. | |
plots <- lapply(1:4, function(draw) { | |
counts <- rpois(100, 1) | |
fit <- vcd::goodfit(counts, type = "poisson", method = "ML") | |
suppressWarnings( | |
vcd::rootogram(fit, scale = "raw", main = sprintf("Draw %s", draw), | |
return_grob = TRUE | |
) | |
) | |
}) | |
patchwork::wrap_plots(plots) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment