Description Usage Arguments Details Value Functions References Examples
Plotting of Dunn-Smyth Residuals
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 | plot_residuals.residual(
residuals,
covar,
plotfunction = facet_species_covariate,
aggregatefcn = mean,
...
)
facet_species_covariate(data, ...)
facet_covariate(data, ...)
plot_residuals_detection.fit(
fit,
detectionresiduals = NULL,
varidx = NULL,
esttype = NULL,
aggregatefcn = mean,
...
)
plot_residuals_occupancy.fit(
fit,
occupancyresidual = NULL,
varidx = NULL,
esttype = NULL,
conditionalLV = TRUE,
aggregatefcn = mean,
...
)
|
residuals |
is a table returned by |
covar |
Is a table of covariate values, it must have a column labelled 'ModelSite' that gives the ModelSite of covariate value. Rows with duplicated ModelSite values are averaged, which is in keeping with Warton et al for detection residuals. |
plotfunction |
A plotting method to use. Default is |
... |
Extra arguments to pass. Currently ignored (no extra arguments accepted). |
data |
Input tibble. Columns of Species, Residual, Covariate and CovariateValue |
fit |
The fitted runjags object. |
detectionresiduals |
Optional. A tibble of already calculated detection residuals.
Must have column names identical to output of |
varidx |
The index of the covariate to plot. If NULL, then all occupancy covariates will be plotted |
esttype |
The point estimate extracted from fit. Passed to |
occupancyresiduals |
Optional. A tibble of already calculated occupancy residuals.
Must have column names identical to output of |
The inclusion of a smoothed fit for easier interpretability follows suggestions by Warton et al (2017)
A ggplot object. Data is in the data
slot.
A ggplot object.
A ggplot object.
A ggplot object. Data is saved in the data
slot.
A ggplot object. Data is saved in the data
slot.
plot_residuals.residual
: For table of provided residuals and covariate values, makes residual plots.
Residual and covariate values must be provided with the ModelSite.
facet_species_covariate
: A function that prepares plot of residuals, one facet for each species and covariate
facet_covariate
: A function that prepares plot of residuals, one facet for each covariate. Species ignored.
plot_residuals_detection.fit
: Prepares tibbles and plots of residuals for covariates that are part of a fitted object
plot_residuals_occupancy.fit
: Prepares tibbles and plots of occupancy residuals for covariates that are part of a fitted object
D. I. Warton, J. Stoklosa, G. Guillera-Arroita, D. I. MacKenzie, and A. H. Welsh, "Graphical diagnostics for occupancy models with imperfect detection," Methods in Ecology and Evolution, vol. 8, no. 4, pp. 408-419, 2017, doi: 10.1111/2041-210X.12761.
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 | fit <- readRDS("./tmpdata/7_1_mcmcchain_20200424.rds")
fit <- runjags::add.summary(fit)
source("./R/calcpredictions.R")
source("./R/DS_residuals.R")
fit$data <- as_list_format(fit$data)
detection_resids <- ds_detection_residuals.fit(fit, type = "median", conditionalLV = FALSE)
# Plot Detection Residual
plt <- plot_residuals_detection.fit(fit, detection_resids, varidx = 2, aggregatefcn = max, conditionalLV = FALSE)
plt
plt + coord_cartesian(ylim = c(-1, +1))
plot_residuals_detection.fit(fit, varidx = 2, esttype = "median", conditionalLV = FALSE)
plot_residuals_detection.fit(fit, varidx = c(2, 3), esttype = "median",
plotfunction = facet_covariate, conditionalLV = FALSE) +
coord_cartesian(ylim = c(-1, +1))
plot_residuals_occupancy.fit(fit, varidx = 3, esttype = "median", conditionalLV = FALSE)
plot_residuals_occupancy.fit(fit, varidx = c(2, 3), esttype = "median",
plotfunction = facet_covariate, conditionalLV = FALSE)
# Residuals against an unincluded covariate:
source("./scripts/7_1_import_site_observations.R")
covar <- occ_covariates[ , "ms_cover", drop = FALSE] %>%
tibble::rowid_to_column(var = "ModelSite")
residuals <- ds_occupancy_residuals.fit(fit, type = "median", conditionalLV = FALSE)
pltobj <- plot_residuals.residual(residuals, covar,
plotfunction = facet_species_covariate)
pltobj + scale_y_continuous(name = "Occupancy Residuals")
pltobj + scale_y_continuous(name = "Occupancy Residuals") + coord_cartesian(ylim = c(-1, +1))
## Example using 7_2_1 data
data_7_2_1 <- readRDS("./private/data/clean/7_2_1_input_data.rds")
fitp <- readRDS("./tmpdata/7_2_2_detectiononly_smallAmodel_run_20200529.rds")
fit <- results.jags("./runjagsfiles_13", read.monitor = c("LV", fitp$monitor))
fit <- add.summary(fit)
covar <- data_7_2_1$plotsmerged_detection %>%
dplyr::select(-all_of(data_7_2_1$detection_data_specieslist)) %>%
dplyr::select_if(is.numeric) %>%
rename(ModelSite = ModelSiteID)
plot_residuals_detection.fit(fit, varidx = 2, esttype = "median", conditionalLV = TRUE) + coord_cartesian(ylim = c(-1, 1))
plt <- plot_LVvscovar.fit(fit, esttype = "median", covar = covar, aggregatefcn = min)
plt + coord_cartesian(ylim = c(-1, 1))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.