spat_strat | R Documentation |
This function sets up the variables used spatial stratification sampling to
be used in the bootstrapped modeling approach in oneimpact.
The function defines the hierarchical levels H0,
used for block cross-validation, as well as the levels H1 and H2, used for setting the
spatial structure of the sampling for model fitting and tuning.
Levels H1 and and H2 are organized in hierarchical spatial blocks. Blocks H1 correspond
to larger square blocks, each of which is subdivided into four, smaller H2 blocks
(with side equal block_size
). H2 blocks are separated
spatially so that 3 of them are used for model fitting the the fourth is used for
model tuning.
The level H0 comes from the data set and should represent some other level for
block cross validation, such as population ID, animal ID, year or study area.
The block H0 is used for drawing validation sets, to allow a thorough evaluation
of the fitted models in all blocks H0.
spat_strat(
x,
colH0 = NULL,
colID = NULL,
H1_as_H0 = FALSE,
k = 4,
block_size = 10000,
buffer = 1000,
coords = NULL,
all_cols = FALSE,
crs = "",
plot_grid = TRUE,
save_grid = c(NA_character_, "raster", "vector")[1]
)
x |
|
colH0 |
|
H1_as_H0 |
|
k |
|
block_size |
|
buffer |
|
coords |
string,vector |
all_cols |
|
crs |
|
plot_grid |
|
save_grid |
|
col_id |
|
The function returns a data.frame
with the blocks for the hierarchical
levels H0, H1, and H2 for each observation in the input data set,
to be used to create samples for the bootstrapped modeling
approach using the create_samples()
function, in case spatial
stratified samples are desired.
A data.frame
with the blocks at hierarchical levels H0, H1, and H2 corresponding to
each of the observations in the input data set x
.
To be implemented for input = data.frame #terra::vect(datadata$case==1,, geom = c("x", "y")) To be implemented for track objects - already have crs Put H0 here as well.
data(reindeer)
library(terra)
library(amt)
# no block H0, spatial blocks
spat_strat(reindeer, block_size = 5000, coords = c("x", "y"))
# with block H0
spst <- spat_strat(reindeer, coords = c("x", "y"), colH0 = "original_animal_id",
all_cols = TRUE)
# Visualize level H0 - individuals
spst_vect <- terra::vect(spst, geom = c("x", "y"))
terra::plot(spst_vect, "blockH0")
# Visualize level H1
terra::plot(spst_vect, "blockH1", type = "classes")
# Visualize level H2 for blockH1 numbers 6 to 10
terra::plot(spst_vect, col = grey(0.7))
terra::plot(spst_vect[spst$blockH1 == 6], "blockH2", type = "classes", add = TRUE) # only 6
terra::plot(spst_vect[spst$blockH1 %in% c(6,7,10,11)], "blockH2", type = "classes", add = TRUE) # 6-10
terra::plot(spst_vect[spst$blockH1 == 6], "blockH2", type = "classes") # zoom to 6
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.