View source: R/auxilaryfunctions.R
ds.residuals | R Documentation |
Calculates the Dunn-Smyth residuals for a fitted model and, if some of the responses are ordinal, a confusion matrix between predicted and true levels.
ds.residuals(object, est = "median", include.ranef = TRUE)
object |
An object for class "boral". |
est |
A choice of either the posterior median ( |
include.ranef |
If response-specific random intercepts were included as part of the fitted model, then this determines whether the predicted random effects will be used in the calculated of the fitted values and thus residuals. When set to |
Details regarding Dunn-Smyth residuals, based on the randomized quantile residuals of Dunn and Smyth (1996), can be found in plot.manyglm
function in the mvabund
package (Wang et al., 2012) where they are implemented in all their glory. Due their inherent stochasticity, Dunn-Smyth residuals will be slightly different each time this function is run. As with other types of residuals, Dunn-Smyth residuals can be used in the context of residual analysis.
For ordinal responses, a single confusion matrix between the predicted levels (as based on the class with the highest probability) and true levels is aso returned. The table pools the results over all columns assumed to be ordinal.
The Dunn-Smyth residuals are calculated based on a point estimate of the parameters, as determined by the argument est
. A fully Bayesian approach would calculate the residuals by averaging over the posterior distribution of the parameters i.e., ergodically average over the MCMC samples. In general however, the results (as in the trends seen in residual analysis) from either approach should be very similar.
Check out also the awesome DHARMa
package for calculation of Dunn-Smyth and probability integral transform residuals in other regression models.
A list containing agree.ordinal
which is a single confusion matrix for ordinal columns, and residuals
which contains Dunn-Smyth residuals.
Francis K.C. Hui [aut, cre], Wade Blanchard [aut]
Maintainer: Francis K.C. Hui <fhui28@gmail.com>
Dunn, P. K., and Smyth, G. K. (1996). Randomized quantile residuals. Journal of Computational and Graphical Statistics, 5, 236-244.
Wang et al. (2012). mvabund-an R package for model-based analysis of multivariate abundance data. Methods in Ecology and Evolution, 3, 471-474.
plot.boral
for constructing residual analysis plots directly; fitted.boral
which calculated fitted values from a model.
## Not run:
## NOTE: The values below MUST NOT be used in a real application;
## they are only used here to make the examples run quick!!!
example_mcmc_control <- list(n.burnin = 10, n.iteration = 100,
n.thin = 1)
testpath <- file.path(tempdir(), "jagsboralmodel.txt")
library(mvabund) ## Load a dataset from the mvabund package
data(spider)
y <- spider$abun
spiderfit_nb <- boral(y, family = "negative.binomial", lv.control = list(num.lv = 2),
row.eff = "fixed", mcmc.control = example_mcmc_control, model.name = testpath)
ds.residuals(spiderfit_nb)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.