# test the MaxEnt version
MaxEnt()
# \donttest{
# get predictor variables
ff <- list.files("tif$", path=system.file("ex", package="predicts"), full.names=TRUE)
preds <- rast(ff)
plot(preds)
# file with presence points
occurence <- system.file("/ex/bradypus.csv", package="predicts")
occ <- read.csv(occurence)[,-1]
# witholding a 20% sample for testing
fold <- folds(occ, k=5)
occtest <- occ[fold == 1, ]
occtrain <- occ[fold != 1, ]
# fit model
me <- MaxEnt(preds, occtrain)
# see the MaxEnt results in a browser:
me
# use "args"
me2 <- MaxEnt(preds, occtrain, args=c("-J", "-P"))
# plot showing importance of each variable
plot(me)
# predict to entire dataset
r <- predict(me, preds)
# with some options:
r <- predict(me, preds, args=c("outputformat=raw"))
plot(r)
points(occ)
#testing
# background sample
bg <- backgroundSample(preds, 1000)
#simplest way to use 'evaluate'
e1 <- pa_evaluate(me, p=occtest, a=bg, x=preds)
# alternative 1
# extract values
pvtest <- data.frame(extract(preds, occtest))
avtest <- data.frame(extract(preds, bg))
e2 <- pa_evaluate(me, p=pvtest, a=avtest)
# alternative 2
# predict to testing points
testp <- predict(me, pvtest)
head(testp)
testa <- predict(me, avtest)
e3 <- pa_evaluate(p=testp, a=testa)
e3
threshold(e3)
plot(e3, 'ROC')
# }
Run the code above in your browser using DataLab