if (FALSE) {
file <- system.file("external/model.sdm", package="sdm")
m <- read.sdm(file) # a sdmModels Object (fitted using sdm function)
getModelInfo(m)
# there are 4 models in the sdmModels objects
# so let's take a look at all the results for the model with modelID 1
# evaluation using training data (both threshod_independent and threshold_based groups):
getEvaluation(m,w=1,wtest='training')
getEvaluation(m,w=1,wtest='training',stat=1) # stat=1 (threshold_independent)
getEvaluation(m,w=1,wtest='test.dep',stat=2) # stat=2 (threshold_based)
getEvaluation(m,w=1:3,wtest='test.dep',stat=c('AUC','TSS'),opt=2)
getEvaluation(m,opt=1) # all models
getEvaluation(m,stat=c('TSS','Kappa','AUC'),opt=1) # all models
############
#example for evaluation:
evaluates(x=c(1,1,0,1,0,0,0,1,1,1,0),
p=c(0.69,0.04,0.05,0.95,0.04,0.65,0.09,0.61,0.75,0.84,0.15))
##############
# Example for getReplication:
df <- read.csv(file) # load a csv file
head(df)
d <- sdmData(sp~b15+NDVI,train=df) # sdmdata object
d
#----
# fit SDMs using 2 methods and a subsampling replication method with 2 replications:
m <- sdm(sp~b15+NDVI,data=d,methods=c('glmpoly','gbm'), replication='sub', test=30, n=2)
m
# randomly drawn species records for test data in the second replication (run) of subsampling:
getReplication(m, replication='sub',run=2)
getReplication(m, replication='sub',run=2,test=F) # drawn record in the training partition
ind <- getReplication(m, replication='sub',run=2,index=T) # index of the selected test record
head(ind)
.df <- as.data.frame(m@data) # convert sdmdata object in the model to data.frame
head(.df)
.df <- .df[.df$rID %in% ind, ] # the full test dataset drawn (second replication)
pr <- predict(m,.df) # predictions of all the methods for the test dataset
pr <- predict(m,.df) # predictions of all the methods for the test dataset
head(pr)
e <- evaluates(.df$sp, pr[,1]) # evaluates for the first method using the selected test data
e@statistics
e@threshold_based
}
Run the code above in your browser using DataLab