Skip to content

Helper functions to check Bayesian brms models with DHARMa

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

Pakillo/DHARMa.helpers

Repository files navigation

DHARMa.helpers

R-CMD-check HitCount HitCount

https://pakillo.github.io/DHARMa.helpers

DHARMa.helpers is an R package that facilitates checking fitted statistical models via the DHARMa package. By now, only Bayesian models fitted with brms are implemented. See this blogpost for a detailed explanation of the approach.

Installation

# install.packages("remotes")
remotes::install_github("Pakillo/DHARMa.helpers")

Example

library(brms)
library(DHARMa.helpers)

Poisson regression

Fit model:

# Example model taken brms::brm()
# Poisson regression for the number of seizures in epileptic patients
fit1 <- brm(count ~ zAge + zBase * Trt + (1|patient),
            data = epilepsy, family = poisson(), refresh = 0)
#> Compiling Stan program...
#> Start sampling

Check with DHARMa:

simres <- dh_check_brms(fit1, integer = TRUE)

Note that we use integer = TRUE in this case as we are modelling a discrete response (counts).

Now check residuals against a predictor (zAge):

plot(simres, form = epilepsy$zAge)

Test overdispersion:

DHARMa::testDispersion(simres)

#> 
#>  DHARMa nonparametric dispersion test via sd of residuals fitted vs.
#>  simulated
#> 
#> data:  simulationOutput
#> dispersion = 1.1747, p-value = 0.194
#> alternative hypothesis: two.sided

See https://pakillo.github.io/DHARMa.helpers/reference/dh_check_brms.html for more examples.

About

Helper functions to check Bayesian brms models with DHARMa

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages