make_spatial_fold {spatialRF} | R Documentation |
Makes one training and one testing spatial folds
Description
Used internally by make_spatial_folds()
and rf_evaluate()
. Uses the coordinates of a point xy.i
to generate two spatially independent data folds from the data frame xy
. It does so by growing a rectangular buffer from xy.i
until a number of records defined by training.fraction
is inside the buffer. The indices of these records are then stored as "training" in the output list. The indices of the remaining records outside of the buffer are stored as "testing". These training and testing records can be then used to evaluate a model on independent data via cross-validation.
Usage
make_spatial_fold(
data = NULL,
dependent.variable.name = NULL,
xy.i = NULL,
xy = NULL,
distance.step.x = NULL,
distance.step.y = NULL,
training.fraction = 0.8
)
Arguments
data |
Data frame with a response variable and a set of predictors. Default: |
dependent.variable.name |
Character string with the name of the response variable. Must be in the column names of |
xy.i |
One row data frame with at least three columns: "x" (longitude), "y" (latitude), and "id" (integer, id of the record). Can be a row of |
xy |
A data frame with at least three columns: "x" (longitude), "y" (latitude), and "id" (integer, index of the record). Default: |
distance.step.x |
Numeric, distance step used during the growth in the x axis of the buffers defining the training folds. Default: |
distance.step.y |
Numeric, distance step used during the growth in the y axis of the buffers defining the training folds. Default: |
training.fraction |
Numeric, fraction of the data to be included in the training fold, Default: |
Value
A list with two slots named training
and testing
with the former having the indices of the training records selected from xy
, and the latter having the indices of the testing records.
See Also
make_spatial_folds()
, rf_evaluate()
Examples
if(interactive()){
#loading example data
data(plant_richness_df)
#getting case coordinates
xy <- plant_richness_df[, 1:3]
colnames(xy) <- c("id", "x", "y")
#building a spatial fold centered in the first pair of coordinates
out <- make_spatial_fold(
xy.i = xy[1, ],
xy = xy,
training.fraction = 0.6
)
#indices of the training and testing folds
out$training
out$testing
#plotting the data
plot(xy[ c("x", "y")], type = "n", xlab = "", ylab = "")
#plots training points
points(xy[out$training, c("x", "y")], col = "red4", pch = 15)
#plots testing points
points(xy[out$testing, c("x", "y")], col = "blue4", pch = 15)
#plots xy.i
points(xy[1, c("x", "y")], col = "black", pch = 15, cex = 2)
}