# Calculates TSS from MaxEnt output
# We used replicates and the Maximum-training-sensitivity-plus-specificity-logistic-threshold rule
# If you are using a different threshold rule, you have to change it in the script
# You will have to change the MaxEnt output directory too
# It will generate a file named __tss.csv, in the Maxent output directory with three columns: Name of replicate, TSS, Binomial probability
# It will only work if the "Write background predictions" option is marked in MaxEnt.
# Loading the libraries
library(ROCR)
library(vcd)
library(boot)
#### Extracting relevant MaxEnt output files ####
listoutput sp
presence threshold)->majortest
sum(testpp < threshold)->minortest
# Determine the number of background values greater and less than the threshold
sum(bb > threshold)->majorbb
sum(bb < threshold)->minorbb
# Calculate the sensitivity and specificity
sensit>tssgeral
})
write.csv(tss_out,file="__tss.csv") # Write table with name of replicate, TSS and Binomial Probability