if (FALSE) {
library(sf)
library(terra)
library(caret)
library(viridis)
library(latticeExtra)
#' # prepare sample data:
dat <- readRDS(system.file("extdata","Cookfarm.RDS",package="CAST"))
dat <- aggregate(dat[,c("VW","Easting","Northing")],by=list(as.character(dat$SOURCEID)),mean)
pts <- st_as_sf(dat,coords=c("Easting","Northing"))
pts$ID <- 1:nrow(pts)
studyArea <- rast(system.file("extdata","predictors_2012-03-25.tif",package="CAST"))[[1:8]]
dat <- extract(studyArea,pts,na.rm=TRUE)
trainDat <- merge(dat,pts,by.x="ID",by.y="ID")
# train a model:
variables <- c("DEM","NDRE.Sd","TWI")
set.seed(100)
model <- train(trainDat[,which(names(trainDat)%in%variables)],
trainDat$VW,method="rf",importance=TRUE,tuneLength=1,
trControl=trainControl(method="cv",number=5,savePredictions=TRUE))
#...then calculate the AOA of the trained model for the study area:
AOA <- aoa(studyArea,model)
AOA_new <- calibrate_aoa(AOA,model)
plot(AOA_new$AOA$expected_RMSE)
}
Run the code above in your browser using DataLab