
sdm_as_X
functions to transform caretSDM
data into other classes.
Source: R/sdm_as.R
sdm_as_stars.Rd
This functions transform data from a caretSDM
object to be used in other packages.
Usage
sdm_as_stars(x,
what = NULL,
spp = NULL,
scen = NULL,
id = NULL,
ens = NULL)
sdm_as_raster(x, what = NULL, spp = NULL, scen = NULL, id = NULL, ens = NULL)
sdm_as_terra(x, what = NULL, spp = NULL, scen = NULL, id = NULL, ens = NULL)
Arguments
- x
A
caretSDM
object.- what
Sometimes multiple data inside
x
could be transformed. This parameter allows users to specify what needs to be converted.It can be one of: "predictors", "scenarios", "predictions" or "ensembles".- spp
character
. Which species should be converted?- scen
character
. Which scenario should be converted?- id
character
. Which id should be converted?- ens
character
. Which ensemble should be converted?
Examples
# Create sdm_area object:
sa <- sdm_area(parana, cell_size = 100000, crs = 6933)
#> ! Making grid over study area is an expensive task. Please, be patient!
#> ℹ Using GDAL to make the grid and resample the variables.
# Include predictors:
sa <- add_predictors(sa, bioc) |> select_predictors(c("bio1", "bio12"))
#> ! Making grid over the study area is an expensive task. Please, be patient!
#> ℹ Using GDAL to make the grid and resample the variables.
# Include scenarios:
sa <- add_scenarios(sa)
# Create occurrences:
oc <- occurrences_sdm(occ, crs = 6933) |> join_area(sa)
#> Warning: Some records from `occ` do not fall in `pred`.
#> ℹ 2 elements from `occ` were excluded.
#> ℹ If this seems too much, check how `occ` and `pred` intersect.
# Create input_sdm:
i <- input_sdm(oc, sa)
# Pseudoabsence generation:
i <- pseudoabsences(i, method="random", n_set=2)
# Custom trainControl:
ctrl_sdm <- caret::trainControl(method = "boot",
number = 1,
classProbs = TRUE,
returnResamp = "all",
summaryFunction = summary_sdm,
savePredictions = "all")
# Train models:
i <- train_sdm(i, algo = c("naive_bayes"), ctrl=ctrl_sdm) |>
suppressWarnings()
# Predict models:
i <- predict_sdm(i, th=0.8)
#> [1] "Projecting: 1/1"
#> [1] "Ensembling..."
#> [1] "current"
#> [1] "Araucaria angustifolia"
# Transform in stars:
sdm_as_stars(i)
#> stars object with 1 dimensions and 2 attributes
#> attribute(s):
#> Min. 1st Qu. Median Mean 3rd Qu.
#> cell_id 2.0000000000 10.5000000 18.0000000 18.1111111 25.5000000
#> mean_occ_prob 0.0001950093 0.3517835 0.8884193 0.6700133 0.9488596
#> Max.
#> cell_id 34.0000000
#> mean_occ_prob 0.9983319
#> dimension(s):
#> from to refsys point
#> geometry 1 27 WGS 84 / NSIDC EASE-Grid ... FALSE
#> values
#> geometry POLYGON ((-5201744 -27950...,...,POLYGON ((-4801744 -31950...