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)
#> 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()
#> 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()
#> 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()
#> 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()
#> 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()
#> 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()
#> 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
#> 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
#> 1  7.974472e-05 1.529132e-04 0.0006178977 6.782811e-03
#> 2  1.236210e-05 2.112553e-04 0.0041072496 7.100138e-03
#> 3  2.900737e-05 1.013395e-04 0.0060756461 2.152463e-03
#> 4  1.276122e-05 5.107520e-04 0.0030639979 7.415022e-03
#> 5  1.609208e-05 9.854752e-06 0.0009543514 2.318842e-03
#> 6  2.054191e-05 3.323853e-04 0.0081108828 1.309096e-05
#> 7  1.032142e-05 3.907932e-04 0.0068363941 2.566385e-04
#> 8  1.270168e-05 5.116246e-04 0.0047392882 7.242310e-03
#> 9  1.872979e-05 2.752257e-05 0.0038668358 5.157556e-03
#> 10 6.482159e-05 3.565201e-04 0.0071928494 7.077782e-03
#>                          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_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
#> 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
#> 1  0.0009493594 0.0017608119 0.0006178977 6.782811e-03
#> 2  0.0001471706 0.0024326274 0.0041072496 7.100138e-03
#> 3  0.0003453322 0.0011669347 0.0060756461 2.152463e-03
#> 4  0.0001519221 0.0058813643 0.0030639979 7.415022e-03
#> 5  0.0001915759 0.0001134785 0.0009543514 2.318842e-03
#> 6  0.0002445511 0.0038274525 0.0081108828 1.309096e-05
#> 7  0.0001228764 0.0045000253 0.0068363941 2.566385e-04
#> 8  0.0001512133 0.0058914121 0.0047392882 7.242310e-03
#> 9  0.0002229778 0.0003169253 0.0038668358 5.157556e-03
#> 10 0.0007716998 0.0041053668 0.0071928494 7.077782e-03
#>                          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_rescale(
  preds.1, c("Density", "Density2"), "abundance", 100, c(3,4)
)
#> 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()
#> 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()
#> 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()
#> 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()
#> 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()
#> 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()
#> 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
#> 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
#> 1  1.594894e-04 3.058264e-04 4.771354e-10 8.081463e-09
#> 2  2.472421e-05 4.225106e-04 3.171583e-09 8.459546e-09
#> 3  5.801473e-05 2.026789e-04 4.691563e-09 2.564579e-09
#> 4  2.552245e-05 1.021504e-03 2.365993e-09 8.834719e-09
#> 5  3.218416e-05 1.970950e-05 7.369421e-10 2.762813e-09
#> 6  4.108382e-05 6.647706e-04 6.263155e-09 1.559739e-11
#> 7  2.064285e-05 7.815864e-04 5.279006e-09 3.057751e-10
#> 8  2.540336e-05 1.023249e-03 3.659638e-09 8.628939e-09
#> 9  3.745958e-05 5.504514e-05 2.985938e-09 6.145034e-09
#> 10 1.296432e-04 7.130402e-04 5.554258e-09 8.432909e-09
#>                          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, ...