Skip to contents

Create a weighted or unweighted ensemble of SDM predictions, including associated uncertainty values

Usage

ensemble_create(x, x.idx, w = NULL, x.var.idx = NULL, ...)

# S3 method for sf
ensemble_create(x, x.idx, w = NULL, x.var.idx = NULL, ...)

# S3 method for data.frame
ensemble_create(x, x.idx, w = NULL, x.var.idx = NULL, ...)

Arguments

x

object of class sf or class data.frame

x.idx

vector of column names or numerical indices; indicates which columns in x will be used to create the ensemble

w

weights for the ensemble; either a numeric vector the same length as x or a data frame (or tibble) with the same number of rows as x and ncol(w) == length(x.idx). If w is a numeric vector, its values (i.e. the weights) must sum to 1. The default value is 1 / length(x.idx), i.e. an unweighted ensemble

x.var.idx

vector of column names or column indices; indicates columns in x with variance values with which to calculate uncertainty values for the ensemble. If x.var.idx is specified, it must be the same length as x.idx. Use x.var.idx = NULL (the default) if none of the predictions have associated uncertainty values; in this case the uncertainty values for the ensemble will be calculated using the among-model uncertainty. See the 'Details' section for more information

...

Arguments to be passed to methods; specifically designed for passing na.rm argument to sum

Value

An object of the same class as x with two columns appended to the data frame:

  • 'Pred_ens' - The ensemble predictions

  • 'Var_ens' - The variance of the ensemble predictions, calculated using either the within-model uncertainty (if x.var.idx is specified) or the among-model uncertainty (if x.var.idx is NULL)

Note that all other columns of x will be included in the returned object. Also, if x is of class sf then 1) the geometry list-column will be the last column of the returned object and 2) the agr attribute will be set as 'constant' for 'Pred_ens' and 'Var_ens'

Details

ensemble_create is designed to be used after overlaying predictions with overlay_sdm and (if desired) rescaling the overlaid predictions with ensemble_rescale.

This function implements ensemble methods provided in eSDM_GUI. Note that it does not implement regional exclusion, which must be done manually if not using the GUI.

Ensemble uncertainty is calculated using either the within-model uncertainty (if x.var.idx is specified) or the among-model uncertainty (if x.var.idx is NULL). See the eSDM GUI manual for applicable formulas.

Examples

ensemble_create(preds.1, c("Density", "Density2"), c(0.2, 0.8))
#> Simple feature collection with 325 features and 6 fields
#> Attribute-geometry relationships: constant (6)
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -123 ymin: 32 xmax: -117 ymax: 35
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> Geodetic CRS:  WGS 84
#> First 10 features:
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#>       Density   Density2         Var1         Var2   Pred_ens      Var_ens
#> 1  0.18149697 0.28017854 0.0006178977 6.782811e-03 0.26044222 1.558088e-03
#> 2  0.02813584 0.38707710 0.0041072496 7.100138e-03 0.31528885 2.061421e-02
#> 3  0.06602004 0.18568142 0.0060756461 2.152463e-03 0.16174914 2.291015e-03
#> 4  0.02904423 0.93583648 0.0030639979 7.415022e-03 0.75447803 1.315635e-01
#> 5  0.03662517 0.01805658 0.0009543514 2.318842e-03 0.02177030 5.516681e-05
#> 6  0.04675287 0.60902020 0.0081108828 1.309096e-05 0.49656674 5.058313e-02
#> 7  0.02349130 0.71603927 0.0068363941 2.566385e-04 0.57752967 7.673963e-02
#> 8  0.02890871 0.93743528 0.0047392882 7.242310e-03 0.75572996 1.320673e-01
#> 9  0.04262853 0.05042882 0.0038668358 5.157556e-03 0.04886876 9.735136e-06
#> 10 0.14753231 0.65324162 0.0071928494 7.077782e-03 0.55209976 4.091871e-02
#>                          geometry
#> 1  POLYGON ((-122.875 32.125, ...
#> 2  POLYGON ((-122.625 32.125, ...
#> 3  POLYGON ((-122.375 32.125, ...
#> 4  POLYGON ((-122.125 32.125, ...
#> 5  POLYGON ((-121.875 32.125, ...
#> 6  POLYGON ((-121.625 32.125, ...
#> 7  POLYGON ((-121.375 32.125, ...
#> 8  POLYGON ((-121.125 32.125, ...
#> 9  POLYGON ((-120.875 32.125, ...
#> 10 POLYGON ((-120.625 32.125, ...
ensemble_create(preds.1, 1:2, c(0.2, 0.8), c("Var1", "Var2"))
#> Simple feature collection with 325 features and 6 fields
#> Attribute-geometry relationships: constant (6)
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -123 ymin: 32 xmax: -117 ymax: 35
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> Geodetic CRS:  WGS 84
#> First 10 features:
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#>       Density   Density2         Var1         Var2   Pred_ens      Var_ens
#> 1  0.18149697 0.28017854 0.0006178977 6.782811e-03 0.26044222 0.0043657149
#> 2  0.02813584 0.38707710 0.0041072496 7.100138e-03 0.31528885 0.0047083781
#> 3  0.06602004 0.18568142 0.0060756461 2.152463e-03 0.16174914 0.0016206025
#> 4  0.02904423 0.93583648 0.0030639979 7.415022e-03 0.75447803 0.0048681740
#> 5  0.03662517 0.01805658 0.0009543514 2.318842e-03 0.02177030 0.0015222329
#> 6  0.04675287 0.60902020 0.0081108828 1.309096e-05 0.49656674 0.0003328135
#> 7  0.02349130 0.71603927 0.0068363941 2.566385e-04 0.57752967 0.0004377044
#> 8  0.02890871 0.93743528 0.0047392882 7.242310e-03 0.75572996 0.0048246499
#> 9  0.04262853 0.05042882 0.0038668358 5.157556e-03 0.04886876 0.0034555096
#> 10 0.14753231 0.65324162 0.0071928494 7.077782e-03 0.55209976 0.0048174942
#>                          geometry
#> 1  POLYGON ((-122.875 32.125, ...
#> 2  POLYGON ((-122.625 32.125, ...
#> 3  POLYGON ((-122.375 32.125, ...
#> 4  POLYGON ((-122.125 32.125, ...
#> 5  POLYGON ((-121.875 32.125, ...
#> 6  POLYGON ((-121.625 32.125, ...
#> 7  POLYGON ((-121.375 32.125, ...
#> 8  POLYGON ((-121.125 32.125, ...
#> 9  POLYGON ((-120.875 32.125, ...
#> 10 POLYGON ((-120.625 32.125, ...
ensemble_create(data.frame(a = 1:5, b = 3:7), c(1, 2))
#>   a b Pred_ens Var_ens
#> 1 1 3        2       1
#> 2 2 4        3       1
#> 3 3 5        4       1
#> 4 4 6        5       1
#> 5 5 7        6       1

weights.df <- data.frame(runif(325), c(rep(NA, 100), runif(225)))
ensemble_create(preds.1, c("Density", "Density2"), weights.df, na.rm = TRUE)
#> Simple feature collection with 325 features and 6 fields
#> Attribute-geometry relationships: constant (6)
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -123 ymin: 32 xmax: -117 ymax: 35
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> Geodetic CRS:  WGS 84
#> First 10 features:
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#> old-style crs object detected; please recreate object with a recent sf::st_crs()
#>       Density   Density2         Var1         Var2   Pred_ens Var_ens
#> 1  0.18149697 0.28017854 0.0006178977 6.782811e-03 0.18149697       0
#> 2  0.02813584 0.38707710 0.0041072496 7.100138e-03 0.02813584       0
#> 3  0.06602004 0.18568142 0.0060756461 2.152463e-03 0.06602004       0
#> 4  0.02904423 0.93583648 0.0030639979 7.415022e-03 0.02904423       0
#> 5  0.03662517 0.01805658 0.0009543514 2.318842e-03 0.03662517       0
#> 6  0.04675287 0.60902020 0.0081108828 1.309096e-05 0.04675287       0
#> 7  0.02349130 0.71603927 0.0068363941 2.566385e-04 0.02349130       0
#> 8  0.02890871 0.93743528 0.0047392882 7.242310e-03 0.02890871       0
#> 9  0.04262853 0.05042882 0.0038668358 5.157556e-03 0.04262853       0
#> 10 0.14753231 0.65324162 0.0071928494 7.077782e-03 0.14753231       0
#>                          geometry
#> 1  POLYGON ((-122.875 32.125, ...
#> 2  POLYGON ((-122.625 32.125, ...
#> 3  POLYGON ((-122.375 32.125, ...
#> 4  POLYGON ((-122.125 32.125, ...
#> 5  POLYGON ((-121.875 32.125, ...
#> 6  POLYGON ((-121.625 32.125, ...
#> 7  POLYGON ((-121.375 32.125, ...
#> 8  POLYGON ((-121.125 32.125, ...
#> 9  POLYGON ((-120.875 32.125, ...
#> 10 POLYGON ((-120.625 32.125, ...