`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, ...)
# Default S3 method
check_residuals(x, alternative = c("two.sided", "less", "greater"), ...)
```

## 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.

## 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()`

.

## 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.

## 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

```
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)
#> Warning: Non-uniformity of simulated residuals detected (p < .001).
#>
```