if (!exists("example_model")) example(example_model)
# Compare distribution of y to distributions of yrep
(pp_dist <- pp_check(example_model, check = "dist", overlay = TRUE))
pp_dist +
ggplot2::scale_color_manual(values = c("red", "black")) + # change colors
ggplot2::scale_size_manual(values = c(0.5, 3)) + # change line sizes
ggplot2::scale_fill_manual(values = c(NA, NA)) # remove fill
# Check residuals
pp_check(example_model, check = "resid", nreps = 6)
# Check histograms of test statistics
test_mean <- pp_check(example_model, check = "test", test = "mean")
test_sd <- pp_check(example_model, check = "test", test = "sd")
gridExtra::grid.arrange(test_mean, test_sd, ncol = 2)
# Scatterplot of two test statistics
pp_check(example_model, check = "test", test = c("mean", "sd"))
## Not run:
# # Scatterplots of y vs. yrep
# fit <- stan_glm(mpg ~ wt, data = mtcars)
# pp_check(fit, check = "scatter") # y vs. average yrep
# pp_check(fit, check = "scatter", nreps = 3) # y vs. a few different yrep datasets
#
#
# # Defining a function to compute test statistic
# roaches$roach100 <- roaches$roach1 / 100
# fit_pois <- stan_glm(y ~ treatment + roach100 + senior, offset = log(exposure2),
# family = "poisson", data = roaches)
# fit_nb <- update(fit_pois, family = "neg_binomial_2")
#
# prop0 <- function(y) mean(y == 0) # function to compute proportion of zeros
# pp_check(fit_pois, check = "test", test = "prop0") # looks bad
# pp_check(fit_nb, check = "test", test = "prop0") # much better
# ## End(Not run)
Run the code above in your browser using DataLab