ensemble_model: Creates ensemble models from several algorithms

Description Usage Arguments Value See Also Examples

View source: R/ensemble_model.R

Description

This function reads the output of final_model for each species and multiple algorithms and builds a simple ensemble model by calculating the mean of the final models in order to obtain one model per species. It also calculates median, standard deviation and range (maximum - minimum)

Usage

1
2
3
4
5
6
ensemble_model(species_name, occurrences, lon = "lon", lat = "lat",
  models_dir = "./models", final_dir = "final_models",
  ensemble_dir = "ensemble", proj_dir = "present",
  which_final = c("raw_mean"), consensus = FALSE,
  consensus_level = 0.5, write_ensemble = TRUE, write_occs = F,
  write_map = F, scale_models = TRUE, ...)

Arguments

species_name

A character string with the species name. Because species name will be used as a directory name, avoid non-ASCII characters, spaces and punctuation marks. Recommendation is to adopt "Genus_species" format. See names in example_occs as an example

occurrences

A data frame with occurrence data. Data must have at least columns with latitude and longitude values of species occurrences. See example_occs as an example

lon

The name of the longitude column. Defaults to "lon"

lat

The name of the latitude column. Defaults to "lat"

models_dir

Folder path to save the output files. Defaults to "./models"

final_dir

Character. Name of the folder to save the output files. A subfolder will be created, defaults to "final_model"

ensemble_dir

Character string, name of the folder to save the output files. A subfolder will be created. Defaults to "ensemble"

proj_dir

Character. The name of the subfolder with the projection. Defaults to "present" but can be set according to the other projections (i.e. to execute the function in projected models)

which_final

Which final_model will be used? Currently it can be:

raw_mean

Continuous model generated by the mean of the raw models (scale from 0 to 1)

raw_mean_th

Cuts the raw_mean by the mean of the thresholds that maximize the selected evaluation metric (e.g. TSS (spec_sens) to make a binary model

raw_mean_cut

Recovers raw_mean values above the mean threshold that maximizes the selected evaluation metric (e.g. TSS (spec_sens) or other dismo thresholds). Generates a continuous model

bin_mean

The mean of the selected binary models. Generates a model in a discrete scale

bin_consensus

The binary consensus from bin_mean Parameter consensus_level must be defined, 0.5 means a majority consensus

cut_mean

The mean of the selected cut models. Values below the thresholds are down-weighted by zeros

consensus

Logical. If TRUE a consensus between the algorithms will be applied

consensus_level

Which proportion of binary models will be kept when creating bin_consensus

write_ensemble

Logical. If TRUE writes png files of the ensemble models

write_occs

Logical. If TRUE writes the occurrence points on the png file of the ensemble model

write_map

Logical. If TRUE adds a map contour to the png file of the ensemble models

scale_models

Logical. Whether input models should be scaled between 0 and 1

...

Other parameters from writeRaster

Value

Retuns a RasterStack with all generated statistics written in the ensemble_dir subfolder

Writes on disk raster files with the median, mean and standard deviation and range of the assembled models

If write_ensemble = TRUE writes .png figures in the ensemble_dir subfolder

See Also

final_model

Examples

 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
# run setup_sdmdata
sp <- names(example_occs)[1]
sp_coord <- example_occs[[1]]
sp_setup <- setup_sdmdata(species_name = sp,
                          occurrences = sp_coord,
                          predictors = example_vars)

# run do_many
sp_many <- do_many(species_name = sp,
                   predictors = example_vars,
                   bioclim = TRUE,
                   maxnet = TRUE)

# run final_model
sp_final <- final_model(species_name = sp,
                        algorithms = c("bioclim", "maxnet"),
                        select_partitions = TRUE,
                        select_par = "TSSmax",
                        select_par_val = 0,
                        which_models = c("raw_mean"),
                        consensus_level = 0.5,
                        overwrite = TRUE)

# run ensemble model
sp_ensemble <- ensemble_model(species_name = sp,
                              occurrences = sp_coord,
                              overwrite = TRUE)

Model-R/modleR documentation built on Dec. 3, 2019, 4:54 p.m.