fit_raf | R Documentation |
Fit and validate Random Forests models
fit_raf(
data,
response,
predictors,
predictors_f = NULL,
fit_formula = NULL,
partition,
thr = NULL,
mtry = sqrt(length(c(predictors, predictors_f))),
ntree = 500
)
data |
data.frame. Database with response (0,1) and predictors values. |
response |
character. Column name with species absence-presence data (0,1). |
predictors |
character. Vector with the column names of quantitative predictor variables (i.e. continuous variables). Usage predictors = c("aet", "cwd", "tmin") |
predictors_f |
character. Vector with the column names of qualitative predictor variables (i.e. ordinal or nominal variables type). Usage predictors_f = c("landform") |
fit_formula |
formula. A formula object with response and predictor variables (e.g. formula(pr_ab ~ aet + ppt_jja + pH + awc + depth + landform)). Note that the variables used here must be consistent with those used in response, predictors, and predictors_f arguments. Default NULL |
partition |
character. Column name with training and validation partition groups. |
thr |
character. Threshold used to get binary suitability values (i.e. 0,1), needed for threshold-dependent performance metrics. More than one threshold type can be used. It is necessary to provide a vector for this argument. The following threshold criteria are available:
If more than one threshold type is used they must be concatenated, e.g., thr=c('lpt', 'max_sens_spec', 'max_jaccard'), or thr=c('lpt', 'max_sens_spec', 'sensitivity', sens='0.8'), or thr=c('lpt', 'max_sens_spec', 'sensitivity'). Function will use all thresholds if no threshold is specified. |
mtry |
numeric. Number of variables randomly sampled as candidates at each split. Default sqrt(length(c(predictors, predictors_f))) |
ntree |
numeric. Number of trees to grow. Default 500 |
A list object with:
model: A "randomForest" class object from randomForest package. This object can be used for predicting.
predictors: A tibble with quantitative (c column names) and qualitative (f column names) variables use for modeling.
performance: Performance metrics (see sdm_eval
).
Threshold dependent metrics are calculated based on the threshold specified in the argument.
data_ens: Predicted suitability for each test partition. This database is used in fit_ensemble
fit_gam
, fit_gau
, fit_gbm
,
fit_glm
, fit_max
, fit_net
, and fit_svm
.
## Not run:
data("abies")
# Using k-fold partition method
abies2 <- part_random(
data = abies,
pr_ab = "pr_ab",
method = c(method = "kfold", folds = 10)
)
abies2
rf_t1 <- fit_raf(
data = abies2,
response = "pr_ab",
predictors = c("aet", "ppt_jja", "pH", "awc", "depth"),
predictors_f = c("landform"),
partition = ".part",
thr = c("max_sens_spec", "equal_sens_spec", "max_sorensen"),
fit_formula = NULL
)
rf_t1$model
rf_t1$predictors
rf_t1$performance
rf_t1$data_ens
# Using bootstrap partition method and only with presence-absence
# and get performance for several method
abies2 <- part_random(
data = abies,
pr_ab = "pr_ab",
method = c(method = "boot", replicates = 10, proportion = 0.7)
)
abies2
rf_t2 <- fit_raf(
data = abies2,
response = "pr_ab",
predictors = c("aet", "ppt_jja", "pH", "awc", "depth"),
predictors_f = c("landform"),
partition = ".part",
thr = c("max_sens_spec", "equal_sens_spec", "max_sorensen"),
fit_formula = NULL,
mtry = 2,
ntree = 500
)
rf_t2
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.