An open API service indexing awesome lists of open source software.

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

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

[![R-CMD-check](https://github.com/Pakillo/DHARMa.helpers/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/Pakillo/DHARMa.helpers/actions/workflows/R-CMD-check.yaml)
[![HitCount](https://hits.dwyl.com/Pakillo/DHARMAhelpers.svg?style=flat-square)](http://hits.dwyl.com/Pakillo/DHARMAhelpers)
[![HitCount](https://hits.dwyl.com/Pakillo/DHARMAhelpers.svg?style=flat-square&show=unique)](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.