plot.DHARMa {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 |
title |
The title for both panels (plotted via mtext, outer = T) |
... |
further options for |
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.
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