Generate posterior predictive checks for a fitted ratio model. Compares observed data to replicated data from the posterior predictive distribution.
Arguments
- object
A
ratiod_fitobject- ...
Additional arguments passed to bayesplot functions
- type
Type of check: "dens_overlay", "scatter", "intervals", "stat"
- component
Which component: "numerator", "denominator", or "both"
- stat
Function for "stat" type (default: mean)
- ndraws
Number of posterior draws to use (default: 50 for plots)
Examples
# pp_check requires a fitted model with posterior predictive draws
# See tratio() examples for fitting models
# \donttest{
# Simulate data and fit model (slow, not run on CRAN)
set.seed(123)
n <- 50
df <- data.frame(
count = rnbinom(n, size = 5, mu = 15),
total = rnbinom(n, size = 8, mu = 100),
x = rnorm(n),
site = factor(rep(1:10, each = 5))
)
fit <- tratio(
count | total ~ x + (1 | site),
data = df,
family = ratiod_negbin_negbin(),
control = list(iter = 200, warmup = 100, chains = 1)
)
#> Inference: Exact (Tier 1)
#> Backend: hmc
#> Reason: default (full MCMC)
#> Fitting ratio model...
#> Family: negbin_negbin
#> Observations: 50
#> Iterations: 200 (warmup: 100)
#> Running NUTS sampler...
#> Parameters: 17
#> Iterations: 200 (warmup: 100)
#> Chains: 1 (cores: 1)
# Density overlay (requires bayesplot package)
# pp_check(fit, type = "dens_overlay")
# }