Skip to contents

Check Bayesian models fitted with brms

Usage

dh_check_brms(
  model,
  integer = FALSE,
  plot = TRUE,
  nsamples = 1000,
  ntrys = 5,
  ...
)

Arguments

model

A fitted model brms::brmsfit-class(). Categorical and ordinal models not supported by now.

integer

Logical (TRUE/FALSE), indicating if response is an integer, as in Poisson and binomial models

plot

Logical. Plot residual checks? Default is TRUE.

nsamples

Integer. Number of samples to draw from the posterior.

ntrys

Integer. Number of trys to use for truncated distributions. See brms::posterior_predict().

...

Further arguments for DHARMa::plotResiduals()

Value

An object of type DHARMa. See DHARMa::createDHARMa() for more details.

Examples

if (FALSE) {
# Example models taken from brms::brm()

# Poisson regression for the number of seizures in epileptic patients
fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient),
           data = epilepsy, family = poisson())
simres <- dh_check_brms(fit1, integer = TRUE)
plot(simres, form = epilepsy$zAge)
testDispersion(simres)


# Probit regression using the binomial family
ntrials <- sample(1:10, 100, TRUE)
success <- rbinom(100, size = ntrials, prob = 0.4)
x <- rnorm(100)
data4 <- data.frame(ntrials, success, x)
fit4 <- brm(success | trials(ntrials) ~ x, data = data4,
            family = binomial("probit"))
summary(fit4)
simres <- dh_check_brms(fit4, integer = TRUE)
plot(simres, form = data4$x)
}