## ---- echo=FALSE, include=FALSE----------------------------------------------- library(knitr) opts_chunk$set(fig.width = 6, fig.height = 6, fig.cap = '', collapse = TRUE) library(dismo) ## ---- sdm22a------------------------------------------------------------------ path <- file.path(system.file(package="dismo"), 'ex') ## ---- sdm22b------------------------------------------------------------------ library(dismo) files <- list.files(path, pattern='grd$', full.names=TRUE ) files ## ---- sdm22c------------------------------------------------------------------ predictors <- stack(files) predictors names(predictors) plot(predictors) ## ---- sdm23a------------------------------------------------------------------ library(maptools) data(wrld_simpl) file <- paste(system.file(package="dismo"), "/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 RasterStack plot(predictors, 1) # note the "add=TRUE" argument with plot plot(wrld_simpl, add=TRUE) # with the points function, "add" is implicit points(bradypus, col='blue') ## ---- sdm24a------------------------------------------------------------------ presvals <- extract(predictors, bradypus) # setting random seed to always create the same # random set of points for this example set.seed(0) backgr <- randomPoints(predictors, 500) absvals <- extract(predictors, backgr) pb <- c(rep(1, nrow(presvals)), rep(0, nrow(absvals))) sdmdata <- data.frame(cbind(pb, rbind(presvals, absvals))) sdmdata[,'biome'] = as.factor(sdmdata[,'biome']) head(sdmdata) tail(sdmdata) summary(sdmdata) ## ---- sdm24b------------------------------------------------------------------ pairs(sdmdata[,2:5], cex=0.1) ## ---- sdm24b2----------------------------------------------------------------- saveRDS(sdmdata, "sdm.Rds") saveRDS(presvals, "pvals.Rds")