if (FALSE) {
library(sf)
library(terra)
library(caret)
library(CAST)
# prepare sample data:
data("splotdata")
splotdata = st_drop_geometry(splotdata)
# train a model:
set.seed(100)
model <- caret::train(splotdata[,6:16],
splotdata$Species_richness,
importance=TRUE, tuneLength=1, ntree = 15, method = "rf",
trControl = trainControl(method="cv", number=5, savePredictions=T))
# variable importance is used for scaling predictors
plot(varImp(model,scale=FALSE))
# calculate the DI of the trained model:
DI = trainDI(model=model)
plot(DI)
#...or calculate the DI and LPD of the trained model:
# DI = trainDI(model=model, LPD = TRUE)
# the DI can now be used to compute the AOA (here with LPD):
studyArea = rast(system.file("extdata/predictors_chile.tif", package = "CAST"))
AOA = aoa(studyArea, model = model, trainDI = DI, LPD = TRUE, maxLPD = 1)
print(AOA)
plot(AOA)
plot(AOA$AOA)
plot(AOA$LPD)
}
Run the code above in your browser using DataLab