https://github.com/pakillo/dharma.helpers
Helper functions to check Bayesian brms models with DHARMa
https://github.com/pakillo/dharma.helpers
bayesian r-package statistics
Last synced: 3 months ago
JSON representation
Helper functions to check Bayesian brms models with DHARMa
- Host: GitHub
- URL: https://github.com/pakillo/dharma.helpers
- Owner: Pakillo
- License: other
- Created: 2021-09-17T11:55:21.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-11-24T14:08:28.000Z (6 months ago)
- Last Synced: 2025-11-28T03:10:52.719Z (6 months ago)
- Topics: bayesian, r-package, statistics
- Language: R
- Homepage: https://pakillo.github.io/DHARMa.helpers/
- Size: 1.74 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# DHARMa.helpers
[](https://github.com/Pakillo/DHARMa.helpers/actions/workflows/R-CMD-check.yaml)
[](http://hits.dwyl.com/Pakillo/DHARMAhelpers)
[](http://hits.dwyl.com/Pakillo/DHARMAhelpers)
https://pakillo.github.io/DHARMa.helpers
DHARMa.helpers is an R package that facilitates checking fitted statistical models via the [DHARMa](https://cran.r-project.org/web/packages/DHARMa/vignettes/DHARMa.html) package. By now, only Bayesian models fitted with [brms](https://paul-buerkner.github.io/brms/) are implemented. See [this blogpost](https://frodriguezsanchez.net/post/using-dharma-to-check-bayesian-models-fitted-with-brms/) for a detailed explanation of the approach.
## Installation
``` r
# install.packages("remotes")
remotes::install_github("Pakillo/DHARMa.helpers")
```
## Example
```{r message = FALSE}
library(brms)
library(DHARMa.helpers)
```
### Poisson regression
Fit model:
```{r cache = TRUE}
# 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)
```
Check with DHARMa:
```{r}
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):
```{r}
plot(simres, form = epilepsy$zAge)
```
Test overdispersion:
```{r}
DHARMa::testDispersion(simres)
```
See https://pakillo.github.io/DHARMa.helpers/reference/dh_check_brms.html for more examples.