Learn R Programming

performance (version 0.12.4)

check_residuals: Check uniformity of simulated residuals

Description

check_residuals() checks generalized linear (mixed) models for uniformity of randomized quantile residuals, which can be used to identify typical model misspecification problems, such as over/underdispersion, zero-inflation, and residual spatial and temporal autocorrelation.

Usage

check_residuals(x, ...)

# S3 method for default check_residuals(x, alternative = c("two.sided", "less", "greater"), ...)

Value

The p-value of the test statistics.

Arguments

x

An object returned by simulate_residuals() or DHARMa::simulateResiduals().

...

Passed down to stats::ks.test().

alternative

A character string specifying the alternative hypothesis. See stats::ks.test() for details.

Tests based on simulated residuals

For certain models, resp. model from certain families, tests like check_zeroinflation() or check_overdispersion() are based on simulated residuals. These are usually more accurate for such tests than the traditionally used Pearson residuals. However, when simulating from more complex models, such as mixed models or models with zero-inflation, there are several important considerations. simulate_residuals() relies on DHARMa::simulateResiduals(), and additional arguments specified in ... are passed further down to that function. The defaults in DHARMa are set on the most conservative option that works for all models. However, in many cases, the help advises to use different settings in particular situations or for particular models. It is recommended to read the 'Details' in ?DHARMa::simulateResiduals closely to understand the implications of the simulation process and which arguments should be modified to get the most accurate results.

Details

Uniformity of residuals is checked using a Kolmogorov-Smirnov test. There is a plot() method to visualize the distribution of the residuals. The test for uniformity basically tests to which extent the observed values deviate from the model expectations (i.e. simulated values). In this sense, the check_residuals() function has similar goals like check_predictions().

See Also

simulate_residuals(), check_zeroinflation(), check_overdispersion() and check_predictions(). See also see::plot.see_performance_simres() for options to customize the plot.

Examples

Run this code
if (FALSE) { # require("DHARMa")
dat <- DHARMa::createData(sampleSize = 100, overdispersion = 0.5, family = poisson())
m <- glm(observedResponse ~ Environment1, family = poisson(), data = dat)
res <- simulate_residuals(m)
check_residuals(res)
}

Run the code above in your browser using DataLab