-
Notifications
You must be signed in to change notification settings - Fork 1
/
NicheModels.R
59 lines (51 loc) · 1.71 KB
/
NicheModels.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
library (zoon)
library (future)
Sys.setenv(NOAWT=TRUE)
options(java.parameters="-Xmx120g")
plan(multicore)
LoadModule('PrintMap1.R')
vars.stack.gbif <- stack("stack_zoon_gbif.grd")
workgbif1 <- function(){ workflow (occurrence = LocalOccurrenceData (filename = "OCURRENCEFILE.csv", occurrenceType = 'presence/absence'),
covariate = LocalRaster(vars.stack.gbif),
process = Chain (StandardiseCov, Crossvalidate (k = 10)),
model = MaxEnt,
output = Chain (PrintMap1 (dir = "DIR"), PerformanceMeasures))}
workresgbif1 <- workgbif1()
save (workresgbif1, file = 'workflow_FILE.RData')
###Testing significant deviation from random expectation
load ("workflow_FILE.RData")
library (dismo)
back<-workresgbif1[["process.output"]][[1]][["df"]]
back<-back[,-c(1:5)]
back<-back[,c(1:12,19,13:18)]
nullModel <- function (x, n = 10, rep = 99)
{
e <- list()
#stopifnot(n < nrow(x))
for (r in 1:rep) {
z <- sample(nrow(x), n)
pres <- x[z, ] # randomly drawn presences
absc <- x[-z, ] # remaining points set as absences
rs10k <- sample(1:nrow(absc), 9500) # random select 10k rows
absc <- absc[rs10k,]
d <- rbind(pres, absc)
v <- c(rep(1, nrow(pres)), rep(0, nrow(absc)))
m.null <- maxent(d,v, args = c("noproduct", "nothreshold", "nohinge"))
e[[r]] <- evaluate(pres, absc, m.null)
cat("-")
if (r%%50 == 0)
cat(" ", r, "\n")
flush.console()
}
if (r%%50 != 0) {
cat(" ", r, "\n")
}
else {
cat("\n")
}
e
}
nulltest <- nullModel (back, n = X, rep = 99)
nulltest
mean(sapply(nulltest, function(x)x@auc))
max(sapply(nulltest, function(x)x@auc))