Learn R Programming

DHARMa (version 0.5.1)

Residual Diagnostics for Hierarchical (Multi-Level / Mixed) Regression Models

Description

Uses a simulation-based approach to create readily interpretable scaled (quantile) residuals for fitted generalized linear (mixed) models. Currently supported are linear and generalized linear (mixed) models from 'lme4' (classes 'lmerMod', 'glmerMod'), 'glmmTMB', 'GLMMadaptive', 'spaMM', and 'brms' (simple models); phylogenetic linear models from 'phylolm' (classes 'phylolm' and 'phyloglm'); generalized additive models ('gam' from 'mgcv'); 'glm' (including 'negbin' from 'MASS', but excluding quasi-distributions) and 'lm' model classes. Moreover, externally created simulations, e.g. posterior predictive simulations from Bayesian software such as 'JAGS', 'STAN', or 'BUGS' can be processed as well. The resulting residuals are standardized to values between 0 and 1 and can be interpreted as intuitively as residuals from a linear regression. The package also provides a number of plot and test functions for typical model misspecification problems, such as over/underdispersion, zero-inflation, and residual spatial, temporal and phylogenetic autocorrelation.

Copy Link

Version

Install

install.packages('DHARMa')

Monthly Downloads

32,911

Version

0.5.1

License

GPL (>= 3)

Maintainer

Florian Hartig

Last Published

November 7th, 2026

Functions in DHARMa (0.5.1)

checkBinomialMatrixWeights

Stop for binomial models with a cbind() response and prior weights
createDHARMa

Create a DHARMa object from hand-coded simulations or Bayesian posterior predictive simulations.
DHARMa-package

DHARMa: Residual Diagnostics for Hierarchical (Multi-Level / Mixed) Regression Models
checkSimulations

Check simulated data
getObservedResponse

Get model response
getFittedResponse

Get fitted/predicted values on the scale of the observed response
createData

Simulate test data
DHARMa.ecdf

Modified ECDF function.
getFormulaPredictors

Get predictors specified in a formula.
getPredictorNames

Get predictor names
getPearsonResiduals

Get Pearson residuals
getPossibleModels

get possible models
getQuantile

Calculate Residual Quantiles
ensureDHARMa

Ensures that an object is of class DHARMa
getFixedEffects

Extract fixed effects of a supported model
getSimulations

Get model simulations
hist.DHARMa

Histogram of DHARMa residuals
hurricanes

Hurricanes
hasWeights

Check if a model has (problematic) prior weights
getFamily

Get model family
plot.DHARMaBenchmark

Plots DHARMa benchmarks
plotConventionalResiduals

Conventional residual plot
getFitted

Get fitted/predicted values
plotResidualsAll

Create multiple residual plots simultaneously (deprecated)
plotSimulatedResiduals

DHARMa standard residual plots (deprecated)
getData

Get model data
ensurePredictor

Ensures the existence of a valid predictor to plot residuals against
getRefitData

Data and formula for refitting a model to a new response
simulateLRT

Simulated likelihood ratio tests for (generalized) linear mixed models
runBenchmarks

Benchmark calculations
testOutliers

Test for outliers
getResiduals

Get model residuals
plotQQunif

Quantile-quantile plot for a uniform distribution
testOverdispersion

Simulated overdisperstion tests (deprecated)
print.DHARMa

Print simulated residuals
rankTransform

Rank transform predictors
testDispersion

DHARMa dispersion tests
testGeneric

Test for a generic summary statistic based on simulated data
testUniformity

Test for overall uniformity
residuals.DHARMa

Return residuals of a DHARMa simulation
recalculateResiduals

Recalculate residuals with grouping
plotResiduals

Generic res ~ pred scatter plot with spline or quantile regression on top
testZeroInflation

Tests for zero-inflation
testCategorical

Test for categorical dependencies
plot.DHARMa

DHARMa standard residual plots
getRandomState

Record and restore a random state
getRefit

Get model refit
outliers

Return outliers
simulateResiduals

Create simulated residuals
testResiduals

DHARMa general residual test
testSpatialAutocorrelation

Test for distance-based spatial (or similar type) autocorrelation
testOverdispersionParametric

Parametric overdisperstion tests (deprecated)
testTemporalAutocorrelation

Test for temporal autocorrelation
testQuantiles

Test for quantiles
transformQuantiles

Transform quantiles to pdf (deprecated)
testPhylogeneticAutocorrelation

Test for phylogenetic autocorrelation
testPDistribution

Plot distribution of p-values.
testSimulatedResiduals

Residual tests
benchmarkRuntime

Benchmark runtimes of several functions
checkDots

Check dot operator
checkModel

Check if the fitted model is supported by DHARMa