# Scatterplot of y vs. average yrep
fit <- stan_glm(mpg ~ wt, data = mtcars)
pp_check(fit, check = "scatter")
# Separate scatterplots of y vs. a few different yrep datasets
pp_check(fit, check = "scatter", nreps = 3)
# 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"))
# Define a test function
prop_zero <- function(y) mean(y == 0)
pp_check(example_model, check = "test", test = "prop_zero", binwidth = 1/20)
Run the code above in your browser using DataLab