# load random species distributions
library(SESraster)
library(terra)
r <- load_ext_data()
plot(r)
# applying the function
rand.str <- bootspat_str(r)
plot(rand.str)
# With null probability raster
rprobnull <- terra::app(r,
function(x){
ifelse(is.na(x), NA, 1)
})
rand.str2 <- bootspat_str(r, rprob = rprobnull)
library(SESraster)
library(terra)
# creating random species distributions
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
set.seed(510)
r10 <- rast(lapply(1:8,
function(i, r, mn, mx){
app(r, function(x, t){
sapply(x, function(x, t){
xmin(t)
}, t=t)
}, t=sample(seq(mn, mx), 2))
}, r=r, mn=minmax(r)[1]+10, mx=minmax(r)[2]-10))
names(r10) <- paste("sp", 1:nlyr(r10))
plot(r10)
rprobnull <- terra::app(r10,
function(x){
ifelse(is.na(x), NA, 1)
})
# bootstrapping once
randr10 <- bootspat_ff(r10, rprobnull)
plot(randr10)
plot(c(sum(r10), sum(randr10)), main=c("observed", "randomized"))
plot(sum(r10)-sum(randr10))
cbind(observed=sapply(r10, function(x)freq(x)[2,3]),
randomized=sapply(randr10, function(x)freq(x)[2,3]))
Run the code above in your browser using DataLab