Return residuals of a DHARMa simulation
# S3 method for DHARMa
residuals(object, quantileFunction = NULL, outlierValues = NULL, ...)
an object with simulated residuals created by simulateResiduals
optional - a quantile function to transform the uniform 0/1 scaling of DHARMa to another distribution
if a quantile function with infinite support (such as dnorm) is used, residuals that are 0/1 are mapped to -Inf / Inf. outlierValues allows to convert -Inf / Inf values to an optional min / max value.
optional arguments for compatibility with the generic function, no function implemented
the function accesses the slot $scaledResiduals in a fitted DHARMa object, and optionally transforms the standard DHARMa quantile residuals (which have a uniform distribution) to a particular pdf.
# NOT RUN {
library(lme4)
testData = createData(sampleSize = 200, overdispersion = 0.5, family = poisson())
fittedModel <- glmer(observedResponse ~ Environment1 + (1|group),
family = "poisson", data = testData)
simulationOutput <- simulateResiduals(fittedModel = fittedModel)
# standard plot
plot(simulationOutput)
# one of the possible test, for other options see ?testResiduals
testOutliers(simulationOutput)
# for various other plots and tests, see the help / vignette
# the calculated residuals can be accessed via
residuals(simulationOutput)
# transform residuals to other pdf, see ?residuals.DHARMa for details
residuals(simulationOutput, quantileFunction = qnorm, outlierValues = c(-7,7))
# calculating summaries per group
simulationOutput = recalculateResiduals(simulationOutput, group = testData$group)
plot(simulationOutput, quantreg = FALSE)
# create residuals with refitting, see ?simulateResiduals for details
# n=10 is very low, set higher when using this for real
simulationOutput <- simulateResiduals(fittedModel = fittedModel,
n = 10, refit = TRUE)
plot(simulationOutput, quantreg = FALSE)
# }
Run the code above in your browser using DataLab