if (FALSE) {
# download example data
path <- ebirdst_download("example_data", tifs_only = FALSE)
# or get the path if you already have the data downloaded
path <- get_species_path("example_data")
# test data to sample
preds <- load_predictions(path, return_sf = TRUE)
# sample on a 100, 4 month grid
s <- sample_grid(preds, res = 100000, t_res = 1 / 4)
preds_grid <- preds[s, ]
# case control sampling independently samples presence and absence
s <- sample_case_control(preds, res = 1000000, t_res = 1 / 12)
preds_cc <- preds[s, ]
# grid sampling preserves the presence/absence ratio
table(preds$obs > 0) / nrow(preds)
table(preds_grid$obs > 0) / nrow(preds_grid)
# while case control sampling increases the prevelance of presences
table(preds_cc$obs > 0) / nrow(preds_cc)
# plot
library(sf)
p <- par(mar = c(0, 0, 0, 0))
plot(st_geometry(preds), col = "black", pch = 19, cex = 0.2)
plot(st_geometry(preds_cc), col = "red", pch = 19, cex = 0.5, add = TRUE)
}
Run the code above in your browser using DataLab