This repository has been archived by the owner on Dec 18, 2022. It is now read-only.
/
03 Make Figures of Results - Full Page Figures.r
2949 lines (2133 loc) · 112 KB
/
03 Make Figures of Results - Full Page Figures.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
### SDM PREDICTOR INFERENCE - ILLUSTRATIONS
### Adam B. Smith | Missouri Botanical Garden | adam.smith@mobot.org
### source('C:/Ecology/Drive/Research/ENMs - Predictor Inference/Scripts/03 Make Figures of Results - Full Page Figures.r')
###
### The code in this document is intended to be run after all models have been calibrated and evaluated. Most of the sections run extremely quickly except for the section that collates evaluation results for the [bivariate] experiment ("### [bivariate] collate evaluations ###") which can take several hours, depending on the number of scenarios modeled.
memory.limit(memory.limit() * 2^30)
rm(list=ls())
options(keep.source=FALSE) # manage memory
gc()
print('')
print(date())
### CONTENTS ###
### libraries ###
### variables and settings ###
### case-specific functions ###
### [simple] simulation results ###
### [simple] statistics ###
### [extent] simulation results ###
### [extent] investigating decline in performance of OMNI control at large extents ###
### sensitivity of CBI to outliers ###
### [prevalence] simulation results ###
### [resolution] simulation results ###
### [correlated TRUE & FALSE] simulation results ###
### [bivariate] collate evaluations ###
### [bivariate] statistics ###
### [bivariate] landscape correlation x niche covariance bar plots for CBI ###
### [bivariate] landscape correlation x niche covariance bar plots for AUC ###
### [bivariate] landscape correlation x niche covariance bar plots for CORpa ###
### [bivariate] landscape correlation x niche covariance bar plots for CORbg ###
#################
### libraries ###
#################
# CRAN
library(RColorBrewer)
library(plotrix)
library(fpCompare)
library(scales)
# custom libraries (on GitHub, user account adamlilith)
library(omnibus)
library(enmSdm)
library(statisfactory)
library(enmSdmPredImport)
library(legendary)
##############################
### variables and settings ###
##############################
### working directory
setwd('C:/ecology/Drive/Research/ENMs - Predictor Inference')
# algorithms
# # set 1
algos <- c('omniscient', 'gam', 'maxent', 'brt')
sdmAlgos <- c('gam', 'maxent', 'brt')
# # set 2
# algos <- c('omniscient', 'bioclim', 'glm', 'rf')
# sdmAlgos <- c('bioclim', 'glm', 'rf')
allAlgos <- c('omniscient', 'bioclim', 'gam', 'glm', 'maxent', 'brt', 'rf')
### colors of bars for scenarios with TRUE and FALSE variables
##############################################################
colTrue <- '#7fbf7b' # perturbed SDM vs TRUE (CB safe)
borderTrue <- '#1b7837' # perturbed SDM vs TRUE (CB safe)
colFalse <- '#d6604d' # perturbed SDM vs FALSE (CB safe)
borderFalse <- '#b2182b' # perturbed SDM vs FALSE (CB safe)
colSdmControl <- 'gray'# 'white'# '#8da0cb' # unperturbed SDM (CB safe)
borderSdmControl <- 'black'# '#7570b3' # unperturbed SDM (CB safe)
colOmniControl <- 'black' # unperturbed OMNI
borderOmniControl <- 'black'# 'gray' # unperturbed OMNI
colOmniResp <- 'white' # perturbed OMNI
borderOmniTrue <- '#1b7837'# 'black' # perturbed OMNI
borderOmniFalse <- '#b2182b'# 'black' # perturbed OMNI
### colors for scenarios with TRUE1 and TRUE2 variables
#######################################################
colSdmT1 <- colOmniT1 <- '#a6dba0' # light green (CB safe)
borderSdmT1 <- borderOmniT1 <- '#008837' # dark green (CB safe)
colSdmT2 <- colOmniT2 <- '#c2a5cf' # light purple (CB safe)
borderSdmT2 <- borderOmniT2 <- '#7b3294' # dark purple (CB safe)
###############################
### case-specific functions ###
###############################
# create abbreviated function names
algosShort <- function(x) {
# x character vector
x[x == 'omniscient'] <- 'OMNI'
x[x == 'bioclim'] <- 'BIO'
x[x == 'brt'] <- 'BRT'
x[x == 'gam'] <- 'GAM'
x[x == 'maxent'] <- 'MAX'
x[x == 'rf'] <- 'RF'
x[x == 'glm'] <- 'GLM'
x
}
# plot rectangle representing inner x-th quantile of response variable
rect <- function(x, at, width=0.1, scale=TRUE, quants=c(0.025, 0.975), col='gray', border='black', ...) {
# x numeric vector of values
# at numeric position of center of rectangle along x axis
# width width of rectangle in plot units
# scale TRUE ==> scale width by number of models that converged (ie, x values are not NA)
# quants 2-element numeric, quantiles for inner distribution
# col, border color of fill and border
# ... args for polygon
if (scale) width <- width * sum(!is.na(x)) / length(x)
lims <- quantile(x, quants, na.rm=TRUE)
bottom <- lims[1]
top <- lims[2]
med <- median(x, na.rm=TRUE)
left <- at - 0.5 * width
right <- at + 0.5 * width
polygon(x=c(left, right, right, left), y=c(bottom, bottom, top, top), col=col, border=border, xpd=NA, ...)
lines(x=c(left, right), y=c(med, med), col=border, xpd=NA, lwd=0.9, lend=1)
}
##############################
### "scalar" plot function ###
##############################
# variables used by "scalar" plot function
width <- 0.22 # bar width
nudge <- 0.22 # nudge pair of bars for same algorithm left/right
subnudge <- nudge / 3 # nudge bars within same algorithm left/right
figLabPos <- c(-0.150, 0.05) # position of figure label
legCex <- 0.34 # legend
ylabX1 <- -0.15 # position of inner y-axis label
ylabX2 <- -0.25 # position of outer y-axis label
labCex <- 0.55 # size of algorithm, y-axis, and figure labels
xlabY1 <- -0 # position of inner x-axis sublabels (range of TRUE)
xlabY2 <- -0.23 # position of outer x-axis label
lineDensity <- 110 # density of lines per inch for perturbed OMNI
### generic plot function for plots with a scalar along the x-axis and variable importance along the y
### The x-axis can represent: prevalence, landscape extent, correlation between landscape variables, correlation between variables in shaping the niche, and so on. This function is intended to supply a thematic unity to plots of these types.
plotScalarResp <- function(
xCol,
decs,
xlab,
algo,
variable,
nudge,
subnudge,
ylim,
yTicks,
ylab,
lab,
rand,
resp,
respControl
) {
# general idea:
# graph shows results for one algorithm plus OMNI
# x-axis: independent variable (prevalence, extent, etc)
# y-axis: variable importance
# each level of TRUE variable range: two sets of bars per algorithm, one is control, one is TRUE or FALSE, sets of bars are staggered
# xCol name of column in evaluation data frame that has values for x axis
# decs NULL (use values of xCol as-is for x-axis tick labels) or an integer indicating number
# of digits to display for x tick labels
# xlab x-axis label
# algo algorithm (not OMNI)
# variable either 'T1' or 'F1'
# nudge amount to move sets of bars belonging to control/treatment model predictions relative to x-axis tick
# subnudge amount to move bars belonging to same control/treatment model predictions relative to x-axis tick
# ylim y-axis limits
# ylab y-axis label
# yTicks position of tick marks on y-axis
# lab figure label
# rand value of response equal to "random prediction" (eg 0.5 for AUC or 0 for CBI)
# resp field name of response (minus the variable name, ie "T1" or "F1")
# respControl field name of response for control case (or NULL if none)
# format settings based on variable
if (variable == 'T1') {
colResp <- colTrue
borderResp <- borderTrue
variableName <- 'TRUE'
borderOmniResp <- borderOmniTrue
} else {
colResp <- colFalse
borderResp <- borderFalse
variableName <- 'FALSE'
borderOmniResp <- borderOmniFalse
}
# x-axis values
x <- sort(unique(evals[ , xCol]))
# base plot
plot(0, type='n', axes=FALSE, ann=FALSE, xlim=c(0.5, length(x)), ylim=ylim)
labelFig(lab, adj=figLabPos, cex=labCex)
usr <- par('usr')
# gray background
left <- 1 - (2.5 + ifelse(is.null(respControl), 0.75, 0)) * nudge
right <- length(x) + (2.5 + ifelse(is.null(respControl), 0.25, 0)) * nudge
polygon(x=c(left, right, right, left), y=c(min(yTicks), min(yTicks), max(yTicks), max(yTicks)), col='gray85', border=NA, xpd=NA)
lines(x=c(left, right), y=c(rand, rand), col='white', lwd=1.4, xpd=NA)
for (ats in yTicks) lines(x=c(left, right), y=c(ats, ats), col='white', lwd=0.5, xpd=NA)
for (i in 1:(length(x) - 1)) lines(x=c(i + 0.5, i + 0.5), y=c(-1, 1), col='white', lwd=0.5, xpd=NA)
# x: axis labels
axis(1, at=seq_along(x), labels=rep('', length(x)), tck=-0.03, lwd=0.8)
xLabs <- if (!is.null(decs)) { sprintf(paste0('%.', decs, 'f'), x) } else { x }
text(seq_along(x), y=rep(usr[3] + xlabY1 * (usr[4] - usr[3]), length(x)), labels=xLabs, cex=0.8 * labCex, xpd=NA, srt=0, pos=1, col='black')
text(mean(seq_along(x)), y=usr[3] + xlabY2 * (usr[4] - usr[3]), labels=xlab, cex=labCex, xpd=NA, srt=0, col='black')
# y: y-axis labels
axis(2, at=yTicks, labels=yTicks, tck=-0.03, lwd=0.8)
text(usr[1] + ylabX1 * (usr[2] - usr[1]), y=mean(yTicks), label='\U2190important unimportant\U2192', srt=90, cex=0.9 * labCex, xpd=NA)
text(usr[1] + ylabX2 * (usr[2] - usr[1]), y=mean(yTicks), label=ylab, srt=90, cex=labCex, xpd=NA)
thisNudge <- length(algos) / 2
# for each value of x
for (countX in seq_along(x)) {
thisX <- x[countX]
# get data
omniResponse <- evals[evals$algo == 'omniscient' & evals[ , xCol] == thisX, paste0(resp, variable)]
algoResponse <- evals[evals$algo == algo & evals[ , xCol] == thisX, paste0(resp, variable)]
# if there is a distinct response for control/unperturbed models
# used when using CBI or AUC
if (!is.null(respControl)) {
omniControl <- evals[evals$algo == 'omniscient' & evals[ , xCol] == thisX, respControl]
algoControl <- evals[evals$algo == algo & evals[ , xCol] == thisX, respControl]
# unperturbed OMNI
rect(omniControl, at=countX - nudge - subnudge, width=width, col='white', border=NA, xpd=NA, lwd=0.5)
rect(omniControl, at=countX - nudge - subnudge, width=width, density=lineDensity, col=colOmniControl, fill='white', border=borderOmniControl, xpd=NA, lwd=0.5)
# unperturbed SDM
rect(algoControl, at=countX - nudge + subnudge, width=width, col=colSdmControl, border=borderSdmControl, xpd=NA, lwd=0.5)
# legend
leg <- c(
'OMNI control',
paste0(algosShort(algo), ' control'),
paste0('OMNI ', variableName,' permuted'),
paste0(algosShort(algo), ' ', variableName, ' permuted')
)
par(lwd=0.5)
legend('bottomright', inset=c(0, 0.05), ncol=2, bty='n', legend=leg, cex=legCex, fill=c(borderSdmControl, colSdmControl, borderResp, colResp), border=c(borderOmniControl, borderSdmControl, borderOmniResp, borderResp), density=c(lineDensity, NA, lineDensity, NA))
# nudges for plotting response bars (below)
omniRespNudge <- nudge - subnudge
sdmRespNudge <- nudge + subnudge
# if there is no distinct response for control/unperturbed
# for when plotting correlation metric
} else {
# legend
leg <- c(
paste0('OMNI ', variableName,' permuted'),
paste0(algosShort(algo), ' ', variableName, ' permuted')
)
par(lwd=0.5)
legend('bottomright', inset=c(0, 0.025), ncol=1, bty='n', legend=leg, cex=legCex, fill=c(borderResp, colResp), border=c(borderOmniResp, borderResp), density=c(lineDensity, NA))
# nudges for plotting response bars (below)
omniRespNudge <- -1 * nudge + subnudge
sdmRespNudge <- nudge - subnudge
}
# OMNI response
rect(omniResponse, at=countX + omniRespNudge, width=width, col='white', border=NA, xpd=NA, lwd=0.5)
rect(omniResponse, at=countX + omniRespNudge, width=width, col=colResp, density=lineDensity, border=borderOmniResp, xpd=NA, lwd=0.5)
# perturbed SDM
rect(algoResponse, at=countX + sdmRespNudge, width=width, col=colResp, border=borderResp, xpd=NA, lwd=0.5)
}
}
# say('###################################')
# say('### [simple] simulation results ###')
# say('###################################')
# scenarioDir <- './Results/simple'
# evalDir <- paste0(scenarioDir, '/evaluations')
# evals <- loadEvals(evalDir, algos=allAlgos, save=TRUE, redo=TRUE)
# # generalization
# width <- 0.14 # bar width
# nudge <- 0.22 # nudge left/right
# figLabPos <- c(-0.15, 0.05) # position of figure label
# ylabX1 <- -0.18 # position of inner y-axis label
# ylabX2 <- -0.26 # position of outer y-axis label
# labCex <- 0.45 # size of algorithm, y-axis, and figure labels
# sublabY <- -0.07 # position of TRUE/FALSE variable sublabels
# sublabCex <- 0.38 # size of TRUE/FALSE sublabels
# # master plot function
# plotSimpleResp <- function(nudge, ylim, yTicks, ylab, lab, rand, respT1, respControl, respF1, controlLab) {
# # nudge amount to move bars in same group (algorithm) left or right
# # ylim y-axis limits
# # ylab y-axis label
# # yTicks position of tick marks on y-axis
# # lab figure label
# # rand value of response equal to "random prediction" (eg 0.5 for AUC or 0 for CBI)
# # respT1 field name of response for TRUE variable
# # respControl field name of response for control case (or NULL if none)
# # respF1 field name of response for FALSE variable
# # controlLab character, name of bar representing "control" model/prediction
# # adjust nudging of bars in same groups
# if (is.null(respControl)) nudge <- nudge / 2
# # base plot
# plot(0, type='n', axes=FALSE, ann=FALSE, xlim=c(0.5, length(algos)), ylim=ylim)
# labelFig(lab, adj=figLabPos, cex=labCex)
# usr <- par('usr')
# # gray background
# left <- 1 - (2 + ifelse(is.null(respControl), 0.75, 0)) * nudge
# right <- length(algos) + (2.5 + ifelse(is.null(respControl), 0.25, -0.3)) * nudge
# polygon(x=c(left, right, right, left), y=c(min(yTicks), min(yTicks), max(yTicks), max(yTicks)), col='gray85', border=NA, xpd=NA)
# lines(x=c(left, right), y=c(rand, rand), col='white', lwd=1.4, xpd=NA)
# for (ats in yTicks) lines(x=c(left, right), y=c(ats, ats), col='white', lwd=0.5, xpd=NA)
# for (i in 1:(length(algos) - 1)) lines(x=c(i + 0.5, i + 0.5), y=c(-1, 1), col='white', lwd=0.5, xpd=NA)
# # x: variable labels
# axis(1, at=seq_along(algos), labels=rep('', length(algos)), tck=-0.03, lwd=0.8)
# text(seq_along(algos) - nudge, y=rep(usr[3] + sublabY * (usr[4] - usr[3]), length(algos)), labels=rep('TRUE', length(algos)), cex=sublabCex, xpd=NA, srt=90, adj=c(1, 0.3), col=borderTrue)
# if (!is.null(respControl)) text(seq_along(algos), y=rep(usr[3] + sublabY * (usr[4] - usr[3]), length(algos)), labels=rep(controlLab, length(algos)), cex=sublabCex, xpd=NA, srt=90, adj=c(1, 0.3), col='black')
# text(seq_along(algos) + nudge, y=rep(usr[3] + sublabY * (usr[4] - usr[3]), length(algos)), labels=rep('FALSE', length(algos)), cex=sublabCex, xpd=NA, srt=90, adj=c(1, 0.3), col=borderFalse)
# # x: algorithm labels
# text(seq_along(algos), y=rep(usr[3] + algoLabY * (usr[4] - usr[3]), length(algos)), labels=algosShort(algos), xpd=NA, cex=labCex)
# # y: y-axis labels
# axis(2, at=yTicks, labels=yTicks, tck=-0.03, lwd=0.8)
# text(usr[1] + ylabX1 * (usr[2] - usr[1]), y=mean(yTicks), label='\U2190important unimportant\U2192', srt=90, cex=0.9 * labCex, xpd=NA)
# text(usr[1] + ylabX2 * (usr[2] - usr[1]), y=mean(yTicks), label=ylab, srt=90, cex=labCex, xpd=NA)
# # responses
# for (countAlgo in seq_along(algos)) {
# algo <- algos[countAlgo]
# true <- evals[evals$algo==algo, respT1]
# if (!is.null(respControl)) control <- evals[evals$algo==algo, respControl]
# false <- evals[evals$algo==algo, respF1]
# if (!is.null(respControl)) rect(control, at=countAlgo, width=width, col='gray', border=borderOmniControl, lwd=0.8)
# rect(true, at=countAlgo - nudge, width=width, col=colTrue, border=borderTrue, xpd=NA, lwd=0.8)
# rect(false, at=countAlgo + nudge, width=width, col=colFalse, border=borderFalse, xpd=NA, lwd=0.8)
# }
# }
# ### multivariate: CBI
# #####################
# algoLabY <- -0.34 # position of algorithm labels
# png(paste0(scenarioDir, '/Results - Multivariate Models - CBI.png'), width=900, height=900, res=600)
# par(oma=rep(0, 4), mar=c(2.2, 2, 0.5, 0.5), mgp=c(2, 0.2, 0), cex.axis=0.35, lwd=0.6)
# # CBI multivariate
# lab <- bquote('')
# ylab <- bquote('CBI')
# ylim <- c(-1, 1)
# yTicks <- seq(-1, 1, by=0.5)
# respT1 <- 'cbiMulti_permT1'
# respControl <- 'cbiMulti'
# respF1 <- 'cbiMulti_permF1'
# plotSimpleResp(nudge=nudge, ylim=ylim, ylab=ylab, lab=lab, yTicks=yTicks, rand=0, respT1=respT1, respControl=respControl, respF1=respF1, controlLab='Control')
# title(sub=date(), outer=TRUE, cex.sub=0.2, line=-0.82)
# dev.off()
# ### multivariate: AUCpa
# #######################
# algoLabY <- -0.34 # position of algorithm labels
# png(paste0(scenarioDir, '/Results - Multivariate Models - AUCpa.png'), width=900, height=900, res=600)
# par(oma=rep(0, 4), mar=c(2.2, 2, 0.5, 0.5), mgp=c(2, 0.2, 0), cex.axis=0.35, lwd=0.6)
# # CBI multivariate
# lab <- bquote('')
# ylab <- bquote('AUC'['pa'])
# ylim <- c(0, 1)
# yTicks <- seq(0, 1, by=0.25)
# respT1 <- 'aucPresAbsMulti_permT1'
# respControl <- 'aucPresAbsMulti'
# respF1 <- 'aucPresAbsMulti_permF1'
# plotSimpleResp(nudge=nudge, ylim=ylim, ylab=ylab, lab=lab, yTicks=yTicks, rand=0, respT1=respT1, respControl=respControl, respF1=respF1, controlLab='Control')
# title(sub=date(), outer=TRUE, cex.sub=0.2, line=-0.82)
# dev.off()
# ### multivariate: AUCbg
# #######################
# algoLabY <- -0.34 # position of algorithm labels
# png(paste0(scenarioDir, '/Results - Multivariate Models - AUCbg.png'), width=900, height=900, res=600)
# par(oma=rep(0, 4), mar=c(2.2, 2, 0.5, 0.5), mgp=c(2, 0.2, 0), cex.axis=0.35, lwd=0.6)
# # CBI multivariate
# lab <- bquote('')
# ylab <- bquote('AUC'['bg'])
# ylim <- c(0, 1)
# yTicks <- seq(0, 1, by=0.25)
# respT1 <- 'aucPresBgMulti_permT1'
# respControl <- 'aucPresBgMulti'
# respF1 <- 'aucPresBgMulti_permF1'
# plotSimpleResp(nudge=nudge, ylim=ylim, ylab=ylab, lab=lab, yTicks=yTicks, rand=0, respT1=respT1, respControl=respControl, respF1=respF1, controlLab='Control')
# title(sub=date(), outer=TRUE, cex.sub=0.2, line=-0.82)
# dev.off()
# ### multivariate: CORpa
# #######################
# algoLabY <- -0.34 # position of algorithm labels
# png(paste0(scenarioDir, '/Results - Multivariate Models - CORpa.png'), width=900, height=900, res=600)
# par(oma=rep(0, 4), mar=c(2.2, 2, 0.5, 0.5), mgp=c(2, 0.2, 0), cex.axis=0.35, lwd=0.6)
# lab <- bquote('')
# ylab <- bquote('COR'['pa'])
# ylim <- c(0, 1)
# yTicks <- seq(0, 1, by=0.25)
# respT1 <- 'corPresAbsMulti_permT1'
# respControl <- NULL
# respF1 <- 'corPresAbsMulti_permF1'
# plotSimpleResp(nudge=nudge, ylim=ylim, ylab=ylab, lab=lab, yTicks=yTicks, rand=0, respT1=respT1, respControl=respControl, respF1=respF1, controlLab='')
# title(sub=date(), outer=TRUE, cex.sub=0.2, line=-0.82)
# dev.off()
# ### multivariate: CORbg
# #######################
# algoLabY <- -0.34 # position of algorithm labels
# png(paste0(scenarioDir, '/Results - Multivariate Models - CORbg.png'), width=900, height=900, res=600)
# par(oma=rep(0, 4), mar=c(2.2, 2, 0.5, 0.5), mgp=c(2, 0.2, 0), cex.axis=0.35, lwd=0.6)
# lab <- bquote('')
# ylab <- bquote('COR'['bg'])
# ylim <- c(0, 1)
# yTicks <- seq(0, 1, by=0.25)
# respT1 <- 'corPresBgMulti_permT1'
# respControl <- NULL
# respF1 <- 'corPresBgMulti_permF1'
# plotSimpleResp(nudge=nudge, ylim=ylim, ylab=ylab, lab=lab, yTicks=yTicks, rand=0, respT1=respT1, respControl=respControl, respF1=respF1, controlLab='')
# title(sub=date(), outer=TRUE, cex.sub=0.2, line=-0.82)
# dev.off()
# say('###########################')
# say('### [simple] statistics ###')
# say('###########################')
# scenarioDir <- './Results/simple'
# evalDir <- paste0(scenarioDir, '/evaluations')
# evals <- loadEvals(evalDir, algos=allAlgos, save=TRUE, redo=TRUE)
# # OMNI AUC
# x <- evals$aucPresAbsMulti[evals$algo=='omniscient']
# avg <- mean(x)
# say('Mean AUCpa for unpermuted multivariate OMNI model is ', sprintf('%.2f', avg), '.')
# x <- evals$aucPresBgMulti[evals$algo=='omniscient']
# avg <- mean(x)
# say('Mean AUCbg for unpermuted multivariate OMNI model is ', sprintf('%.2f', avg), '.', post=2)
# # BRT native importance
# x <- evals$brtMultiNativeImportT1[evals$algo=='brt']
# avg <- mean(x, na.rm=TRUE)
# quants <- quantile(x, c(0.025, 0.975), na.rm=TRUE)
# say('Mean algorithm-specific importance for multivariate BRT model for TRUE variable is ', sprintf('%.2f', avg), ' (inner 95% range:', sprintf('%.2f', quants[1]), '-', sprintf('%.2f', quants[2]), ')')
# x <- evals$brtMultiNativeImportF1[evals$algo=='brt']
# avg <- mean(x, na.rm=TRUE)
# quants <- quantile(x, c(0.025, 0.975), na.rm=TRUE)
# say('Mean algorithm-specific importance for multivariate BRT model for FALSE variable is ', sprintf('%.2f', avg), ' (inner 95% range:', sprintf('%.2f', quants[1]), '-', sprintf('%.2f', quants[2]), ')', post=2)
# # BRT performance and use of TRUE/FALSE
# x1 <- evals$brtMultiNativeImportT1[evals$algo=='brt']
# x2 <- evals$cbiMulti[evals$algo=='brt']
# x <- cor(x1, x2, use='complete.obs')
# say('Correlation between multivariate CBI and native-BRT TRUE importance: ', sprintf('%.2f', x))
# x1 <- evals$brtMultiNativeImportF1[evals$algo=='brt']
# x2 <- evals$cbiMulti[evals$algo=='brt']
# x <- cor(x1, x2, use='complete.obs')
# say('Correlation between multivariate CBI and native-BRT FALSE importance: ', sprintf('%.2f', x), post=2)
# # BRT AUC
# x <- evals$aucPresAbsMulti[evals$algo=='brt']
# successes <- sum(!is.na(x))
# say('Number of times multivariate BRT converged (out of 100): ', successes, post=2)
# # OMNI CBI
# x <- evals$cbiMulti[evals$algo=='omniscient']
# stats <- quantile(x, c(0.025, 0.5, 0.975))
# say('2.5th/median/97.5th quantiles of CBI for multivariate control OMNISCIENT model: ', paste(sprintf('%.2f', stats), collapse=' '))
# x <- evals$cbiMulti[evals$algo=='omniscient']
# stats <- quantile(x, c(0, 0.5, 1))
# say('Min/median/max CBI for multivariate control OMNISCIENT model: ', paste(sprintf('%.2f', stats), collapse=' '), post=2)
# # BRT CBI
# x <- evals$cbiUni_onlyT1[evals$algo=='brt']
# successes <- sum(!is.na(x))
# say('Number of times univariate BRT converged using just TRUE variable (out of 100): ', successes)
# x <- evals$cbiUni_onlyF1[evals$algo=='brt']
# say('Number of times univariate BRT converged using just FALSE variable (out of 100): ', successes)
# successes <- sum(!is.na(x))
# say('########################################')
# say('### [sample size] simulation results ###')
# say('########################################')
# # generalization
# scenarioDir <- './Results/sample size' # scenario directory
# evalDir <- paste0(scenarioDir, '/evaluations')
# xCol <- 'numTrainPres' # name of x-axis variable column in evaluation data frame
# decs <- 0 # number of decimals to show in x-axis variable tick mark labels
# xlab <- 'Number of presences' # x-axis label
# # load evaluations and calculate x-axis variable
# evals <- loadEvals(evalDir, algos=allAlgos, save=TRUE, redo=FALSE)
# #### CBI multivariate
# #####################
# ylim <- c(-1, 1)
# yTicks <- seq(-1, 1, by=0.25)
# ylab <- 'CBI'
# rand <- 0
# resp <- 'cbiMulti_perm'
# respControl <- 'cbiMulti'
# png(paste0(scenarioDir, '/Results - Multivariate Models - CBI - ', paste(toupper(sdmAlgos), collapse=' '), '.png'), width=1800, height=2400, res=600)
# par(mfrow=c(3, 2), oma=c(1, 0.5, 0.2, 0.1), mar=c(2.5, 2, 1, 1.2), mgp=c(2, 0.2, 0), cex.axis=0.425)
# for (countAlgo in seq_along(sdmAlgos)) {
# algo <- sdmAlgos[countAlgo]
# lab <- paste0(letters[2 * countAlgo - 1], ') ', algosShort(algo), ' versus TRUE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='T1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# lab <- paste0(letters[2 * countAlgo] , ') ', algosShort(algo), ' versus FALSE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='F1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# }
# title(sub=date(), outer=TRUE, line=0, cex.sub=0.3)
# dev.off()
# ### AUCpa
# #########
# ylim <- c(0, 1)
# yTicks <- seq(0, 1, by=0.25)
# ylab <- bquote('AUC'['pa'])
# rand <- 0.5
# resp <- 'aucPresAbsMulti_perm'
# respControl <- 'aucPresAbsMulti'
# png(paste0(scenarioDir, '/Results - Multivariate Models - AUCpa - ', paste(toupper(sdmAlgos), collapse=' '), '.png'), width=1800, height=2400, res=600)
# par(mfrow=c(3, 2), oma=c(1, 0.5, 0.2, 0.1), mar=c(2.5, 2, 1, 1.2), mgp=c(2, 0.2, 0), cex.axis=0.425)
# for (countAlgo in seq_along(sdmAlgos)) {
# algo <- sdmAlgos[countAlgo]
# lab <- paste0(letters[2 * countAlgo - 1], ') ', algosShort(algo), ' versus TRUE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='T1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# lab <- paste0(letters[2 * countAlgo] , ') ', algosShort(algo), ' versus FALSE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='F1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# }
# title(sub=date(), outer=TRUE, line=0, cex.sub=0.3)
# dev.off()
# ### AUCbg
# #########
# ylim <- c(0, 1)
# yTicks <- seq(0, 1, by=0.25)
# ylab <- bquote('AUC'['bg'])
# rand <- 0.5
# resp <- 'aucPresBgMulti_perm'
# respControl <- 'aucPresBgMulti'
# png(paste0(scenarioDir, '/Results - Multivariate Models - AUCbg - ', paste(toupper(sdmAlgos), collapse=' '), '.png'), width=1800, height=2400, res=600)
# par(mfrow=c(3, 2), oma=c(1, 0.5, 0.2, 0.1), mar=c(2.5, 2, 1, 1.2), mgp=c(2, 0.2, 0), cex.axis=0.425)
# for (countAlgo in seq_along(sdmAlgos)) {
# algo <- sdmAlgos[countAlgo]
# lab <- paste0(letters[2 * countAlgo - 1], ') ', algosShort(algo), ' versus TRUE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='T1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# lab <- paste0(letters[2 * countAlgo] , ') ', algosShort(algo), ' versus FALSE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='F1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# }
# title(sub=date(), outer=TRUE, line=0, cex.sub=0.3)
# dev.off()
# ### CORpa multivariate
# ######################
# ylim <- c(-0.25, 1)
# yTicks <- seq(-0.25, 1, by=0.25)
# ylab <- bquote('COR'['pa'])
# rand <- 0
# resp <- 'corPresAbsMulti_perm'
# respControl <- NULL
# png(paste0(scenarioDir, '/Results - Multivariate Models - CORpa - ', paste(toupper(sdmAlgos), collapse=' '), '.png'), width=1800, height=2400, res=600)
# par(mfrow=c(3, 2), oma=c(1, 0.5, 0.2, 0.1), mar=c(2.5, 2, 1, 1.2), mgp=c(2, 0.2, 0), cex.axis=0.425)
# for (countAlgo in seq_along(sdmAlgos)) {
# algo <- sdmAlgos[countAlgo]
# lab <- paste0(letters[2 * countAlgo - 1], ') ', algosShort(algo), ' versus TRUE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='T1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# lab <- paste0(letters[2 * countAlgo] , ') ', algosShort(algo), ' versus FALSE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='F1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# }
# title(sub=date(), outer=TRUE, line=0, cex.sub=0.3)
# dev.off()
# ### CORbg multivariate
# ######################
# ylim <- c(-0.25, 1)
# yTicks <- seq(-0.25, 1, by=0.25)
# ylab <- bquote('COR'['bg'])
# rand <- 0
# resp <- 'corPresBgMulti_perm'
# respControl <- NULL
# png(paste0(scenarioDir, '/Results - Multivariate Models - CORbg - ', paste(toupper(sdmAlgos), collapse=' '), '.png'), width=1800, height=2400, res=600)
# par(mfrow=c(3, 2), oma=c(1, 0.5, 0.2, 0.1), mar=c(2.5, 2, 1, 1.2), mgp=c(2, 0.2, 0), cex.axis=0.425)
# for (countAlgo in seq_along(sdmAlgos)) {
# algo <- sdmAlgos[countAlgo]
# lab <- paste0(letters[2 * countAlgo - 1], ') ', algosShort(algo), ' versus TRUE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='T1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# lab <- paste0(letters[2 * countAlgo] , ') ', algosShort(algo), ' versus FALSE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='F1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# }
# title(sub=date(), outer=TRUE, line=0, cex.sub=0.3)
# dev.off()
# say('###################################')
# say('### [extent] simulation results ###')
# say('###################################')
# # generalization
# scenarioDir <- './Results/extent' # scenario directory
# evalDir <- paste0(scenarioDir, '/evaluations')
# xCol <- 'rangeT1' # name of x-axis variable column in evaluation data frame
# decs <- NULL # number of decimals to show in x-axis variable tick mark labels
# xlab <- 'Range of TRUE variable' # x-axis label
# # load evaluations and calculate x-axis variable
# evals <- loadEvals(evalDir, algos=allAlgos, save=TRUE, redo=FALSE)
# evals$rangeT1 <- evals$maxT1 - evals$minT1
# ### CBI multivariate
# ####################
# ylim <- c(-1, 1)
# yTicks <- seq(-1, 1, by=0.25)
# ylab <- 'CBI'
# rand <- 0
# resp <- 'cbiMulti_perm'
# respControl <- 'cbiMulti'
# png(paste0(scenarioDir, '/Results - Multivariate Models - CBI - ', paste(toupper(sdmAlgos), collapse=' '), '.png'), width=1800, height=2400, res=600)
# par(mfrow=c(3, 2), oma=c(1, 0.5, 0.2, 0.1), mar=c(2.5, 2, 1, 1.2), mgp=c(2, 0.2, 0), cex.axis=0.425)
# for (countAlgo in seq_along(sdmAlgos)) {
# algo <- sdmAlgos[countAlgo]
# lab <- paste0(letters[2 * countAlgo - 1], ') ', algosShort(algo), ' versus TRUE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='T1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# lab <- paste0(letters[2 * countAlgo] , ') ', algosShort(algo), ' versus FALSE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='F1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# }
# title(sub=date(), outer=TRUE, line=0, cex.sub=0.3)
# dev.off()
# ### AUCpa multivariate
# ######################
# ylim <- c(0, 1)
# yTicks <- seq(0, 1, by=0.25)
# ylab <- bquote('AUC'['pa'])
# rand <- 0
# resp <- 'aucPresAbsMulti_perm'
# respControl <- 'aucPresAbsMulti'
# png(paste0(scenarioDir, '/Results - Multivariate Models - AUCpa - ', paste(toupper(sdmAlgos), collapse=' '), '.png'), width=1800, height=2400, res=600)
# par(mfrow=c(3, 2), oma=c(1, 0.5, 0.2, 0.1), mar=c(2.5, 2, 1, 1.2), mgp=c(2, 0.2, 0), cex.axis=0.425)
# for (countAlgo in seq_along(sdmAlgos)) {
# algo <- sdmAlgos[countAlgo]
# lab <- paste0(letters[2 * countAlgo - 1], ') ', algosShort(algo), ' versus TRUE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='T1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# lab <- paste0(letters[2 * countAlgo] , ') ', algosShort(algo), ' versus FALSE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='F1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# }
# title(sub=date(), outer=TRUE, line=0, cex.sub=0.3)
# dev.off()
# ### AUCbg multivariate
# ######################
# ylim <- c(0, 1)
# yTicks <- seq(0, 1, by=0.25)
# ylab <- bquote('AUC'['bg'])
# rand <- 0
# resp <- 'aucPresBgMulti_perm'
# respControl <- 'aucPresBgMulti'
# png(paste0(scenarioDir, '/Results - Multivariate Models - AUCbg - ', paste(toupper(sdmAlgos), collapse=' '), '.png'), width=1800, height=2400, res=600)
# par(mfrow=c(3, 2), oma=c(1, 0.5, 0.2, 0.1), mar=c(2.5, 2, 1, 1.2), mgp=c(2, 0.2, 0), cex.axis=0.425)
# for (countAlgo in seq_along(sdmAlgos)) {
# algo <- sdmAlgos[countAlgo]
# lab <- paste0(letters[2 * countAlgo - 1], ') ', algosShort(algo), ' versus TRUE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='T1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# lab <- paste0(letters[2 * countAlgo] , ') ', algosShort(algo), ' versus FALSE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='F1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# }
# title(sub=date(), outer=TRUE, line=0, cex.sub=0.3)
# dev.off()
# ### CORpa multivariate
# ####################
# ylim <- c(-0.25, 1)
# yTicks <- seq(-0.25, 1, by=0.25)
# ylab <- bquote('COR'['pa'])
# rand <- 0
# resp <- 'corPresAbsMulti_perm'
# respControl <- NULL
# png(paste0(scenarioDir, '/Results - Multivariate Models - CORpa - ', paste(toupper(sdmAlgos), collapse=' '), '.png'), width=1800, height=2400, res=600)
# par(mfrow=c(3, 2), oma=c(1, 0.5, 0.2, 0.1), mar=c(2.5, 2, 1, 1.2), mgp=c(2, 0.2, 0), cex.axis=0.425)
# for (countAlgo in seq_along(sdmAlgos)) {
# algo <- sdmAlgos[countAlgo]
# lab <- paste0(letters[2 * countAlgo - 1], ') ', algosShort(algo), ' versus TRUE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='T1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# lab <- paste0(letters[2 * countAlgo] , ') ', algosShort(algo), ' versus FALSE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='F1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# }
# title(sub=date(), outer=TRUE, line=0, cex.sub=0.3)
# dev.off()
# ### CORbg multivariate
# ####################
# ylim <- c(-0.25, 1)
# yTicks <- seq(-0.25, 1, by=0.25)
# ylab <- bquote('COR'['bg'])
# rand <- 0
# resp <- 'corPresBgMulti_perm'
# respControl <- NULL
# png(paste0(scenarioDir, '/Results - Multivariate Models - CORbg - ', paste(toupper(sdmAlgos), collapse=' '), '.png'), width=1800, height=2400, res=600)
# par(mfrow=c(3, 2), oma=c(1, 0.5, 0.2, 0.1), mar=c(2.5, 2, 1, 1.2), mgp=c(2, 0.2, 0), cex.axis=0.425)
# for (countAlgo in seq_along(sdmAlgos)) {
# algo <- sdmAlgos[countAlgo]
# lab <- paste0(letters[2 * countAlgo - 1], ') ', algosShort(algo), ' versus TRUE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='T1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# lab <- paste0(letters[2 * countAlgo] , ') ', algosShort(algo), ' versus FALSE variable')
# plotScalarResp(xCol=xCol, decs=decs, xlab=xlab, algo=algo, variable='F1', nudge=nudge, subnudge=subnudge, ylim=ylim, yTicks=yTicks, ylab, lab, rand, resp, respControl)
# }
# title(sub=date(), outer=TRUE, line=0, cex.sub=0.3)
# dev.off()
# say('######################################################################################')
# say('### [extent] investigating decline in performance of OMNI control at large extents ###')
# say('######################################################################################')
# say('I want to investigate the why OMNI control seems to decline in performance as extent goes above 2048 cells on a side. I am guessing this is due to location of some test presences in highly unlikely locations (ie at very low values of TRUE).', breaks=100)
# # generalization
# scenarioDir <- 'H:/Global Change Program/Research/ENMs - Predictor Inference/Results/extent'
# simDir <- paste0(scenarioDir, '/!scenario data')
# evalDir <- paste0(scenarioDir, '/evaluations')
# # threshold
# threshold <- 0 # tabulate proportion of test presences less than this value for each simulation
# # load evaluations and calculate x-axis variable
# evals <- loadEvals(evalDir, algos=allAlgos, save=TRUE, redo=FALSE)
# evals$rangeT1 <- evals$maxT1 - evals$minT1
# xCol <- 'rangeT1' # name of x-axis variable column in evaluation data frame
# xlab <- 'Range of TRUE variable' # x-axis label
# # landscape sizes
# landscapeSizes <- sort(unique(evals$sizeNative))
# # will store proportion of test presences less than the threshold for each simulation
# test <- data.frame()
# for (landscapeSize in landscapeSizes) {
# for (iter in 1:100) {
# load(paste0(simDir, '/landscape size = ', prefix(landscapeSize, 4), ' cells sim ', prefix(iter, 4), '.RData'))
# proportLtThold <- sum(sim$testData$testPres$T1 < threshold) / length(sim$testData$testPres$T1)
# cbiMulti <- evals$cbiMulti[evals$algo == 'omniscient' & evals$sizeNative == landscapeSize & evals$iter == iter]
# test <- rbind(
# test,
# data.frame(
# threshold = threshold,
# landscapeSize = landscapeSize,
# iter = iter,
# proportLtThold = proportLtThold,
# cbiMulti = cbiMulti
# )
# )
# }
# }
# plot(0, 0, xlim=c(0, 1), ylim=c(-1, 1), xlab='Proportion of test presences\nwith TRUE < 0', ylab='CBI', col='white')
# cols <- paste0('gray', round(100 / (1 + seq_along(landscapeSizes))))
# for (count in seq_along(landscapeSizes)) {
# landscapeSize <- landscapeSizes[count]
# col <- cols[count]
# x <- test$proportLtThold[test$landscapeSize == landscapeSize]
# y <- test$cbiMulti[test$landscapeSize == landscapeSize]
# xOrder <- order(x)
# x <- x[xOrder]
# y <- y[xOrder]
# yTrans <- logitAdj(0.5 * (y + 1), epsilon=0.001)
# lm <- lm(yTrans ~ x)
# lmPred <- predict(lm)
# lmPred <- (2 * probitAdj(lmPred, epsilon=0.001)) - 1
# points(x, y, col=col, pch=count)
# lines(x, lmPred, col=col, lwd=5)
# }
# legend('topright', legend=landscapeSizes, col=cols, lwd=3)
# say('######################################')
# say('### sensitivity of CBI to outliers ###')
# say('######################################')