| Title: | Modelling framework for hierachical ecological impact analysis |
|---|---|
| Description: | This package uses principles of hierarchical modelling to assess the impacts of land use and land-use intensity on ecological communities. Data and modelling approach originate from the PREDICTS framework and are adapted for use with alternative land-use categories (legends), integration of additional ecological data, modelling with frequentist and Bayesian approaches, and extended model evaluation. |
| Authors: | Richard Cornford [aut, cre] (ORCID: <https://orcid.org/0000-0002-9963-3603>), Martin Jung [aut] (ORCID: <https://orcid.org/0000-0002-7569-1390>) |
| Maintainer: | Richard Cornford <[email protected]> |
| License: | CC BY 4.0 |
| Version: | 0.1 |
| Built: | 2026-10-31 01:01:10 UTC |
| Source: | https://github.com/iiasa/hibiiscus |
Calculate the Area-of-Applicability (AOA) given a model, cross-validation output, and the data being used to make projection/prediction.
hib_calc_aoa(mod_obj, cv_obj, proj_data)hib_calc_aoa(mod_obj, cv_obj, proj_data)
mod_obj |
One of; |
cv_obj |
A |
proj_data |
A |
This function estimates an AOA, for each of the cross-validation approaches
supplied.
We follow the methods of Meyer and Pebesma 2021, to estimate a dissimilarity
index (DI) using model fitting/projection variables, and cross-validation
folds to estimate applicability limits.
See references for further information.
The returned list includes:
variable_weights, a data.frame of variable importance weights.
variable_scale_params, a list of the parameters used to scale each variable.
train_DI, a list containing DI estimates and thresholds per cross-validation type.
proj_aoa, the AOA output, where 1 indicates a location within the AOA, 0 outside the AOA,
same data type as proj_data.
list
Meyer, H., & Pebesma, E. (2021). Predicting into unknown space? Estimating the area of applicability of spatial prediction models. Methods in Ecology and Evolution, 12, 1620–1633. https://doi.org/10.1111/2041-210X.13650
Meyer H, Milà C, Ludwig M, Linnenbrink J (2023). CAST: 'caret' Applications for Spatial-Temporal Models. R package, https://CRAN.R-project.org/package=CAST.
## Not run: aoa_res <- hib_calc_aoa(mod_obj, cv_obj, proj_data) ## End(Not run)## Not run: aoa_res <- hib_calc_aoa(mod_obj, cv_obj, proj_data) ## End(Not run)
This function calculates a range of compositional dissimilarity/distance measures between sites (within studies) based on taxonomic diversity and for the associated HibDatabase.
hib_calc_div_between( obj, metrics, binary = FALSE, rel_abund = TRUE, rescale = TRUE, baseline_lui = "Primary vegetation_Minimal use" )hib_calc_div_between( obj, metrics, binary = FALSE, rel_abund = TRUE, rescale = TRUE, baseline_lui = "Primary vegetation_Minimal use" )
obj |
A |
metrics |
Character vector of dissimilarity/distance metrics.
Metrics available via |
binary |
Logical vector - should metric be calculated using occurence
values ( |
rel_abund |
Logical vector - determining whether relative abundance
should be used to calculate the dissimilarity metric, only applicable for some metrics,
e.g., euclidean, hypervolume.
Note: many metrics include rescaling of abundances as part of the calculation.
Default values is |
rescale |
Logical vector - determining if dissimilarity measure should
be rescaled relative to its maximum value - applies to metrics that are not
on a 0-1 scale by default - hypervolume, euclidean (if relative abundance),
chord, hellinger.
Default values is |
baseline_lui |
Character or NULL, indicating the baseline LUI/s against which compositional dissimilarity is calculated per study. If NULL, compositional dissimilarity is calculated between all sites within each study. Default values is 'Primary vegetation_Minimal use' - the most pristine LUI within the PREDICTS database. |
As is standard for R6 Classes, the HibDatabase is modified in-place.
If effort correction (hib_effort_correction()) has previously been conducted,
diversity metrics will be estimated using effort corrected measurements.
HibDatabase with updated '$diversity_between' tibble
## Not run: obj <- hib_calc_div_between(obj, c("bray", "jaccard"), c(F, T), c(T, F), c(F, F), "Primary vegetation_Minimal use") ## End(Not run)## Not run: obj <- hib_calc_div_between(obj, c("bray", "jaccard"), c(F, T), c(T, F), c(F, F), "Primary vegetation_Minimal use") ## End(Not run)
This function calculates multiple, user specified measures of site-level (taxonomic) diversity for sites in the associated HibDatabase.
hib_calc_div_within(obj, metrics)hib_calc_div_within(obj, metrics)
obj |
A |
metrics |
Character vector, any/all of; "Total_abundance", "Species_richness", "Chao1_diversity", "Simpson_diversity", "Rarefied_species_richness", "Mean_abundance", "Geometric_mean_abundance", "Shannon_diversity", "HillShannon_diversity", "HillSimpson_diversity", "PIE", "Equalness". Metrics can be provided in upper or lower case and as unambiguous abbreviations (internal processing is done using lower-case). |
As is standard for R6 Classes, the HibDatabase is modified in-place.
If effort correction (hib_effort_correction()) has previously been conducted,
diversity metrics will be estimated using effort corrected measurements.
HibDatabase with updated '$diversity_within' tibble
## Not run: hib_db <- hib_calc_div_within(hib_db, c("Total_abundance", "Species_richness")) ## End(Not run)## Not run: hib_db <- hib_calc_div_within(hib_db, c("Total_abundance", "Species_richness")) ## End(Not run)
This function calculates measures of differences between sites within a study,
which can then be used as covariates in models of compositional dis/similarity.
A data.frame (named site_contrasts) containing the site-contrast pairs
(SSBS1, SSBS2) and the associated 'differences' is added to the provided
HibDatabase.
hib_calc_site_contrasts( obj, metrics, custom_metric_specs = NULL, baseline_lui = "Primary vegetation_Minimal use", overwrite = FALSE )hib_calc_site_contrasts( obj, metrics, custom_metric_specs = NULL, baseline_lui = "Primary vegetation_Minimal use", overwrite = FALSE )
obj |
A |
metrics |
A |
custom_metric_specs |
A named
For example: |
baseline_lui |
A |
overwrite |
A |
The function currently returns site1-site2 contrasts for all within-study contrasts
where site1 has the baseline_lui. Subsequent, filtering to ensure contrasts
are based on the same effort level is recommended and may be incrporated in
future releases.
HibDatabase
https://adrianadepalma.github.io/BII_tutorial
## Not run: obj <- hib_calc_site_contrasts(obj, c("lui_contrast", "geogr_dist_hav"), baseline_lui = "Primary vegetation_Minimal use") ## End(Not run)## Not run: obj <- hib_calc_site_contrasts(obj, c("lui_contrast", "geogr_dist_hav"), baseline_lui = "Primary vegetation_Minimal use") ## End(Not run)
HibDatabase object from input filesThis function creates an R6 HibDatabase object containing the loaded
PREDICTS-like database.
hib_create_db(path_species, path_sites = "", dataset_name = "")hib_create_db(path_species, path_sites = "", dataset_name = "")
path_species |
A character pointing to a |
path_sites |
Optional character argument, pointing to a |
dataset_name |
A |
This function assumes that a species database file is explicitly provided,
with a site database file being optional.
Provided file paths are expected to include a '.rds' extension.
All files are loaded and compiled into a single database object that can be
stored for future use (see hib_save()).
This object is then used in other functions of this package to prepare or filter
the database and enable ecological impact analyses.
An object of class HibDatabase, containing site and species information
which can be further modified for subsequent ecological analysis.
Hudson, L.N., Newbold, T., Contu, S., Hill, S.L.L., Lysenko, I., De Palma, A., Phillips, H.R.P., Senior, R.A., Bennett, D.J., Booth, H., et al. (2014). The PREDICTS database: a global database of how local terrestrial biodiversity responds to human impacts. Ecol. Evol. 4, 4701–4735. 10.1002/ece3.1303.
Hudson, L.N., Newbold, T., Contu, S., Hill, S.L.L., Lysenko, I., De Palma, A., Phillips, H.R.P., Alhusseini, T.I., Bedford, F.E., Bennett, D.J., et al. (2017). The database of the PREDICTS (Projecting Responses of Ecological Diversity In Changing Terrestrial Systems) project. Ecol. Evol. 7, 145–188. 10.1002/ece3.2579.
Lawrence Hudson; Tim Newbold; Sara Contu; Samantha L L Hill et al. (2023). The 2016 release of the PREDICTS database V1.1. Natural History Museum. https://doi.org/10.5519/j4sh7e0w
Sara Contu; Adriana De Palma; Rachel Bates; Jessica Borer et al. (2022). Release of data added to the PREDICTS database (November 2022). Natural History Museum. https://doi.org/10.5519/jg7i52dg
## Not run: path_species <- "rawdata/PREDICTS/2016/database.rds" path_sites <- "rawdata/PREDICTS/2016/sites.rds" hibDB <- hib_create_db(path_species, path_sites) hibDB ## End(Not run)## Not run: path_species <- "rawdata/PREDICTS/2016/database.rds" path_sites <- "rawdata/PREDICTS/2016/sites.rds" hibDB <- hib_create_db(path_species, path_sites) hibDB ## End(Not run)
This function creates a R6 HibLULegend object containing the provided
land-use legend (i.e., linking sites, SSBS, to land-uses/intensities).
hib_create_lu_legend(input)hib_create_lu_legend(input)
input |
Either a |
The provided data.frame must include the following columns:
SSBS, Predominant_land_use, Use_intensity and LUI.
HibLULegend
## Not run: lu_leg <- hib_create_lu_legend("../Data/landuse_dataframe.rds") ## End(Not run)## Not run: lu_leg <- hib_create_lu_legend("../Data/landuse_dataframe.rds") ## End(Not run)
This function re-fits models on different subsets of the data, and estimates a range of error metrics allowing for evaluation of model predictive performance.
hib_cv_model( mod_obj, db_obj, fold_type, custom_col = NULL, random_seed = NULL, re_form = list(NA), backtransform = NULL, use_original_mesh = NULL )hib_cv_model( mod_obj, db_obj, fold_type, custom_col = NULL, random_seed = NULL, re_form = list(NA), backtransform = NULL, use_original_mesh = NULL )
mod_obj |
One of; |
db_obj |
A |
fold_type |
A |
custom_col |
A |
random_seed |
A |
re_form |
A |
backtransform |
A function to convert the model prediction back to the original scale of interest. The inverse of any transformation used in model fitting. |
use_original_mesh |
A |
This function allows for model evaluation using multiple cross-validation strategies, and multiple random effects structures. It returns a HibCV object, which includes the original model, insample and CV performance for multiple evaluation metrics, model coefficients estimated per cross-validation fold.
HibCV
## Not run: cv_out <- hib_cv_model(mod_obj, db_obj, fold_type = "Random-10") ## End(Not run)## Not run: cv_out <- hib_cv_model(mod_obj, db_obj, fold_type = "Random-10") ## End(Not run)
This function returns a database object containing only sites (and associated species) whose characteristics are retained.
hib_filter_sites(obj, condition)hib_filter_sites(obj, condition)
obj |
A |
condition |
An expression identifying how to filter the sites data.frame,
as would be passed to |
HibDatabase
## Not run: hib_obj <- hib_filter_sites(hib_obj, UN_region == "Europe") ## End(Not run)## Not run: hib_obj <- hib_filter_sites(hib_obj, UN_region == "Europe") ## End(Not run)
This function returns a database object containing only species (and associated sites) whose characteristics are retained.
hib_filter_species(obj, condition)hib_filter_species(obj, condition)
obj |
A |
condition |
An expression identifying how to filter the species data.frame,
as would be passed to |
HibDatabase
## Not run: hib_obj <- hib_filter_species(hib_obj, Class == "Insecta") ## End(Not run)## Not run: hib_obj <- hib_filter_species(hib_obj, Class == "Insecta") ## End(Not run)
This function fits a brms model using the supplied database, formula and other function arguments tuning the model fitting process.
hib_fit_brms( obj, form, family = stats::gaussian, weight_specs = list(weights = NULL, weight_type = NULL), scale_specs = list(covars_to_scale = NULL, scale_func = NULL), relevel_specs = c(NULL), ... )hib_fit_brms( obj, form, family = stats::gaussian, weight_specs = list(weights = NULL, weight_type = NULL), scale_specs = list(covars_to_scale = NULL, scale_func = NULL), relevel_specs = c(NULL), ... )
obj |
A |
form |
A |
family |
A |
weight_specs |
A named
Only applicable if a list of |
scale_specs |
A named
|
relevel_specs |
A |
... |
Any other named arguments that can be passed to |
This function takes the supplied database object (and various other arguments), fits the specified model and returns a HibModelBRMS object.
HibModelBRMS
Paul-Christian Bürkner (2017). brms: An R Package for Bayesian Multilevel Models Using Stan. Journal of Statistical Software, 80(1), 1-28. doi:10.18637/jss.v080.i01
Paul-Christian Bürkner (2018). Advanced Bayesian Multilevel Modeling with the R Package brms. The R Journal, 10(1), 395-411. doi:10.32614/RJ-2018-017
Paul-Christian Bürkner (2021). Bayesian Item Response Modeling in R with brms and Stan. Journal of Statistical Software, 100(5), 1-54. doi:10.18637/jss.v100.i05
## Not run: mod <- hib_fit_brms(obj, y ~ x + ( 1 | a ), ...) ## End(Not run)## Not run: mod <- hib_fit_brms(obj, y ~ x + ( 1 | a ), ...) ## End(Not run)
This function fits an INLA model using the supplied database, formula and other function arguments tuning the model fitting process
hib_fit_inla( obj, response_fixed_form, random_covar, family = "gaussian", fit_settings, incl_spatial_term = FALSE, input_mesh = NULL, mesh_settings = list(mesh_dim = "2d", max.edge = c(75, 100), cutoff = 1e-12, offset = NULL), scale_specs = list(covars_to_scale = NULL, scale_func = NULL), relevel_specs = c(NULL), prior_list )hib_fit_inla( obj, response_fixed_form, random_covar, family = "gaussian", fit_settings, incl_spatial_term = FALSE, input_mesh = NULL, mesh_settings = list(mesh_dim = "2d", max.edge = c(75, 100), cutoff = 1e-12, offset = NULL), scale_specs = list(covars_to_scale = NULL, scale_func = NULL), relevel_specs = c(NULL), prior_list )
obj |
A |
response_fixed_form |
A |
random_covar |
A |
family |
A |
fit_settings |
In development |
incl_spatial_term |
A |
input_mesh |
Optionally provide an INLA |
mesh_settings |
Optionally specify INLA mash settings, e.g., max.edge |
scale_specs |
A named
|
relevel_specs |
A |
prior_list |
In development |
This function takes the supplied database object (and various other arguments), fits the specified model and returns a HibModelINLA object. Still in development. Weighted data integration currently not implemented.
HibModelINLA
Havard Rue, Sara Martino, and Nicholas Chopin (2009), Approximate Bayesian Inference for Latent Gaussian Models Using Integrated Nested Laplace Approximations (with discussion), Journal of the Royal Statistical Society B, 71, 319-39
H. Rue, A. Riebler, S. H. Sorbye, J. B. Illian, D. P. Simpson, and F. K. Lindgren. Bayesian computing with INLA: A review. Annual Reviews of Statistics and Its Applications, 4(March):395-421, 2017. URL http://arxiv.org/abs/1604.00860
## Not run: mod <- hib_fit_inla(obj, y ~ -1 + Intercept + x, ~ f(a, model = "iid")) ## End(Not run)## Not run: mod <- hib_fit_inla(obj, y ~ -1 + Intercept + x, ~ f(a, model = "iid")) ## End(Not run)
This function fits an lme4 model using the supplied database, formula and other function arguments tuning the model fitting process.
hib_fit_lme4( obj, form, family = stats::gaussian, REML = TRUE, calc_CIs = NULL, optimise_ranefs = FALSE, model_dredge = FALSE, model_average = FALSE, weight_specs = list(weights = NULL, weight_type = NULL), scale_specs = list(covars_to_scale = NULL, scale_func = NULL), relevel_specs = c(NULL), ... )hib_fit_lme4( obj, form, family = stats::gaussian, REML = TRUE, calc_CIs = NULL, optimise_ranefs = FALSE, model_dredge = FALSE, model_average = FALSE, weight_specs = list(weights = NULL, weight_type = NULL), scale_specs = list(covars_to_scale = NULL, scale_func = NULL), relevel_specs = c(NULL), ... )
obj |
A |
form |
Model formula in the style of lme4 - including fixed and random effects. |
family |
A |
REML |
A |
calc_CIs |
An indication of whether fixed effect confidence intervals (95%) should be calculated or not, and if so how - one of NULL, "Wald", "profile", "boot". |
optimise_ranefs |
Not currently applicable - future dev |
model_dredge |
Not currently applicable - future dev |
model_average |
Not currently applicable - future dev |
weight_specs |
A named
Only applicable if a list of |
scale_specs |
A named
|
relevel_specs |
A |
... |
Any other named arguments that can be passed to |
This function takes the supplied database object (and various other arguments), fits the specified model and returns a HibModelLME4 object.
HibModelLME4
Douglas Bates, Martin Maechler, Ben Bolker, Steve Walker (2015). Fitting Linear Mixed-Effects Models Using lme4. Journal of Statistical Software, 67(1), 1-48. doi:10.18637/jss.v067.i01.
## Not run: mod <- hib_fit_lme4(obj, y ~ x + ( 1 | a ), ...) ## End(Not run)## Not run: mod <- hib_fit_lme4(obj, y ~ x + ( 1 | a ), ...) ## End(Not run)
This function joins external information to a HibDatabase object. Such
information could be for example additional site-contrast-specific data that
are not already present in the database.
hib_join_site_contrasts(obj, site_contrast_info)hib_join_site_contrasts(obj, site_contrast_info)
obj |
A |
site_contrast_info |
A |
HibDatabase
## Not run: hib_db <- hib_join_site_contrasts(hib_db, new_site_contrast_data_df) ## End(Not run)## Not run: hib_db <- hib_join_site_contrasts(hib_db, new_site_contrast_data_df) ## End(Not run)
This function joins external information to a HibDatabase object. Such
information could be for example additional site-specific data that are not
already present in the database.
hib_join_sites(obj, site_info)hib_join_sites(obj, site_info)
obj |
A |
site_info |
A |
HibDatabase
## Not run: hib_db <- hib_join_sites(hib_db, new_site_data_df) ## End(Not run)## Not run: hib_db <- hib_join_sites(hib_db, new_site_data_df) ## End(Not run)
This function joins external information to a HibDatabase object. Such
information could be for example prepared data on species traits.
hib_join_species(obj, spp_info)hib_join_species(obj, spp_info)
obj |
A |
spp_info |
A |
HibDatabase
## Not run: hib_db <- hib_join_species(hib_db, new_spp_data_df) ## End(Not run)## Not run: hib_db <- hib_join_species(hib_db, new_spp_data_df) ## End(Not run)
Load a hibiiscus object from a saved RDS.
hib_load(path)hib_load(path)
path |
A |
The function loads the hibiiscus object from the specified file location.
If the original object (HibProjection) included SpatRaster data, this
will be loaded from the appropriate tif file/s.
A hibiiscus object, one of: HibDatabase, HibLULegend,
HibModelLME4, HibModelINLA, HibModelBRMS, HibCV, HibProjection
## Not run: hib_obj <- hib_load("an/example/file_path/hib_model.rds") ## End(Not run)## Not run: hib_obj <- hib_load("an/example/file_path/hib_model.rds") ## End(Not run)
This function projects a fitted HibModelXXX using the supplied model object and data to be used in projection.
hib_project_model( mod_obj, data, backtransform = NULL, rescale_specs = NULL, lme4_specs = NULL, inla_specs = NULL, brms_specs = NULL, calc_aoa = FALSE, cv_obj = NULL )hib_project_model( mod_obj, data, backtransform = NULL, rescale_specs = NULL, lme4_specs = NULL, inla_specs = NULL, brms_specs = NULL, calc_aoa = FALSE, cv_obj = NULL )
mod_obj |
One of; |
data |
A |
backtransform |
A |
rescale_specs |
A named
In combination, these arguments determine if predictions will be rescaled or not
( |
lme4_specs |
A named
|
inla_specs |
A named
|
brms_specs |
A named
|
calc_aoa |
A |
cv_obj |
A |
Given a HibModelXXX, new data and specification, this function projects/predicts
modelled responses for each 'unit' of the new data.
Calculation of the 'Area-of-Applicability' of the model within the new data is
an optional addition.
Specification arguments allow for customisation of the prediction type.
If specifications are not provided, defaults will be used.
Projections will be returned in the same format as the provided data.
If data is provided as SpatRaster, a land-use variable should be included
as a single categorical layer, or as multiple, proportional layers, named to
align with the levels of the categorical variable.
Currently, only a single 'categorical' variable can be provided in
'proportional cover' format in a SpatRaster.
HibProjection
Meyer, H., & Pebesma, E. (2021). Predicting into unknown space? Estimating the area of applicability of spatial prediction models. Methods in Ecology and Evolution, 12, 1620–1633. https://doi.org/10.1111/2041-210X.13650
Meyer H, Milà C, Ludwig M, Linnenbrink J (2023). CAST: 'caret' Applications for Spatial-Temporal Models. R package, https://CRAN.R-project.org/package=CAST.
HibProjection
hib_calc_aoa
predict.merMod
fitted.brmsfit
predict.brmsfit
## Not run: proj <- hib_mod_project(hib_model, proj_data) ## End(Not run)## Not run: proj <- hib_mod_project(hib_model, proj_data) ## End(Not run)
Saves a hibiiscus data object to disk.
hib_save(obj, path, overwrite = FALSE)hib_save(obj, path, overwrite = FALSE)
obj |
A hibiiscus object, one of: |
path |
A |
overwrite |
A |
The function saves the hibiiscus object in the specified file location.
If the object (HibProjection) includes SpatRaster data, this will
be separately saved in '.tif' file/s, with the same base-path.
## Not run: hib_save(model_obj, "an/example/file_path/hib_model.rds", T) ## End(Not run)## Not run: hib_save(model_obj, "an/example/file_path/hib_model.rds", T) ## End(Not run)
HibLULegend as the LU legend in a HibDatabase
This function adds the HibLULegend to the HibDatabase, modifying both the
sites and species data.frames.
hib_set_lu_legend(obj, leg)hib_set_lu_legend(obj, leg)
obj |
A |
leg |
A |
This function updates (and therefore overwrites) the previous
Predominant_land_use, Use_intensity and LUI columns in both the sites
and species data.frames.
HibDatabase
## Not run: obj <- hib_set_lu_legend(obj, leg) ## End(Not run)## Not run: obj <- hib_set_lu_legend(obj, leg) ## End(Not run)
HibDatabase with further dataThis function updates an existing HibDatabase, for example by adding
the 2022 version of the PREDICTS data to the 2016 version.
hib_update_db(obj, path_species, path_sites = "", dataset_name = "")hib_update_db(obj, path_species, path_sites = "", dataset_name = "")
obj |
A |
path_species |
A character pointing to a |
path_sites |
Optional character argument, pointing to a |
dataset_name |
A |
Newly provided data (from files) will be appended to the previously created
HibDatabase. Species data will be added to the species data.frame, and
site data to the site data.frame.
Meta-data/descriptors in the HibDatabase will be updated to reflect
the additions.
Note: Prior filtering/processing of the initial HibDatabase will not
be applied to the newly provided data. Please load all data of interest into
the HibDatabase prior to further processing.
The updated HibDatabase object, with the supplied dataset added to its site and species data.
Hudson, L.N., Newbold, T., Contu, S., Hill, S.L.L., Lysenko, I., De Palma, A., Phillips, H.R.P., Senior, R.A., Bennett, D.J., Booth, H., et al. (2014). The PREDICTS database: a global database of how local terrestrial biodiversity responds to human impacts. Ecol. Evol. 4, 4701–4735. 10.1002/ece3.1303.
Hudson, L.N., Newbold, T., Contu, S., Hill, S.L.L., Lysenko, I., De Palma, A., Phillips, H.R.P., Alhusseini, T.I., Bedford, F.E., Bennett, D.J., et al. (2017). The database of the PREDICTS (Projecting Responses of Ecological Diversity In Changing Terrestrial Systems) project. Ecol. Evol. 7, 145–188. 10.1002/ece3.2579.
Lawrence Hudson; Tim Newbold; Sara Contu; Samantha L L Hill et al. (2023). The 2016 release of the PREDICTS database V1.1. Natural History Museum. https://doi.org/10.5519/j4sh7e0w
Sara Contu; Adriana De Palma; Rachel Bates; Jessica Borer et al. (2022). Release of data added to the PREDICTS database (November 2022). Natural History Museum. https://doi.org/10.5519/jg7i52dg
## Not run: path_species <- "rawdata/PREDICTS/2016/database.rds" path_sites <- "rawdata/PREDICTS/2016/sites.rds" hibDB <- hib_create_db(path_species, path_sites, "predicts_2016") path_species_upd <- "rawdata/PREDICTS/2022/database2ndrelease.rds" hibDB <- update_hib(hibDB, path_species_upd, "", "predicts_2022") hibDB ## End(Not run)## Not run: path_species <- "rawdata/PREDICTS/2016/database.rds" path_sites <- "rawdata/PREDICTS/2016/sites.rds" hibDB <- hib_create_db(path_species, path_sites, "predicts_2016") path_species_upd <- "rawdata/PREDICTS/2022/database2ndrelease.rds" hibDB <- update_hib(hibDB, path_species_upd, "", "predicts_2022") hibDB ## End(Not run)
This is the template object for a an R6 class containing the results of cross-validation. It contains functions for summarising and visualising the results.
Template object for cross-validation results
last_update(character)
Identifies the most recent update to the object (YYYY-MM-DD).
model_type(character)
Identifies the type of model; one of "HibModelLME4",
"HibModelINLA", "HibModelBRMS".
original_model_obj(list)
Contains a list of core model information
cv_results(list)
Contains the list of results from cross-validation
insample_results(list)
Contains the list of results from in-sample validation
re_form(list)
A list of the re_form model structures used in evaluation.
use_original_mesh(logical or NULL)
Indicates use of original mesh for spatial INLA models.
HibCV$new()Creates a new instance of this R6 class. Note, this object is constructed via the hib_cv_model function found within this package.
HibCV$new(mod_obj, cv_res, insamp_res, re_form, use_orig_mesh)
mod_obj(HibModelXXXX)
The model object used in cross-validation.
cv_res(list)
The results of cross-validation.
insamp_res(list)
The results of ins-sample validation.
re_form(list)
The list of random effects structures used in model evaluation.
use_orig_mesh(logical or NULL)
Indicates use of original mesh for spatial INLA models
(HibCV)
HibCV$print()Base printout function presents core information about the object.
HibCV$print()
(NULL).
HibCV$plot()Function to generate figures summarising the cross- validation results.
HibCV$plot(type = "metrics", metrics = c("rmse", "rsq"))
type(character()) Options are: "coefficients",
"coefficients-summary", "obs-v-pred", "obs-v-error",
"pred-v-error", "metrics", "map-sites".
metrics(character) Options are the lower-case
abbreviations of calculated error metrics. - Only needed
if type == "metrics".
(ggplot).
HibCV$clone()The objects of this class are cloneable with this method.
HibCV$clone(deep = FALSE)
deepWhether to make a deep clone.
This is the template object for an R6 database containing PREDICTS or PREDICTS-like data. Functions are provided to prepare the data for modelling and visualise the data.
Template objects for databases
dataset_name(character())
Identifies the dataset used.
last_update(character())
Identifies the most recent update to the Database (YYYY-MM-DD).
paths(list())
Identifies the files used to create the Database object.
sites(data.frame)
Stores information on the sites within the Database.
species(data.frame)
Stores information on the species within the Database.
diversity_within(tibble)
Stores information on biodiversity metrics calculated for
each site (i.e. alpha diversity).
diversity_between(tibble)
Stores information on biodiversity metrics calculated
between sites, within studies (i.e. beta diversity).
site_contrasts(data.frame)
Stores information on 'distances' between sites, within
studies (e.g., geographic distance).
processing_flags(list())
Stores information on processing that has occurred (e.g.,
filtering data, adding data).
HibDatabase$new()Creates a new instance of this R6 class. Note, this object is constructed via the hib_create_db and hib_update_db functions found within this package.
HibDatabase$new(dataset_name, paths)
dataset_name(character())
Text indicating the dataset contributing to the database being created.
paths(list())
List of paths to the 'species' and 'site' data to be loaded.
(HibDatabase)
HibDatabase$checkself()Self check function to ensure that the site and species data.frames contain the correct columns and align in content.
HibDatabase$checkself(sites = self$sites, species = self$species)
sites(data.frame).
species(data.frame).
(NULL).
HibDatabase$print()Base printout function presents core information about the Database object.
HibDatabase$print()
(NULL).
HibDatabase$hib_effort_correction()Function to apply effort correction to the species data. Uses a simple, linear scaling, such that sampling effort of a site is scaled relative to the maximum value per study, and multiplied by the original measure of diversity.
HibDatabase$hib_effort_correction()
(HibDatabase).
HibDatabase$plot()Function to generate figures summarising the site-level data present in the HibDatabase.
HibDatabase$plot(type = "map-sites")
type(character()) Options are: "map-sites",
"map-studies", "biome-N", "ecoregion-N", "realm-N", "class-N".
(ggplot).
HibDatabase$clone()The objects of this class are cloneable with this method.
HibDatabase$clone(deep = FALSE)
deepWhether to make a deep clone.
De Palma, A., Abrahamczyk, S., Aizen, M. et al. Predicting bee community responses to land-use changes: Effects of geographic and taxonomic biases. Sci Rep 6, 31153 (2016). https://doi.org/10.1038/srep31153
This is the template object for an R6 land-use legend that can be linked to a HibDatabase object. The legend should contain information on land-use and management/intensity types for sites with the database.
Template object for land-use legend
last_update(character())
Identifies the most recent update to the legend object (YYYY-MM-DD)
input_data(character())
Identifies the source of the input data, either "file ([...])",
or "dataframe [...]".
lu_df(data.frame)
Contains the LU legend dataframe, i.e, A data.frame
containing columns for "SSBS", "Predominant_land_use",
"Use_intensity" and "LUI".
land_use(character())
The unique values of lu_df$Predominant_land_use.
management(character())
The unique values of lu_df$Use_intensity
land_use_management(character())
The unique values of lu_df$LUI
HibLULegend$new()Creates a new instance of this R6 class. Note, this object is constructed via the hib_create_lu_legend function found within this package.
HibLULegend$new(input, input_chr)
input(character() (rds filepath) or data.frame)
The source data used to generate the LU legend
input_chr(character())
Text indicating the source of the data.
(HibLULegend)
HibLULegend$checkself()Self check function to ensure that the legend data.frame contains the correct columns.
HibLULegend$checkself(df = self$lu_df)
df(data.frame).
(NULL).
HibLULegend$print()Base printout function presents core information about the object.
HibLULegend$print()
(NULL).
HibLULegend$plot()Function to generate figures summarising the data present in the LU legend
HibLULegend$plot(x_var = "land-use")
x_var(character()) Options are: "land-use",
"use-intensity", "land-use:use-intensity".
(ggplot).
HibLULegend$clone()The objects of this class are cloneable with this method.
HibLULegend$clone(deep = FALSE)
deepWhether to make a deep clone.
This is the template object for an R6 brms model class.
It contains functions for summarising and visualising the model results.
Template object for brms model
dataset_name(character)
Identifies the dataset used.
last_update(character)
Identifies the most recent update to the object (YYYY-MM-DD).
data(data.frame)
The data used in model fitting.
model(brmsfit)
The brms model object.
extra_args(list())
Identifies addition arguments supplied during model
fitting (found in '...' when calling hib_fit_brms).
fixedef_coefficients(data.frame)
The fixed effects coefficients.
metrics(list)
List containing model performance metrics.
processing_flags(list())
Identifies the processing steps used for the HibDatabase
object that was used for model fitting.
site_locations(data.frame)
Contains columns for "SSBS", "Longitude" ,"Latitude"
HibModelBRMS$new()Creates a new instance of this R6 class. Note, this object is constructed via the hib_fit_brms function found within this package.
HibModelBRMS$new( db_obj, mod_df, brms_obj, fixef_df, metr_ls, n_spp, n_taxa, n_sites, extra_args )
db_obj(HibDatabase, or list)
The HibDatabase object/s used to fit the model.
mod_df(data.frame)
The data.frame of the data used in model fitting.
brms_obj(brmsfit)
The brms model object.
fixef_df(data.frame)
The fixed effects from the fitted model.
metr_ls(list)
The list of model performance metrics.
n_spp(integer or list)
Number of species contributing to the fitted model.
n_taxa(integer or list)
Number of orignal taxa names contributing to the fitted model.
n_sites(integer or list)
Number of sites contributing to the fitted model.
extra_args(list)
Additional arguments specified during model fitting.
@return (HibModelBRMS)
HibModelBRMS$print()Base printout function presents core information about the object.
HibModelBRMS$print()
(NULL).
HibModelBRMS$plot()Function to generate figures summarising the model.
HibModelBRMS$plot(type = "fixed-effects")
type(character()) Options are: "fixed-effects",
"random-effects", "map-sites".
(ggplot).
HibModelBRMS$check_model()Function to assess the model using the performance package.
HibModelBRMS$check_model()
(NULL).
HibModelBRMS$clone()The objects of this class are cloneable with this method.
HibModelBRMS$clone(deep = FALSE)
deepWhether to make a deep clone.
This is the template object for an R6 INLA model class.
It contains functions for summarising and visualising the model results.
Template object for INLA model
dataset_name(character)
Identifies the dataset used.
last_update(character)
Identifies the most recent update to the object (YYYY-MM-DD).
data(data.frame)
The data used in model fitting.
model(inla)
The INLA::inla model object.
processing_flags(list())
Identifies the processing steps used for the HibDatabase
object that was used for model fitting.
fixedef_coefficients(data.frame)
The fixed effects coefficients.
user_formula(formula or list)
The model formula supplied by the user (includes
the fixed effects and non-spatial random effects).
inla_fitted_formula(formula)
The fitted model formula (includes all effects).
inla_incl_spatial_term(logical)
TRUE or FALSE, does the model include a spatial term.
inla_stack(inla.data.stack)
The data.stack used in model fitting, an INLA object.
inla_mesh(inla.mesh or NULL)
If used, the mesh used in model fitting.
inla_mesh_settings(list)
A list of specifications for generating the mesh,
if used in modelling.
inla_mesh_source(character or NULL)
A description of the mesh source - if not null,
can be either "user_provided" or "mesh_settings".
site_locations(data.frame)
Contains columns for "SSBS", "Longitude" ,"Latitude".
HibModelINLA$new()Creates a new instance of this R6 class. Note, this object is constructed via the hib_fit_inla function found within this package.
HibModelINLA$new( db_obj, mod_df, inla_obj, fixef_df, user_formula, inla_fitted_formula, inla_incl_spatial_term, inla_stack, inla_mesh, inla_mesh_settings, inla_mesh_source, n_spp, n_taxa, n_sites )
db_obj(HibDatabase, or list)
The HibDatabase object/s used to fit the model.
mod_df(data.frame)
The data.frame of the data used in model fitting.
inla_obj(inla)
The inla model object.
fixef_df(data.frame)
The fixed effects from the fitted model.
user_formula(formula or list)
The model formula supplied by the user.
inla_fitted_formula(formula)
The fitted model formula.
inla_incl_spatial_term(logical)
TRUE or FALSE, does the model include a spatial term.
inla_stack(inla.data.stack)
The data.stack used in model fitting, an INLA object.
inla_mesh(inla.mesh or NULL)
If used, the mesh used in model fitting.
inla_mesh_settings(list)
A list of specifications for generating the mesh.
inla_mesh_source(character or NULL)
A description of the mesh source.
n_spp(integer)
Number of species contributing to the fitted model.
n_taxa(integer)
Number of orignal taxa names contributing to the fitted model.
n_sites(integer)
Number of sites contributing to the fitted model.
@return (HibModelINLA)
metr_ls(list)
The list of model performance metrics.
HibModelINLA$print()Base printout function presents core information about the object.
HibModelINLA$print()
(NULL).
HibModelINLA$plot()Function to generate figures summarising the model.
HibModelINLA$plot(type = "fixed-effects")
type(character()) Options are: "fixed-effects",
"random-effects", "spatial-random-field", "map-sites".
(ggplot).
HibModelINLA$clone()The objects of this class are cloneable with this method.
HibModelINLA$clone(deep = FALSE)
deepWhether to make a deep clone.
This is the template object for an R6 lme4 model class.
It contains functions for summarising and visualising the model results.
Template object for lme4 model
dataset_name(character)
Identifies the dataset used.
last_update(character)
Identifies the most recent update to the object (YYYY-MM-DD).
data(data.frame)
The data used in model fitting.
model(merMod)
The lme4 model object.
fixedef_coefficients(data.frame)
The fixed effects coefficients.
ci_type(character, or NA)
Identifies the types of confidence intervals calculated.
metrics(numeric)
Named vector containing model performance metrics.
processing_flags(list())
Identifies the processing steps used for the HibDatabase
object that was used for model fitting.
site_locations(data.frame)
Contains columns for "SSBS", "Longitude" ,"Latitude".
HibModelLME4$new()Creates a new instance of this R6 class. Note, this object is constructed via the hib_fit_lme4 function found within this package.
HibModelLME4$new( db_obj, mod_df, lme4_obj, fixef_df, ci_type, metr_vec, n_spp, n_taxa, n_sites )
db_obj(HibDatabase, or list)
The HibDatabase object/s used to fit the model.
mod_df(data.frame)
The data.frame of the data used in model fitting.
lme4_obj(merMod)
The lme4 model object.
fixef_df(data.frame)
The fixed effects from the fitted model.
ci_type(character, or NA)
The type of confidence intervals calculated.
metr_vec(numeric)
The named vector of model performance metrics.
n_spp(integer or list)
Number of species contributing to the fitted model.
n_taxa(integer or list)
Number of orignal taxa names contributing to the fitted model.
n_sites(integer or list)
Number of sites contributing to the fitted model.
@return (HibModelLME4)
HibModelLME4$print()Base printout function presents core information about the object.
HibModelLME4$print()
(NULL).
HibModelLME4$plot()Function to generate figures summarising the model.
HibModelLME4$plot(type = "fixed-effects")
type(character()) Options are: "fixed-effects",
"random-effects", "map-sites".
(ggplot).
HibModelLME4$check_model()Function to assess the model using the performance package.
HibModelLME4$check_model()
(NULL).
HibModelLME4$clone()The objects of this class are cloneable with this method.
HibModelLME4$clone(deep = FALSE)
deepWhether to make a deep clone.
This is the template object for a an R6 class containing the results of projecting a fitted HibModel based on data of interest. It contains functions for summarising and visualising the results.
Template object for projection results
last_update(character)
Identifies the most recent update to the object (YYYY-MM-DD).
model(R6)
The model used to project, one of HibModelLME4,
HibModelINLA, HibModelBRMS.
projection(data.frame, SpatRaster, or list)
The results of model projection.
projection_specs(list)
List of specifications used for modelling.
aoa(list)
Results of Area-of-Applicability calculations.
HibProjection$new()Creates a new instance of this R6 class. Note, this object is constructed via the hib_project_model function found within this package.
HibProjection$new( obj, proj, backtransform, rescale_specs, lme4_specs, inla_specs, brms_specs, aoa_res )
obj(HibModelXXXX)
The model object used in cross-validation.
proj(data.frame, SpatRaster, or list)
The results of model projection.
backtransform(function or NULL)
Describes the backtransformation specified when
making a model projection.
rescale_specs(list)
List of specifications used for rescaling predictions.
lme4_specs(list)
List of specifications used for lme4 models.
inla_specs(list)
List of specifications used for inla models.
brms_specs(list)
List of specifications used for brms models.
aoa_res(list, or NULL)
List of Area-of-Applicability results.
(HibProjection)
HibProjection$print()Base printout function presents core information about the object.
HibProjection$print()
(NULL).
HibProjection$plot()Function to generate figures summarising the projection results.
HibProjection$plot( type = "response-map", response_var = NULL, uncertainty_var = NULL, aoa_mask = FALSE, aoa_var = NULL )
type(character()) Options are:
"response-map", "uncertainty-map", "bivariate-map",
"response-distr", "uncertainty-distr", "bivariate-distr".
response_var(character, or NULL)
uncertainty_var(character, or NULL)
aoa_mask(logical)
aoa_var(character, or NULL)
(ggplot).
HibProjection$clone()The objects of this class are cloneable with this method.
HibProjection$clone(deep = FALSE)
deepWhether to make a deep clone.
Function to format a prepared GLOBIOM netCDF file for use in Hibiiscus projections.
prep_globiom( file_path, out_as_rast = TRUE, incl_pixel_area = TRUE, vars_to_include = NULL, vars_to_ignore = NULL )prep_globiom( file_path, out_as_rast = TRUE, incl_pixel_area = TRUE, vars_to_include = NULL, vars_to_ignore = NULL )
file_path |
A filepath ( |
out_as_rast |
A |
incl_pixel_area |
A |
vars_to_include |
A |
vars_to_ignore |
A |
This function expects a downscaled GLOBIOM output. Variables are extracted and converted to raster format, with each raster stack representing a particular year. Likely of little use for anyone outside IIASA.
A (list of) SpatRaster stacks with the formatted GLOBIOM predictors.
## Not run: # Expects a filename pointing to a globiom-netCDF file. globiom_rast <- prep_globiom("path/to/globiom_data.nc") ## End(Not run)## Not run: # Expects a filename pointing to a globiom-netCDF file. globiom_rast <- prep_globiom("path/to/globiom_data.nc") ## End(Not run)