Skip to contents

Obtain the Partial Dependence Plots (PDP) to each variable.

Usage

pdp_sdm(i, spp = NULL, algo = NULL, variables_selected = NULL, mean.only = FALSE)

get_pdp_sdm(i, spp = NULL, algo = NULL, variables_selected = NULL)

Arguments

i

A input_sdm object.

spp

A character vector with species names to obtain the PDPs. If NULL (standard), the first species in species_names(i) is used.

algo

A character containing the algorithm to obtain the PDP. If NULL (standard) all algorithms are mixed.

variables_selected

A character. If there is a subset of predictors that should be ploted in this, it can be informed using this parameter.

mean.only

Boolean. Should only the mean curve be plotted or a curve to each run should be included? Standard is FALSE.

Value

A plot (for pdp_sdm) or a data.frame (for get_pdp_sdm) with PDP values.

See also

Author

Luíz Fernando Esser (luizesser@gmail.com) https://luizfesser.wordpress.com

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="bioclim", n_set=3)

# Custom trainControl:
ctrl_sdm <- caret::trainControl(method = "repeatedcv",
                                number = 2,
                                repeats = 1,
                                classProbs = TRUE,
                                returnResamp = "all",
                                summaryFunction = summary_sdm,
                                savePredictions = "all")
# Train models:
i <- train_sdm(i, algo = c("naive_bayes"), ctrl=ctrl_sdm)
#> Warning: There were missing values in resampled performance measures.
# PDP plots:
pdp_sdm(i)
#> `geom_smooth()` using method = 'loess' and formula = 'y ~ x'

get_pdp_sdm(i)
#> $naive_bayes
#> # A tibble: 156 × 4
#>    id     yhat variable value
#>    <chr> <dbl> <chr>    <dbl>
#>  1 m1.1  0.996 bio1      15.9
#>  2 m1.1  0.996 bio1      16.1
#>  3 m1.1  0.998 bio1      16.3
#>  4 m1.1  0.998 bio1      16.6
#>  5 m1.1  0.999 bio1      16.8
#>  6 m1.1  0.999 bio1      17.1
#>  7 m1.1  1.00  bio1      17.3
#>  8 m1.1  1.00  bio1      17.6
#>  9 m1.1  1.00  bio1      17.8
#> 10 m1.1  0.999 bio1      18.1
#> # ℹ 146 more rows
#>