# NOT RUN {
library(ggplot2)
library(dplyr)
library(sf)
library(sfheaders)
library(blockCV)
growth_ex %>%
ggplot() +
geom_sf()
growth_ex %>%
group_by(sp) %>%
summarize(mean(growth))
# Add buffer
growth_spatial_ex <- growth_ex %>%
add_buffer_variable(direction = "in", size = 1, region = study_region_ex)
# Add cross-validation folds
fold1 <- rbind(c(0, 0), c(5, 0), c(5, 5), c(0, 5), c(0, 0))
fold2 <- rbind(c(5, 0), c(10, 0), c(10, 5), c(5, 5), c(5, 0))
blocks <- bind_rows(
sf_polygon(fold1),
sf_polygon(fold2)
) %>%
mutate(foldID = c(1, 2))
SpatialBlock_ex <- spatialBlock(
speciesData = growth_ex,
verbose = FALSE,
k = 2,
selection = "systematic",
blocks = blocks
)
# Add foldID to data
growth_spatial_ex <- growth_spatial_ex %>%
mutate(foldID = SpatialBlock_ex$foldID %>% as.factor())
# }
Run the code above in your browser using DataLab