Skip to contents

Rescale SDM predictions and (if applicable) associated uncertainties

Usage

ensemble_rescale(x, x.idx, y, y.abund = NULL, x.var.idx = NULL)

Arguments

x

object of class sf

x.idx

vector of column names or column indices; indicates columns in x with prediction values that will be rescaled

y

rescaling method; must be either "abundance" or "sumto1". See 'Details' section for descriptions of the rescaling methods

y.abund

numeric value; ignored if y is not "abundance"

x.var.idx

vector of column names or column indices; indicates columns in x with variance values that will be rescaled. 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; see the 'Details' section for more information

Value

The sf object x with the columns specified by x.idx and x.var.idx rescaled. The agr attributes of x will be conserved

Details

ensemble_rescale is intended to be used after overlaying predictions with overlay_sdm and before creating ensembles with ensemble_create. The provided rescaling methods are:

  • 'abundance' - Rescale the density values so that the predicted abundance is y.abund

  • 'sumto1' - Rescale the density values so their sum is 1

SDM uncertainty values must be rescaled differently than the prediction values. Columns specified in x.var.idx must contain variance values. These values will be rescaled using the formula var(c * x) = c^2 * var(x), where c is the rescaling factor for the associated predictions.

If x.var.idx is not NULL, then the function assumes x.var.idx[1] contains the variance values associated with the predictions in x.idx[1], x.var.idx[2] contains the variance values associated with the predictions in x.idx[2], etc. Use NA in x.var.idx to indicate a set of predictions that does not have associated uncertainty values (e.g., x.var.idx = c(4, NA, 5))

Examples

ensemble_rescale(preds.1, c("Density", "Density2"), "abundance", 50)
#> Simple feature collection with 325 features and 4 fields
#> Attribute-geometry relationships: constant (4)
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -123 ymin: 32 xmax: -117 ymax: 35.03686
#> Geodetic CRS:  WGS 84
#> First 10 features:
#>         Density     Density2        Var1         Var2
#> 1  8.014377e-05 0.0003903286 0.004881167 5.813315e-04
#> 2  1.242396e-05 0.0002700312 0.008067182 4.260565e-04
#> 3  2.915252e-05 0.0001959982 0.002044914 8.936224e-03
#> 4  1.282508e-05 0.0003877259 0.004061446 4.281218e-04
#> 5  1.617261e-05 0.0003516557 0.009396155 6.683912e-03
#> 6  2.064470e-05 0.0004962905 0.008085898 9.530925e-05
#> 7  1.037307e-05 0.0001445535 0.008159037 6.253449e-03
#> 8  1.276524e-05 0.0005284574 0.008667279 1.936805e-03
#> 9  1.882351e-05 0.0001335137 0.001207384 4.332171e-03
#> 10 6.514596e-05 0.0002387673 0.003063388 7.799161e-03
#>                          geometry
#> 1  POLYGON ((-123 32, -122.875...
#> 2  POLYGON ((-122.625 32.00828...
#> 3  POLYGON ((-122.375 32.01319...
#> 4  POLYGON ((-122.125 32.0176,...
#> 5  POLYGON ((-121.875 32.02153...
#> 6  POLYGON ((-121.625 32.02496...
#> 7  POLYGON ((-121.375 32.0279,...
#> 8  POLYGON ((-121.125 32.03036...
#> 9  POLYGON ((-120.875 32.03232...
#> 10 POLYGON ((-120.625 32.03379...
ensemble_rescale(preds.1, c(1, 2), "sumto1")
#> Simple feature collection with 325 features and 4 fields
#> Attribute-geometry relationships: constant (4)
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -123 ymin: 32 xmax: -117 ymax: 35.03686
#> Geodetic CRS:  WGS 84
#> First 10 features:
#>         Density    Density2        Var1         Var2
#> 1  0.0009493594 0.004478398 0.004881167 5.813315e-04
#> 2  0.0001471706 0.003098178 0.008067182 4.260565e-04
#> 3  0.0003453322 0.002248767 0.002044914 8.936224e-03
#> 4  0.0001519221 0.004448537 0.004061446 4.281218e-04
#> 5  0.0001915759 0.004034689 0.009396155 6.683912e-03
#> 6  0.0002445511 0.005694143 0.008085898 9.530925e-05
#> 7  0.0001228764 0.001658521 0.008159037 6.253449e-03
#> 8  0.0001512133 0.006063207 0.008667279 1.936805e-03
#> 9  0.0002229778 0.001531857 0.001207384 4.332171e-03
#> 10 0.0007716998 0.002739474 0.003063388 7.799161e-03
#>                          geometry
#> 1  POLYGON ((-123 32, -122.875...
#> 2  POLYGON ((-122.625 32.00828...
#> 3  POLYGON ((-122.375 32.01319...
#> 4  POLYGON ((-122.125 32.0176,...
#> 5  POLYGON ((-121.875 32.02153...
#> 6  POLYGON ((-121.625 32.02496...
#> 7  POLYGON ((-121.375 32.0279,...
#> 8  POLYGON ((-121.125 32.03036...
#> 9  POLYGON ((-120.875 32.03232...
#> 10 POLYGON ((-120.625 32.03379...

ensemble_rescale(
  preds.1, c("Density", "Density2"), "abundance", 100, c(3,4)
)
#> Simple feature collection with 325 features and 4 fields
#> Attribute-geometry relationships: constant (4)
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -123 ymin: 32 xmax: -117 ymax: 35.03686
#> Geodetic CRS:  WGS 84
#> First 10 features:
#>         Density     Density2         Var1         Var2
#> 1  1.602875e-04 0.0007806571 3.807013e-09 7.130261e-10
#> 2  2.484793e-05 0.0005400624 6.291912e-09 5.225751e-10
#> 3  5.830505e-05 0.0003919964 1.594909e-09 1.096063e-08
#> 4  2.565017e-05 0.0007754518 3.167681e-09 5.251084e-10
#> 5  3.234522e-05 0.0007033113 7.328429e-09 8.198083e-09
#> 6  4.128941e-05 0.0009925810 6.306508e-09 1.169006e-10
#> 7  2.074615e-05 0.0002891069 6.363553e-09 7.670103e-09
#> 8  2.553049e-05 0.0010569148 6.759950e-09 2.375568e-09
#> 9  3.764703e-05 0.0002670274 9.416861e-10 5.313579e-09
#> 10 1.302919e-04 0.0004775345 2.389256e-09 9.565980e-09
#>                          geometry
#> 1  POLYGON ((-123 32, -122.875...
#> 2  POLYGON ((-122.625 32.00828...
#> 3  POLYGON ((-122.375 32.01319...
#> 4  POLYGON ((-122.125 32.0176,...
#> 5  POLYGON ((-121.875 32.02153...
#> 6  POLYGON ((-121.625 32.02496...
#> 7  POLYGON ((-121.375 32.0279,...
#> 8  POLYGON ((-121.125 32.03036...
#> 9  POLYGON ((-120.875 32.03232...
#> 10 POLYGON ((-120.625 32.03379...