Returns various evaluation metrics from predicts::pa_evaluate()
and
flexsdm::sdm_eval()
.
Arguments
- m
SDM result within
tune_sdm()
- p_test
Presence test data generated within
tune_sdm()
- b_test
Background test data generated within
tune_sdm()
- do_gc
Logical. Run
base::rm(list = ls)
andbase::gc()
at end of function? Useful when running SDMs for many, many taxa, especially if done in parallel. Note, actually useesrm(list = ls(pattern = "^[^e$]"))
.- ...
Passed to both
terra::predict()
andpredicts::pa_evaluate()
Value
paModelEvaluation (see predicts::pa_evaluate()
) with extra metrics
from flexsdm::sdm_eval()
: AUC as auc_po_flexsdm; BOYCE as CBI; CBI_rescale
(CBI is -1 to 1, CBI_rescale is 0 to 1); and IMAE.
Examples
out_dir <- file.path(system.file(package = "envSDM"), "examples")
source(fs::path(out_dir, "tune_sdm_ex.R")) # make sure following prep file exists
#> Warning: Missing `trust` will be set to FALSE by default for RDS in 2.0.0.
#> Warning: Missing `trust` will be set to FALSE by default for RDS in 2.0.0.
#> Warning: Missing `trust` will be set to FALSE by default for RDS in 2.0.0.
#> Warning: Missing `trust` will be set to FALSE by default for RDS in 2.0.0.
#> Warning: There were 2 warnings in `dplyr::mutate()`.
#> The first warning was:
#> ℹ In argument: `tune = purrr::map(tune, rio::import)`.
#> Caused by warning:
#> ! Missing `trust` will be set to FALSE by default for RDS in 2.0.0.
#> ℹ Run dplyr::last_dplyr_warnings() to see the 1 remaining warning.
#> Warning: There were 2 warnings in `dplyr::mutate()`.
#> The first warning was:
#> ℹ In argument: `tune = purrr::map(tune, rio::import)`.
#> Caused by warning:
#> ! Missing `trust` will be set to FALSE by default for RDS in 2.0.0.
#> ℹ Run dplyr::last_dplyr_warnings() to see the 1 remaining warning.
prep <- rio::import(fs::path(out_dir, "acaule", "prep.rds"))
#> Warning: Missing `trust` will be set to FALSE by default for RDS in 2.0.0.
model <- tune_sdm(prep = prep
, out_dir = FALSE
, return_val = "object"
, algo = "rf"
, trees = 500
, mtry = 2
, nodesize = 1
, keep_model = TRUE
)
#> tuning acaule
#> out_dir is H:/temp/nige\Rtmpk9T0CA\file44e41a463367
#> rf tune
#> Joining with `by = join_by(algo)`
#> Joining with `by = join_by(metric)`
#> Joining with `by = join_by(algo, tune_args, trees, nodesize)`
presences <- prep$blocks[prep$blocks$pa == 1 & prep$blocks$block != 1, ]
background <- prep$blocks[prep$blocks$pa == 0 & prep$blocks$block != 1, ]
evaluate_sdm(model$tune_rf$m[[1]]
, p_test = presences
, b_test = background
)
#> @stats
#> np na prevalence auc cor pcor ODP auc_po auc_po_flexsdm CBI
#> 1 458 4521 0.092 1 0.937 0 0.908 1 1 0.904
#> CBI_rescale IMAE
#> 1 0.952 0.972
#>
#> @thresholds
#> max_kappa max_spec_sens no_omission equal_prevalence equal_sens_spec
#> 1 0.93 0.618 0.618 0.092 0.69
#>
#> @tr_stats
#> treshold kappa CCR TPR TNR FPR FNR PPP NPP MCR OR
#> 1 0 0 0.09 1 0 1 0 0.09 NaN 0.91 NaN
#> 2 0 0.15 0.54 1 0.49 0.51 0 0.17 1 0.46 Inf
#> 3 0 0.2 0.62 1 0.58 0.42 0 0.19 1 0.38 Inf
#> 4 ... ... ... ... ... ... ... ... ... ... ...
#> 143 1 0.87 0.98 0.79 1 0 0.21 1 0.98 0.02 Inf
#> 144 1 0.87 0.98 0.79 1 0 0.21 1 0.98 0.02 Inf
#> 145 1 0 0.91 0 1 0 1 NaN 0.91 0.09 NaN