# plot.DHARMa: DHARMa standard residual plots In DHARMa: Residual Diagnostics for Hierarchical (Multi-Level / Mixed) Regression Models

## Description

This S3 function creates standard plots for the simulated residuals contained in an object of class DHARMa, using `plotQQunif` (left panel) and `plotResiduals` (right panel)

## Usage

 ```1 2``` ```## S3 method for class 'DHARMa' plot(x, ...) ```

## Arguments

 `x` an object of class DHARMa with simulated residuals created by `simulateResiduals` `...` further options for `plotResiduals`. Consider in particular parameters quantreg, rank and asFactor. xlab, ylab and main cannot be changed when using plot.DHARMa, but can be changed when using plotResiduals.

## Details

The function creates a plot with two panels. The left panel is a uniform qq plot (calling `plotQQunif`), and the right panel shows residuals against predicted values (calling `plotResiduals`), with outliers highlighted in red.

Very briefly, we would expect that a correctly specified model shows:

a) a straight 1-1 line, as well as n.s. of the displayed tests in the qq-plot (left) -> evidence for an the correct overall residual distribution (for more details on the interpretation of this plot, see `plotQQunif`)

b) visual homogeneity of residuals in both vertical and horizontal direction, as well as n.s. of quantile tests in the res ~ predictor plot (for more details on the interpretation of this plot, see `plotResiduals`)

Deviations from these expectations can be interpreted similar to a linear regression. See the vignette for detailed examples.

Note that, unlike `plotResiduals`, plot.DHARMa command uses the default rank = T.

`plotResiduals`, `plotQQunif`
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43``` ```testData = createData(sampleSize = 200, family = poisson(), randomEffectVariance = 1, numGroups = 10) fittedModel <- glm(observedResponse ~ Environment1, family = "poisson", data = testData) simulationOutput <- simulateResiduals(fittedModel = fittedModel) ######### main plotting function ############# # for all functions, quantreg = T will be more # informative, but slower plot(simulationOutput, quantreg = FALSE) ############# Distribution ###################### plotQQunif(simulationOutput = simulationOutput, testDispersion = FALSE, testUniformity = FALSE, testOutliers = FALSE) hist(simulationOutput ) ############# residual plots ############### # rank transformation, using a simulationOutput plotResiduals(simulationOutput, rank = TRUE, quantreg = FALSE) # smooth scatter plot - usually used for large datasets, default for n > 10000 plotResiduals(simulationOutput, rank = TRUE, quantreg = FALSE, smoothScatter = TRUE) # residual vs predictors, using explicit values for pred, residual plotResiduals(simulationOutput, form = testData\$Environment1, quantreg = FALSE) # if pred is a factor, or if asFactor = T, will produce a boxplot plotResiduals(simulationOutput, form = testData\$group) # All these options can also be provided to the main plotting function # If you want to plot summaries per group, use simulationOutput = recalculateResiduals(simulationOutput, group = testData\$group) plot(simulationOutput, quantreg = FALSE) # we see one residual point per RE ```