## ----sdm22a------------------------------------------------------------------- library(predicts) f <- system.file("ex/bio.tif", package="predicts") predictors <- rast(f) predictors names(predictors) plot(predictors) ## ----sdm23a------------------------------------------------------------------- library(geodata) wrld <- world(path=".") file <- paste(system.file(package="predicts"), "/ex/bradypus.csv", sep="") bradypus <- read.table(file, header=TRUE, sep=',') # we do not need the first column bradypus <- bradypus[,-1] ## ----sdm23b------------------------------------------------------------------- # first layer of the SpatRaster plot(predictors, 1) lines(wrld) points(bradypus, col='blue') ## ----sdm24a------------------------------------------------------------------- presvals <- extract(predictors, bradypus) # remove the ID variable presvals <- presvals[,-1] # setting random seed to always create the same # random set of points for this example set.seed(0) backgr <- spatSample(predictors, 500, "random", as.points=TRUE, na.rm=TRUE) absvals <- values(backgr) pb <- c(rep(1, nrow(presvals)), rep(0, nrow(absvals))) sdmdata <- data.frame(cbind(pb, rbind(presvals, absvals))) head(sdmdata) tail(sdmdata) summary(sdmdata) ## ----sdm24b------------------------------------------------------------------- pairs(sdmdata[,2:5], cex=0.1) ## ----sdm24b2------------------------------------------------------------------ saveRDS(sdmdata, "sdm.Rds") saveRDS(presvals, "pvals.Rds")