plot.DHARMa | R Documentation |
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)
## S3 method for class 'DHARMa'
plot(x, title = "DHARMa residual", ...)
x |
An object of class DHARMa with simulated residuals created by simulateResiduals. |
title |
The title for both panels (plotted via mtext, outer = TRUE). |
... |
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. |
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 (default color but see Note).
Very briefly, we would expect that a correctly specified model shows:
a) a straight 1-1 line, as well as non-significance 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.
The color for highlighting outliers and significant tests can be changed by setting options(DHARMaSignalColor = "red")
to a different color. See getOption("DHARMaSignalColor")
for the current setting. This is convenient for a color-blind friendly display, since red and black are difficult for some people to separate.
plotResiduals, plotQQunif
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 = TRUE, will produce a boxplot
plotResiduals(simulationOutput, form = testData$group)
# to diagnose overdispersion and heteroskedasticity it can be useful to
# display residuals as absolute deviation from the expected mean 0.5
plotResiduals(simulationOutput, absoluteDeviation = TRUE, quantreg = FALSE)
# 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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.