-
Notifications
You must be signed in to change notification settings - Fork 0
/
figures_and_tables.Rout
1322 lines (1263 loc) · 50.8 KB
/
figures_and_tables.Rout
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
R version 3.6.1 (2019-07-05) -- "Action of the Toes"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R é um software livre e vem sem GARANTIA ALGUMA.
Você pode redistribuí-lo sob certas circunstâncias.
Digite 'license()' ou 'licence()' para detalhes de distribuição.
R é um projeto colaborativo com muitos contribuidores.
Digite 'contributors()' para obter mais informações e
'citation()' para saber como citar o R ou pacotes do R em publicações.
Digite 'demo()' para demonstrações, 'help()' para o sistema on-line de ajuda,
ou 'help.start()' para abrir o sistema de ajuda em HTML no seu navegador.
Digite 'q()' para sair do R.
[Área de trabalho anterior carregada]
> source("functions.R")
Carregando pacotes exigidos: stats4
Carregando pacotes exigidos: splines
Carregando pacotes exigidos: permute
Carregando pacotes exigidos: lattice
Registered S3 method overwritten by 'vegan':
method from
plot.preston untb
This is vegan 2.5-4
Attaching package: ‘vegan’
The following object is masked from ‘package:VGAM’:
calibrate
Carregando pacotes exigidos: bbmle
Attaching package: ‘bbmle’
The following object is masked from ‘package:VGAM’:
AICc
Attaching package: ‘sads’
The following objects are masked from ‘package:VGAM’:
dpareto, dzipf, ppareto, pzipf, qpareto, qzipf, rpareto, rzipf
Carregando pacotes exigidos: abc.data
Carregando pacotes exigidos: nnet
Carregando pacotes exigidos: quantreg
Carregando pacotes exigidos: SparseM
Attaching package: ‘SparseM’
The following object is masked from ‘package:base’:
backsolve
Carregando pacotes exigidos: MASS
Attaching package: ‘MASS’
The following object is masked from ‘package:untb’:
select
Carregando pacotes exigidos: locfit
locfit 1.5-9.1 2013-03-22
> library(dplyr)
Attaching package: ‘dplyr’
The following object is masked from ‘package:MASS’:
select
The following object is masked from ‘package:bbmle’:
slice
The following objects are masked from ‘package:untb’:
count, select
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
> library(tidyr)
Attaching package: ‘tidyr’
The following object is masked from ‘package:VGAM’:
fill
> ## Basic quantities and original (biased estimates), from script 'dataprep.R'
> load("lists_with_all_objects.RData")
> ## Summaries and posterior distributions of ABC analyses, from script 'abc_summaries.R'
> load("abcSummaries.RData")
> ## Bias analyses for estimates from logseries and tnb fitted to the sample for 2013 dataset , from script
> ## 'simulation_bias/ls_tnb_bias_parallel_2013.R'
> load("bias_ls_tnb_2013.RData")
> ## same for 2013 updated
> load("bias_ls_tnb_2013t.RData")
> ## same for 2019
> load("bias_ls_tnb_2019.RData")
> ## Bias analyses for model selection of ls, tnb, pln fitted to the samples, from script 'simulation_bias/model_selection_bias.R'
> load("bias_msel.RData")
> ## Bias analyses for estimates from LSE method on the estimated population sizes,
> ## from script 'simulation_bias/LSE_bias.R'
> load("bias_LSE.RData")
> ## Extrapolated species richness from simulated samples with clumping from a logseries
> ## from script 'richness_extrapolations.R'
> load("richness_extrapolation_19.RData")
>
> ################################################################################
> ## AIC Model selection table for ls, tnb, poilog models for each dataset
> ################################################################################
> ms13 <- (with(atdn.13, AICtab(y.nb2, y.ls, pln, weights = TRUE, sort=FALSE)))
> ms13t <- (with(atdn.13.tax, AICtab(y.nb2, y.ls, pln, weights = TRUE, sort=FALSE)))
> ms19 <- (with(atdn.19, AICtab(y.nb2, y.ls, pln, weights = TRUE, sort=FALSE)))
> tab.ms.all <- data.frame(
+ model = c("TNB", "LS", "PLN"),
+ df = ms13$df,
+ y.13 = ms13$dAIC,
+ y.13t = ms13t$dAIC,
+ y.19 = ms19$dAIC
+ )
> write.csv(tab.ms.all, row.names=FALSE, file = "figs_and_tables/AIC_model_selection_table.csv")
>
> ################################################################################
> ## BIC Model selection table for ls, tnb, poilog models for each dataset
> ################################################################################
> ms13.b <- (with(atdn.13, BICtab(y.nb2, y.ls, pln, weights = TRUE, sort=FALSE)))
> ms13t.b <- (with(atdn.13.tax, BICtab(y.nb2, y.ls, pln, weights = TRUE, sort=FALSE)))
> ms19.b <- (with(atdn.19, BICtab(y.nb2, y.ls, pln, weights = TRUE, sort=FALSE)))
> tab.ms.all.b <- data.frame(
+ model = c("TNB", "LS", "PLN"),
+ df = ms13.b$df,
+ y.13 = ms13.b$dBIC,
+ y.13t = ms13t.b$dBIC,
+ y.19 = ms19.b$dBIC
+ )
> write.csv(tab.ms.all, row.names=FALSE, file = "figs_and_tables/BIC_model_selection_table.csv")
>
>
> ################################################################################
> ## Table with estimated coefficients and SEs and likelihoods for ls, tnb, poilog models for each dataset
> ################################################################################
> tab.cf <- rbind(
+ cbind(with(atdn.13, summary(y.nb2)@coef[,1:2]),
+ with(atdn.13.tax, summary(y.nb2)@coef[,1:2]),
+ with(atdn.19, summary(y.nb2)@coef[,1:2])),
+ cbind(with(atdn.13, matrix(summary(y.ls)@coef[,1:2], nrow=1)),
+ with(atdn.13.tax, matrix(summary(y.ls)@coef[,1:2], nrow=1)),
+ with(atdn.19, matrix(summary(y.ls)@coef[,1:2], nrow=1))),
+ cbind(with(atdn.13, summary(pln)@coef[,1:2]),
+ with(atdn.13.tax, summary(pln)@coef[,1:2]),
+ with(atdn.19, summary(pln)@coef[,1:2]))
+ )
> colnames(tab.cf) <- paste(colnames(tab.cf), rep(c("2013","2013t","2019"),each=2))
> rownames(tab.cf)[rownames(tab.cf)==""] <- "alpha"
> write.csv(tab.cf, file = "figs_and_tables/model_coefficients.csv")
>
> ################################################################################
> ## ABC posterior probabilities for each model for each dataset
> ################################################################################
> tab.abc <- rbind(
+ summary(abc2013.summ$model.sel)$Prob,
+ summary(abc2013t.summ$model.sel)$Prob,
+ summary(abc2019.summ$model.sel)$Prob
+ )
Call:
postpr(target = target, index = abc2013$labels, sumstat = abc2013$sims,
tol = 0.01, method = "rejection", corr = TRUE)
Data:
postpr.out$values (600 posterior samples)
Models a priori:
LNclump, LNrnd, LSclump, LSrnd, NBclump, NBrnd
Models a posteriori:
LNclump, LNrnd, LSclump, LSrnd, NBclump, NBrnd
Proportion of accepted simulations (rejection):
LNclump LNrnd LSclump LSrnd NBclump NBrnd
0.0000 0.0000 0.7050 0.2917 0.0033 0.0000
Bayes factors:
LNclump LNrnd LSclump LSrnd NBclump NBrnd
LNclump 0.0000 0.0000 0.0000
LNrnd 0.0000 0.0000 0.0000
LSclump Inf Inf 1.0000 2.4171 211.5000 Inf
LSrnd Inf Inf 0.4137 1.0000 87.5000 Inf
NBclump Inf Inf 0.0047 0.0114 1.0000 Inf
NBrnd 0.0000 0.0000 0.0000
Call:
postpr(target = target, index = abc2013t$labels, sumstat = abc2013t$sims,
tol = 0.01, method = "rejection", corr = TRUE)
Data:
postpr.out$values (508 posterior samples)
Models a priori:
LNclump, LNrnd, LSclump, LSrnd, NBclump, NBrnd
Models a posteriori:
LNclump, LNrnd, LSclump, LSrnd, NBclump, NBrnd
Warning: Posterior model probabilities are corrected for unequal number of simulations per models.
Proportion of accepted simulations (rejection):
LNclump LNrnd LSclump LSrnd NBclump NBrnd
0.0000 0.0000 0.7579 0.2421 0.0000 0.0000
Bayes factors:
LNclump LNrnd LSclump LSrnd NBclump NBrnd
LNclump 0.0000 0.0000
LNrnd 0.0000 0.0000
LSclump Inf Inf 1.0000 3.1301 Inf Inf
LSrnd Inf Inf 0.3195 1.0000 Inf Inf
NBclump 0.0000 0.0000
NBrnd 0.0000 0.0000
Call:
postpr(target = target, index = abc2019$labels, sumstat = abc2019$sims,
tol = 0.01, method = "rejection", corr = TRUE)
Data:
postpr.out$values (570 posterior samples)
Models a priori:
LNclump, LNrnd, LSclump, LSrnd, NBclump, NBrnd
Models a posteriori:
LNclump, LNrnd, LSclump, LSrnd, NBclump, NBrnd
Warning: Posterior model probabilities are corrected for unequal number of simulations per models.
Proportion of accepted simulations (rejection):
LNclump LNrnd LSclump LSrnd NBclump NBrnd
0.0000 0.0000 0.9123 0.0877 0.0000 0.0000
Bayes factors:
LNclump LNrnd LSclump LSrnd NBclump NBrnd
LNclump 0.0000 0.0000
LNrnd 0.0000 0.0000
LSclump Inf Inf 1.0000 10.4000 Inf Inf
LSrnd Inf Inf 0.0962 1.0000 Inf Inf
NBclump 0.0000 0.0000
NBrnd 0.0000 0.0000
> rownames(tab.abc) <- c("2013","2013t","2019")
> write.csv(tab.abc, row.names=FALSE, file = "figs_and_tables/abc_post_table.csv")
>
>
> ################################################################################
> ## Tables with all estimates of species richness and CI's 95%
> ################################################################################
> ## Not exactly an elegant code, but alas, it works
>
> ## Table with original estimates and CI's (without bias correction) ##
> S.estimates <- expand.grid(
+ dataset = c("2013", "2013 updated", "2019"),
+ type = c("TNB", "LS", "LSE"),
+ mean = NA,
+ IC.low = NA,
+ IC.up = NA
+ )
> ## Add a missing column of sampling in simulations (to compatibility with the next table)
> S.estimates$sampling <- NA
> S.estimates <- S.estimates[,c(1:2,6,3:5)]
> ## Including the values
> ## Truncated negative binomial
> S.estimates[S.estimates$type=="TNB"&S.estimates$dataset=="2013",4:6] <-
+ with(atdn.13, c(tovo.S$S.est, tovo.S$CIs[4,2:1]))
> S.estimates[S.estimates$type=="TNB"&S.estimates$dataset=="2013 updated",4:6] <-
+ with(atdn.13.tax, c(tovo.S$S.est, tovo.S$CIs[4,2:1]))
> S.estimates[S.estimates$type=="TNB"&S.estimates$dataset=="2019",4:6] <-
+ with(atdn.19, c(tovo.S$S.est, tovo.S$CIs[4,2:1]))
> ## Log-series
> S.estimates[S.estimates$type=="LS"&S.estimates$dataset=="2013",4:6] <-
+ with(atdn.13, c(S.ls, S.ls.ci))
> S.estimates[S.estimates$type=="LS"&S.estimates$dataset=="2013 updated",4:6] <-
+ with(atdn.13.tax, c(S.ls, S.ls.ci))
> S.estimates[S.estimates$type=="LS"&S.estimates$dataset=="2019",4:6] <-
+ with(atdn.19, c(S.ls, S.ls.ci))
> ## Linear extension of RAD of estimated pop sizes (LSE)
> S.estimates[S.estimates$type=="LSE"&S.estimates$dataset=="2013",4:6] <-
+ with(atdn.13, S.ulrich$S[1,2:4])
> S.estimates[S.estimates$type=="LSE"&S.estimates$dataset=="2013 updated",4:6] <-
+ with(atdn.13.tax, S.ulrich$S[1,2:4])
> S.estimates[S.estimates$type=="LSE"&S.estimates$dataset=="2019",4:6] <-
+ with(atdn.19, S.ulrich$S[1,2:4])
>
> ## Table of Bias-corrected estimates ##
> S.estimates.bc <- expand.grid(
+ sampling = c("rnd", "clump"),
+ type = c("TNB", "LS", "LSE LS", "ABC"),
+ dataset = c("2013", "2013 updated", "2019"),
+ mean = NA,
+ IC.low = NA,
+ IC.up = NA,
+ stringsAsFactors=FALSE
+ )[c(3:1,4:6)]
> ## Including the values
> ## Truncated negative binomial
> type <- "TNB"
> ## 2013
> dataset <- "2013"
> obj <- bias13$tnb
> S.estimates.bc[S.estimates.bc$type==type&S.estimates.bc$dataset==dataset,4:6] <-
+ bias.ci(obj, ci.vector = S.estimates[S.estimates$type==type&S.estimates$dataset==dataset,4:6])
> ##2013 updated
> dataset <- "2013 updated"
> obj <- bias13t$tnb
> S.estimates.bc[S.estimates.bc$type==type&S.estimates.bc$dataset==dataset,4:6] <-
+ bias.ci(obj, ci.vector = S.estimates[S.estimates$type==type&S.estimates$dataset==dataset,4:6])
> ## 2019
> dataset <- "2019"
> obj <- bias19$tnb
> S.estimates.bc[S.estimates.bc$type==type&S.estimates.bc$dataset==dataset,4:6] <-
+ bias.ci(obj, ci.vector = S.estimates[S.estimates$type==type&S.estimates$dataset==dataset,4:6])
> ## Logseries
> type <- "LS"
> ## 2013
> dataset <- "2013"
> obj <- bias13$ls
> S.estimates.bc[S.estimates.bc$type==type&S.estimates.bc$dataset==dataset,4:6] <-
+ bias.ci(obj, ci.vector = S.estimates[S.estimates$type==type&S.estimates$dataset==dataset,4:6], method="lm")
> ##2013 updated
> dataset <- "2013 updated"
> obj <- bias13t$ls
> S.estimates.bc[S.estimates.bc$type==type&S.estimates.bc$dataset==dataset,4:6] <-
+ bias.ci(obj, ci.vector = S.estimates[S.estimates$type==type&S.estimates$dataset==dataset,4:6], method="lm")
> ## 2019
> dataset <- "2019"
> obj <- bias19$ls
> S.estimates.bc[S.estimates.bc$type==type&S.estimates.bc$dataset==dataset,4:6] <-
+ bias.ci(obj, ci.vector = S.estimates[S.estimates$type==type&S.estimates$dataset==dataset,4:6], method="lm")
> ## LSE (linear extension of the RAD of estimated population sizes, assuming a log-series RAD)
> type <- "LSE LS"
> ## 2013
> dataset <- "2013"
> obj <- bias.lse.13$ls
> S.estimates.bc[S.estimates.bc$type==type&S.estimates.bc$dataset==dataset,4:6] <-
+ bias.ci(obj, ci.vector = S.estimates[S.estimates$type=="LSE"&S.estimates$dataset==dataset,4:6], method="lm")
> ##2013 updated
> dataset <- "2013 updated"
> obj <- bias.lse.13t$ls
> S.estimates.bc[S.estimates.bc$type==type&S.estimates.bc$dataset==dataset,4:6] <-
+ bias.ci(obj, ci.vector = S.estimates[S.estimates$type=="LSE"&S.estimates$dataset==dataset,4:6], method="lm")
> ## 2019
> dataset <- "2019"
> obj <- bias.lse.19$ls
> S.estimates.bc[S.estimates.bc$type==type&S.estimates.bc$dataset==dataset,4:6] <-
+ bias.ci(obj, ci.vector = S.estimates[S.estimates$type=="LSE"&S.estimates$dataset==dataset,4:6], method="lm")
> ## ABC (only the selected model)
> S.estimates.bc[S.estimates.bc$type=="ABC"&S.estimates.bc$dataset=="2013"&S.estimates.bc$sampling=="clump",4:6] <-
+ summary(abc2013.summ$S.post1)[c(4,2,6),]
Call:
abc(target = target, param = data.frame(S = abc2013$params[index]),
sumstat = abc2013$sims[index, ], tol = 0.05, method = "loclinear")
Data:
abc.out$adj.values (500 posterior samples)
Weights:
abc.out$weights
S
Min.: 16138.15
Weighted 2.5 % Perc.: 16145.22
Weighted Median: 16163.76
Weighted Mean: 16163.64
Weighted Mode: 16161.27
Weighted 97.5 % Perc.: 16180.56
Max.: 16191.92
> S.estimates.bc[S.estimates.bc$type=="ABC"&S.estimates.bc$dataset=="2013 updated"&S.estimates.bc$sampling=="clump",4:6] <-
+ summary(abc2013t.summ$S.post1)[c(4,2,6),]
Call:
abc(target = target, param = data.frame(S = abc2013t$params[index]),
sumstat = abc2013t$sims[index, ], tol = 0.01, method = "loclinear")
Data:
abc.out$adj.values (100 posterior samples)
Weights:
abc.out$weights
S
Min.: 14538.47
Weighted 2.5 % Perc.: 14746.78
Weighted Median: 14950.65
Weighted Mean: 14940.69
Weighted Mode: 14873.35
Weighted 97.5 % Perc.: 15131.96
Max.: 15168.43
> S.estimates.bc[S.estimates.bc$type=="ABC"&S.estimates.bc$dataset=="2019"&S.estimates.bc$sampling=="clump",4:6] <-
+ summary(abc2019.summ$S.post1)[c(4,2,6),]
Call:
abc(target = target, param = data.frame(S = abc2019$params[index]),
sumstat = abc2019$sims[index, ], tol = 0.05, method = "loclinear",
numnet = 100)
Data:
abc.out$adj.values (500 posterior samples)
Weights:
abc.out$weights
S
Min.: 15485.58
Weighted 2.5 % Perc.: 15556.79
Weighted Median: 15671.26
Weighted Mean: 15666.44
Weighted Mode: 15677.99
Weighted 97.5 % Perc.: 15748.88
Max.: 15817.95
> ## A single table with all values (for supplemmentary material) ##
> S.estimates.all <- rbind(S.estimates.bc, S.estimates)
> S.estimates.all$bias.corrected <- !is.na(S.estimates.all$sampling)
>
> write.csv(S.estimates.all, row.names=FALSE, file = "figs_and_tables/estimates_S_table.csv")
>
> ################################################################################
> ## Figures with relationship estimated x true values of Species Richness
> ################################################################################
> ## auxiliary ploting functions ##
> ## True x estimated values
> bias.p1 <- function(bias.est, point, lower, upper, reg.line = TRUE, ...){
+ plot(S ~ S.est.rnd, data = bias.est, type= "n", ...)
+ rect(lower,0,upper,max(bias.est$S)*1.1,col="lightgrey", border=NA)
+ box()
+ points(S ~ S.est.rnd, data = bias.est, col="blue", cex=0.5)
+ points(S ~ S.est.clump, data = bias.est, col="red", cex=0.5)
+ abline(0,1)
+ if(reg.line){
+ lm1 <- lm(S ~ S.est.rnd, data = bias.est, subset=S.est.rnd>=lower&S.est.rnd<=upper)
+ plm1 <- predict(lm1,data.frame(S.est.rnd=c(point,lower,upper)))
+ lm2 <- lm(S ~ S.est.clump, data = bias.est, subset=S.est.clump>=lower&S.est.clump<=upper)
+ plm2 <- predict(lm2,data.frame(S.est.clump=c(point,lower,upper)))
+ lines(c(point,lower,upper), plm1, col="blue", lwd=3)
+ lines(c(point,lower,upper), plm2, col="red", lwd=3)
+ }
+ }
> ## Point and range bias-corrected estimates
> bias.p2 <- function(dataset, type, ...){
+ df <- S.estimates.all[S.estimates.all$dataset==dataset & S.estimates.all$type==type & S.estimates.all$bias.corrected,]
+ df <- df[order(df$sampling),]
+ plot(df$mean ~ c(1,2), type = "n",
+ axes=FALSE,
+ xlab="", ylab="", xlim=c(0.5,2.5), ...)
+ segments(x0=1:2, x1=1:2, y0=df$IC.low, y1=df$IC.up, col=c("red", "blue"), lwd=2)
+ points(1:2, df$mean, col=c("red", "blue"), cex=2)
+ }
>
> ### Plots for each data set ###
>
> ## 2013 ##
> pdf("figs_and_tables/estSxS_2013.pdf", width = 12, height = 11)
> nf <- layout(
+ matrix(
+ c( c(1,2:5),c(1,6:9), c(1,rep(10,4)) ),
+ nrow = 3,
+ ncol = 5,
+ byrow = TRUE
+ ),
+ widths = c(0.5, rep(c(0.5,3),2)),
+ heights= c(3,3,0.5))
> ## Y axis label
> par(las = 0, mar=c(0,4,0,0), cex.axis=1.25)
> plot(0,0, xlim=c(0,1), ylim =c(0,1), axes=FALSE, xlab="", ylab="", type="n")
> mtext(text = "Number of species in simulated communities", side=2, cex = 1.5)
> ## Logseries #
> par(mar = c(5, 0, 4, 0))
> bias.p2("2013", "LS", ylim=atdn.13$S.ls.ci*c(.9,1.1))
> par(mar = c(5, 2, 4, 4), cex.main=1.5)
> bias.p1(bias13$ls$estimates, atdn.13$S.ls, atdn.13$S.ls.ci[1], atdn.13$S.ls.ci[2],
+ ylim = atdn.13$S.ls.ci*c(.9,1.1),
+ xlim = atdn.13$S.ls.ci*c(.9,1.1),
+ ylab = "", xlab = "", main = "LS")
> # LSE
> par(mar = c(5, 0, 4, 0))
> bias.p2("2013", "LSE LS", ylim=c(1.5e4,1.95e4))
> par(mar = c(5, 2, 4, 4))
> bias.p1(bias.lse.13$ls$estimates, atdn.13$S.ulrich$S$boot.mean[1],
+ atdn.13$S.ulrich$S$boot.CI.low[1], atdn.13$S.ulrich$S$boot.CI.up[1],
+ ylim = c(1.5e4,1.95e4),
+ xlim = c(1.4e4,1.6e4),
+ ylab = "", xlab = "", main = "LSE")
> ## TNB
> par(mar = c(5, 0, 5, 0))
> bias.p2("2013", "TNB", ylim=range(bias13$tnb$estimates$S))
> par(mar = c(5, 2, 4, 4))
> bias.p1(bias13$tnb$estimates, atdn.13$tovo.S$S.est,
+ atdn.13$tovo.S$CIs[4,2], atdn.13$tovo.S$CIs[4,1],
+ reg.line=FALSE,
+ ylim = range(bias13$tnb$estimates$S),
+ ylab = "", xlab = "", main = "TNB")
> ## X axis
> par(mar=c(2,0,1,0))
> plot(0,0, xlim=c(0,1), ylim =c(0,1), axes=FALSE, xlab="", ylab="", type="n")
> mtext(text = "Estimated number of species from simulated samples", side=1, cex = 1.5)
> dev.off()
null device
1
>
> ## 2013 updated ##
> pdf("figs_and_tables/estSxS_2013t.pdf", width = 12, height = 11)
> nf <- layout(
+ matrix(
+ c( c(1,2:5),c(1,6:9), c(1,rep(10,4)) ),
+ nrow = 3,
+ ncol = 5,
+ byrow = TRUE
+ ),
+ widths = c(0.5, rep(c(0.5,3),2)),
+ heights= c(3,3,0.5))
> ## Y axis label
> par(las = 0, mar=c(0,4,0,0), cex.axis=1.25)
> plot(0,0, xlim=c(0,1), ylim =c(0,1), axes=FALSE, xlab="", ylab="", type="n")
> mtext(text = "Number of species in simulated communities", side=2, cex = 1.5)
> ## Logseries #
> par(mar = c(5, 0, 4, 0))
> bias.p2("2013 updated", "LS", ylim=atdn.13.tax$S.ls.ci*c(.9,1.1))
> par(mar = c(5, 2, 4, 4), cex.main=1.5)
> bias.p1(bias13t$ls$estimates, atdn.13.tax$S.ls, atdn.13.tax$S.ls.ci[1], atdn.13.tax$S.ls.ci[2],
+ ylim = atdn.13.tax$S.ls.ci*c(.9,1.1),
+ xlim = atdn.13.tax$S.ls.ci*c(.9,1.1),
+ ylab = "", xlab = "", main = "LS")
> # LSE
> par(mar = c(5, 0, 4, 0))
> bias.p2("2013 updated", "LSE LS", ylim=c(1.25e4,1.65e4))
> par(mar = c(5, 2, 4, 4))
> bias.p1(bias.lse.13t$ls$estimates, atdn.13.tax$S.ulrich$S$boot.mean[1],
+ atdn.13.tax$S.ulrich$S$boot.CI.low[1], atdn.13.tax$S.ulrich$S$boot.CI.up[1],
+ ylim = c(1.25e4,1.65e4),
+ xlim = c(1.3e4,1.45e4),
+ ylab = "", xlab = "", main = "LSE")
> ## TNB
> par(mar = c(5, 0, 5, 0))
> bias.p2("2013 updated", "TNB", ylim=range(bias13t$tnb$estimates$S))
> par(mar = c(5, 2, 4, 4))
> bias.p1(bias13t$tnb$estimates, atdn.13.tax$tovo.S$S.est,
+ atdn.13.tax$tovo.S$CIs[4,2], atdn.13.tax$tovo.S$CIs[4,1],
+ reg.line=FALSE,
+ ylim = range(bias13t$tnb$estimates$S),
+ xlim = range(bias13$tnb$estimates$S.est.rnd),
+ ylab = "", xlab = "", main = "TNB")
> ## X axis
> par(mar=c(2,0,1,0))
> plot(0,0, xlim=c(0,1), ylim =c(0,1), axes=FALSE, xlab="", ylab="", type="n")
> mtext(text = "Estimated number of species from simulated samples", side=1, cex = 1.5)
> dev.off()
null device
1
>
>
> ## 2019 ##
> pdf("figs_and_tables/estSxS_2019.pdf", width = 12, height = 11)
> nf <- layout(
+ matrix(
+ c( c(1,2:5),c(1,6:9), c(1,rep(10,4)) ),
+ nrow = 3,
+ ncol = 5,
+ byrow = TRUE
+ ),
+ widths = c(0.5, rep(c(0.5,3),2)),
+ heights= c(3,3,0.5))
> ## Y axis label
> par(las = 0, mar=c(0,4,0,0), cex.axis=1.25)
> plot(0,0, xlim=c(0,1), ylim =c(0,1), axes=FALSE, xlab="", ylab="", type="n")
> mtext(text = "Number of species in simulated communities", side=2, cex = 1.5)
> ## Logseries #
> par(mar = c(5, 0, 4, 0))
> bias.p2("2019", "LS", ylim=atdn.19$S.ls.ci*c(.9,1.1))
> par(mar = c(5, 2, 4, 4), cex.main=1.5)
> bias.p1(bias19$ls$estimates, atdn.19$S.ls, atdn.19$S.ls.ci[1], atdn.19$S.ls.ci[2],
+ ylim = atdn.19$S.ls.ci*c(.9,1.1),
+ xlim = atdn.19$S.ls.ci*c(.9,1.1),
+ ylab = "", xlab = "", main = "LS")
> # LSE
> par(mar = c(5, 0, 4, 0))
> bias.p2("2019", "LSE LS", ylim=c(1.4e4,1.72e4))
> par(mar = c(5, 2, 4, 4))
> bias.p1(bias.lse.19$ls$estimates, atdn.19$S.ulrich$S$boot.mean[1],
+ atdn.19$S.ulrich$S$boot.CI.low[1], atdn.19$S.ulrich$S$boot.CI.up[1],
+ ylim = c(1.4e4,1.72e4),
+ xlim = c(1.4e4,1.55e4),
+ ylab = "", xlab = "", main = "LSE")
> ## TNB
> par(mar = c(5, 0, 5, 0))
> bias.p2("2019", "TNB", ylim=range(bias19$tnb$estimates$S))
> par(mar = c(5, 2, 4, 4))
> bias.p1(bias19$tnb$estimates, atdn.19$tovo.S$S.est,
+ atdn.19$tovo.S$CIs[4,2], atdn.19$tovo.S$CIs[4,1],
+ reg.line=FALSE,
+ ylim = range(bias19$tnb$estimates$S),
+ xlim = range(bias13$tnb$estimates$S.est.rnd),
+ ylab = "", xlab = "", main = "TNB")
> ## X axis
> par(mar=c(2,0,1,0))
> plot(0,0, xlim=c(0,1), ylim =c(0,1), axes=FALSE, xlab="", ylab="", type="n")
> mtext(text = "Estimated number of species from simulated samples", side=1, cex = 1.5)
> dev.off()
null device
1
>
> ## Separated plots for CHAO ###
> p.chaob <- function(dado, ...){
+ plot(S.est.rnd ~ S, data=dado, ylim=range(dado[,-1]), type="n", ...)
+ points(S.est.rnd ~ S, data=dado, col = "blue")
+ points(S.est.clump ~ S, data=dado, col = "red")
+ }
> pdf("figs_and_tables/bias_chao.pdf", width=12, height=7)
> par(mar = c(5, 5, 4, 2) + 0.1,
+ mgp = c(3.5, 1, 0),
+ oma=c(3,3,0,0),
+ las = 0,
+ bty = "l",
+ cex.main = 1.5,
+ cex.lab = 1.4, font.lab = 2, cex.axis = 1.25,
+ lwd = 2,
+ mfrow=c(1,2))
> p.chaob(bias.chao.19$ls$estimates, xlab="Species richness", ylab="Estimated species richness (CHAO)", main="LS community")
> p.chaob(bias.chao.19$tnb$estimates, xlab="Species richness", ylab="Estimated species richness (CHAO)", main="TNB community")
> dev.off()
null device
1
>
> ################################################################################
> ## Dotplots of estimated Species Richness and ABC estimates##
> ################################################################################
>
> pdf("figs_and_tables/bias_corrected_estimates_dotchart.pdf")
> par(cex.main = 1.5,
+ cex.lab = 1.25,
+ font.lab = 2,
+ cex.axis = 1.25)
> ## Bias-corrected estimates (assuming clumped sampling) ##
> tmp1 <- S.estimates.bc[S.estimates.bc$sampling=="clump"&S.estimates.bc$type!="LSE TNB",]
> tmp1$type[tmp1$type=="LSE LS"] <- "LSE"
> tmp1$type <- factor(tmp1$type, levels=c("TNB", "LS","ABC","LSE"))
> tmp1 <- tmp1[order(tmp1$type,tmp1$dataset),]
> with(tmp1,
+ dotchart(mean, labels = dataset, groups = type, color=2:4, pch=1,
+ pt.cex = 1.5,
+ xlab = "Estimated species richness",
+ xlim=range(c(IC.low, IC.up),na.rm=TRUE))
+ )
> ## Adds error bars
> Ys <- 16:18 - rep(seq(0,15, by=5), each=3)
> cores <- rep(2:4,4)
> for(i in 1:nrow(tmp1))
+ segments(x0=tmp1$IC.low[i], x1=tmp1$IC.up[i], y0=Ys[i], y1=Ys[i],
+ col=cores[i], lwd =1.5)
> dev.off()
null device
1
>
>
> ## Original (biased) estimates ##
> pdf("figs_and_tables/uncorrected_estimates_dotchart.pdf")
> par(cex.main = 1.5,
+ cex.lab = 1.25,
+ font.lab = 2,
+ cex.axis = 1.25)
> with(S.estimates,
+ dotchart(mean, labels = dataset, groups = type, color=2:4, pch=1,
+ pt.cex = 1.5,
+ xlim=range(c(S.estimates$IC.low, S.estimates$IC.up),na.rm=TRUE),
+ xlab = "Estimated species richness")
+ )
> Ys <- c(11:13, 6:8, 1:3)
> cores <- rep(2:4,3)
> for(i in 1:nrow(S.estimates))
+ segments(x0=S.estimates$IC.low[i], x1=S.estimates$IC.up[i], y0=Ys[i], y1=Ys[i],
+ col=cores[i], lwd =1.5)
> dev.off()
null device
1
>
> ## Bias corrected with both types of sampling (random and clumped) ##
> ## Auxiliary function
> f11 <- function(x, type, ...){
+ tmp3 <- x[x$type==type,]
+ with(tmp3,
+ dotchart(mean, labels = sampling, groups = factor(dataset),
+ color=2:4,
+ pch=1,
+ pt.cex = 1.5,
+ #xlim=range(c(IC.low, IC.up),na.rm=TRUE),
+ ...
+ )
+ )
+ ## Errors bars
+ Ys <- 11:13 - rep(seq(0,10, by=5), each=3)
+ cores <- rep(2:4,4)
+ for(i in 1:nrow(tmp3))
+ segments(x0=tmp3$IC.low[i], x1=tmp3$IC.up[i], y0=Ys[i], y1=Ys[i],
+ col=cores[i], lwd =1.5)
+ }
> #####################################################################################
> tmp2 <- S.estimates.all[S.estimates.all$type!="LSE TNB"&S.estimates.all$type!="ABC",]
> tmp2$type[tmp2$type=="LSE LS"] <- "LSE"
> tmp2$sampling[is.na(tmp2$sampling)] <- "Not corrected"
> tmp2$sampling <- factor(tmp2$sampling, levels=c("Not corrected", "rnd", "clump"))
> tmp2 <- tmp2[order(tmp2$dataset,tmp2$sampling),]
>
> pdf("figs_and_tables/bias_corrected_estimates_rnd_clump_dotchart.pdf", width = 7, height = 12)
> par(cex.main = 1.5,
+ cex.lab = 1.25,
+ font.lab = 2,
+ cex.axis = 1.5,
+ mfrow = c(3,1))
> f11(tmp2, "LS", xlab = "", main= "LS", xlim=range(tmp2[,5:6]))
> f11(tmp2, "TNB", xlab = "", main= "TNB", xlim=range(tmp2[,5:6]))
> f11(tmp2, "LSE", xlab = "Estimated species richness", main= "LSE", xlim=range(tmp2[,5:6]))
> dev.off()
null device
1
>
>
> ################################################################################
> ## Plots of Population rad expected by ABC ##
> ################################################################################
>
> ## 2013
> S1 <- S.estimates.all[S.estimates.all$type=="ABC"&S.estimates.all$dataset=="2013"&S.estimates.all$sampling=="clump",4:6]
> abc13.sim.pop <- with(atdn.13,
+ lapply(S1, sim.abc, sad = "ls",
+ N = Tot.t, tot.area = Tot.A, n.plots = N.plots,
+ lm.sd.fit = lm.sd, lmk.fit = lm.k, nb.fit =y.nb2,
+ summary = FALSE, upper=1e16) )
> ## 2013 with updated taxonomy
> S1 <- S.estimates.all[S.estimates.all$type=="ABC"&S.estimates.all$dataset=="2013 updated"&S.estimates.all$sampling=="clump",4:6]
> abc13t.sim.pop <- with(atdn.13.tax,
+ lapply(S1,
+ sim.abc, sad = "ls",
+ N = Tot.t, tot.area = Tot.A, n.plots = N.plots,
+ lm.sd.fit = lm.sd, lmk.fit = lm.k, nb.fit =y.nb2,
+ summary = FALSE, upper=1e16) )
> ## 2019
> S1 <- S.estimates.all[S.estimates.all$type=="ABC"&S.estimates.all$dataset=="2019"&S.estimates.all$sampling=="clump",4:6]
> abc19.sim.pop <- with(atdn.19,
+ lapply(S1,
+ sim.abc, sad = "ls",
+ N = Tot.t, tot.area = Tot.A, n.plots = N.plots,
+ lm.sd.fit = lm.sd, lmk.fit = lm.k, nb.fit =y.nb2,
+ summary = FALSE, upper=1e16) )
>
>
> ## The plots for ##
> pdf("figs_and_tables/population_RADS_and_ABC_predictions%d.pdf", onefile=TRUE)
> par(cex.main = 1.5, lwd=2,
+ mar = c(5, 4, 4, 2) + 0.1,
+ mgp = c(3.5, 1, 0),
+ cex.lab = 1.25, font.lab = 2, cex.axis = 1.2, bty = "l", las = 1,
+ oma=c(3,3,0,0))
> ## 2013
> plot(rad(atdn.13$data$population), xlim=c(1,6e3), col="grey", ylab="")
> par(las=0)
> mtext("Species abundances", 2, cex =1.25, font = 2, line = 4.5)
> par(las=1)
> lines(rad(abc13.sim.pop$mean$clump.samp[,2]))
> lines(rad(abc13.sim.pop$IC.low$clump.samp[,2]), lty=2)
> lines(rad(abc13.sim.pop$IC.up$clump.samp[,2]), lty=2)
> ## 2013 updated
> plot(rad(atdn.13.tax$data$population), xlim=c(1,6e3), col="grey", ylab = "")
> par(las=0)
> mtext("Species abundances", 2, cex =1.25, font = 2, line = 4.5)
> par(las=1)
> lines(rad(abc13t.sim.pop$mean$clump.samp[,2]))
> lines(rad(abc13t.sim.pop$IC.low$clump.samp[,2]), lty=2)
> lines(rad(abc13t.sim.pop$IC.up$clump.samp[,2]), lty=2)
> ## 2019
> plot(rad(atdn.19$data$population), xlim=c(1,6e3), col="grey", ylab = "")
> par(las=0)
> mtext("Species abundances", 2, cex =1.25, font = 2, line = 4.5)
> par(las=1)
> lines(rad(abc19.sim.pop$mean$clump.samp[,2]))
> lines(rad(abc19.sim.pop$IC.low$clump.samp[,2]), lty=2)
> lines(rad(abc19.sim.pop$IC.up$clump.samp[,2]), lty=2)
> dev.off()
null device
1
>
> ################################################################################
> ## Plots of aggregation coefficients x mean population abundances
> ################################################################################
> ##Utility function
> f12 <- function(obj, ...){
+ with(obj,{
+ cf1 <- coef(lm.k)
+ plot(k ~ dens.ha, data= data, log = "xy", ...)
+ curve(exp(cf1[1])*x^cf1[2], add=TRUE, col = 4)
+ }
+ )
+ }
> ###################################
> yl1 <- range(atdn.13$data$k,atdn.13.tax$data$k,atdn.19$data$k[atdn.19$data$k<1])
> xl1 <- range(atdn.13$data$dens.ha,atdn.13.tax$data$dens.ha,atdn.19$data$dens.ha)
> pdf("figs_and_tables/kXdens.pdf", width = 12, height = 4.25)
> par(mar = c(5, 5, 4, 2) + 0.1,
+ mgp = c(3.5, 1, 0),
+ oma=c(3,3,0,0),
+ las = 0,
+ bty = "l",
+ cex.main = 1.5,
+ cex.lab = 1.4, font.lab = 2, cex.axis = 1.25,
+ lwd = 2,
+ mfrow=c(1,3))
> f12(atdn.13,
+ ylab = "",
+ xlab="",
+ xlim = xl1, ylim = yl1,
+ main = "2013", col="grey", cex=0.25
+ )
> mtext("Dispersion coefficient", cex=1.5, font =2, side = 2, line=5)
> f12(atdn.13.tax, ylab = "",
+ xlab="",
+ xlim = xl1, ylim = yl1,
+ main = "2013 updated", col="grey", cex=0.25)
> mtext(expression(paste("Density (",ha^{-1},")")), cex=1.5, font = 2, side = 1, line= 6)
> f12(atdn.19,
+ ylab = "",
+ xlab="",
+ xlim = xl1, ylim = yl1,
+ main = "2019", col="grey", cex=0.25)
> dev.off()
null device
1
>
>
> ################################################################################
> ## Plots of sd deviations x mean of population abundances
> ################################################################################
> f13 <- function(obj, ...){
+ with(obj,{
+ cf1 <- coef(lm.sd)
+ plot(pop.sd ~ population, data= data, log = "xy", ...)
+ curve(exp(cf1[1])*x^cf1[2], add=TRUE, col = 4)
+ }
+ )
+ }
>
> yl1 <- range(atdn.13$data$pop.sd,atdn.13.tax$data$pop.sd,atdn.19$data$pop.sd[atdn.19$data$pop.sd<1])
> xl1 <- range(atdn.13$data$population,atdn.13.tax$data$population,atdn.19$data$population)
> pdf("figs_and_tables/sdXpopsize.pdf", width = 12, height = 4.25)
> par(mar = c(5, 5, 4, 2) + 0.1,
+ mgp = c(3.5, 1, 0),
+ oma=c(3,3,0,0),
+ las = 0,
+ bty = "l",
+ cex.main = 1.5,
+ cex.lab = 1.4, font.lab = 2, cex.axis = 1.25,
+ lwd = 2,
+ mfrow=c(1,3))
> f13(atdn.13,
+ ylab = "",
+ xlab="",
+ xlim = xl1, ylim = yl1,
+ main = "2013", col="grey", cex=0.25
+ )
> mtext("Standard deviation", cex=1.5, font =2, side = 2, line=5)
> f13(atdn.13.tax, ylab = "",
+ xlab="",
+ xlim = xl1, ylim = yl1,
+ main = "2013 updated", col="grey", cex=0.25)
> mtext("Estimated population size", cex=1.5, font = 2, side = 1, line= 6)
> f13(atdn.19,
+ ylab = "",
+ xlab="",
+ xlim = xl1, ylim = yl1,
+ main = "2019", col="grey", cex=0.25)
> dev.off()
null device
1
>
>
> ################################################################################
> ## Plots of model selection biases
> ################################################################################
>
> pdf("figs_and_tables/bias_model_selection.pdf", width = 9, height = 9)
> par(mar = c(5, 5, 4, 2) + 0.1,
+ mgp = c(3.5, 1, 0),
+ oma=c(3,3,0,0),
+ las = 1,
+ bty = "l",
+ cex.main = 1.15,
+ cex.lab = 1, font.lab = 2, cex.axis = 1,
+ lwd = 2,
+ mfrow=c(2,2))
> plot(ls.rnd.w.aic ~ S, data = bias.msel.19$ls, ylim = c(0,1),
+ xlab = "",
+ ylab = "AIC Evidence weight of logseries fit",
+ main = "Logseries community")
> points(ls.clump.w.aic ~ S, data = bias.msel.19$ls, col = 2)
> plot(ls.rnd.w.aic ~ S, data = bias.msel.19$tnb, ylim = c(0,1),
+ xlab = "",
+ ylab = "",
+ main = "Negative binomial community")
> points(ls.clump.w.aic ~ S, data = bias.msel.19$tnb, col = 2)
> legend("topright", c("Random", "Clumped"), col=c(1,2), cex = 1, pch =1, bty="n")
> plot(ls.rnd.w.bic ~ S, data = bias.msel.19$ls, ylim = c(0,1),
+ xlab = "Species richness in the community",
+ ylab = "BIC Evidence weight of logseries fit",
+ main = "")
> points(ls.clump.w.bic ~ S, data = bias.msel.19$ls, col = 2)
> plot(ls.rnd.w.bic ~ S, data = bias.msel.19$tnb, ylim = c(0,1),
+ xlab = "Species richness in the community",
+ ylab = "",
+ main = "")
> points(ls.clump.w.bic ~ S, data = bias.msel.19$tnb, col = 2)
> dev.off()
null device
1
>
>
> ################################################################################
> ## Population RAD and regional LS
> ################################################################################
> ## Species richness estimates and CI's to use:
> ## from ABC
> ## S1 <- unlist(S.estimates.all[S.estimates.all$type=="ABC"&S.estimates.all$dataset=="2019"&S.estimates.all$sampling=="clump",4:6])
> ## Mean of estimates weighted by uncertainty, excluding TNB. ICs as the range of IC
> S1 <-
+ read.csv("figs_and_tables/estimates_S_table.csv") %>%
+ filter(bias.corrected==TRUE&type!="LSE TNB"&sampling=="clump"&type!="TNB"&dataset=="2019") %>%
+ mutate(se = (IC.up-IC.low)/4)%>%
+ summarise(w.mean = weighted.mean(mean, w=1/se), min=min(IC.low), max=max(IC.up)) %>%
+ unlist()
>
> ## Simulated regional rads
> ls.m <- rad.ls(S = S1[1], N = atdn.19$Tot.t)
> ls.low <- rad.ls(S = S1[2], N = atdn.19$Tot.t)
> ls.up <- rad.ls(S = S1[3], N = atdn.19$Tot.t)
> ## Simulated population sizes
> abc19.sim.pop <- with(atdn.19,
+ lapply(S1, sim.abc, N = Tot.t, sad = "ls", tot.area = Tot.A, n.plots = N.plots,
+ lm.sd.fit = lm.sd, lmk.fit = lm.k, nb.fit = y.nb2, summary = FALSE))
> ## Hyperdominants
> hd <- round(atdn.19$HD$summary[c(2,4:5)])
> ## The figure
> pdf("figs_and_tables/pop_rad_with_predicted_rad.pdf")
> par(bty = "l", lwd = 2)
> plot(rad(atdn.19$data$population), xlim = c(1, S1[3]),
+ ##ylim=c(min(c(ls.m$y, ls.up$y, ls.low$y)), max(atdn.19$data$population)),
+ ylim = c(1, max(atdn.19$data$population)),
+ axes=FALSE , #yaxs="i",
+ col=rep(c("red","darkgrey"), c(hd[1], length(atdn.19$data$population)-hd[1])),
+ cex.lab = 1.25, font.lab = 2, cex.axis = 1.2)
> axis(1, at=c(1, seq(2500,17500, by=2500)))
> axis(2)
> lines(rad(ceiling(ls.m$y)), col="darkblue")
> lines(rad(ls.low$y), lty=2, col="darkblue")
> lines(rad(ls.up$y), lty=2, col="darkblue")
> text(1.7e4, 1e9, paste("Nr of hyperdominant species = ",hd[1]," (",hd[2]," - ",hd[3],")", sep=""), font=2, pos=2)
> text(1.7e4, 0.25e9, paste("Estimated tree species = ",round(S1[1])," (",round(S1[2])," - ",round(S1[3]),")", sep=""), font=2, pos=2)
> par(fig=c(0.09,0.49,0.05,0.50),
+ mgp = c(2.5,0.5,0),
+ ##mar = c(5,4,4,2),
+ new = T, cex.axis = 0.8, cex.lab=1,
+ ##yaxp=c(1,3,3),
+ bty="o")
> plot(rad(atdn.19$data$population), xlim=c(1,6e3),
+ col="grey", ylab = "", xlab="", cex=0.75, axes = F)
> axis(2, at=c(1e6, 1e9), labels=c("","1e+09"))
> axis(1, at=c(1,2500,5000), labels=c("","","5000"))
> lines(rad(abc19.sim.pop[[1]]$clump.samp[,2]))
> lines(rad(abc19.sim.pop[[2]]$clump.samp[,2]), lty=2)
> lines(rad(abc19.sim.pop[[3]]$clump.samp[,2]), lty=2)
> par(fig=c(0,1,0,1))
> dev.off()
null device
1
>
> ################################################################################
> ## Simulating number of species recorded with increased sample size
> ################################################################################
> ## assembles the data for clumped sampling in a dataframe
> sim.rich <- with(S.proj.19,
+ data.frame(
+ n.plots = n.plots,
+ mean = matrix(unlist(S.est.mean), byrow=TRUE, ncol=2)[,2],
+ low = matrix(unlist(S.est.low), byrow=TRUE, ncol=2)[,2],
+ upp= matrix(unlist(S.est.upp), byrow=TRUE, ncol=2)[,2])
+ )
> write.csv(sim.rich, "figs_and_tables/sp_accum_2019_clump_samp_LS.csv", row.names=FALSE)
> ## Estimated species richness from Fisher's logseries
> a1 <- fishers.alpha(N=atdn.19$Tot.t, S = S1[1])
> ## Density per hectare
> d1 <- with(atdn.19, Tot.t/Tot.A)
> a1*log(1 + (2*atdn.19$N.plots*d1)/a1)
[1] 6305.51
> a1*log(1 + (max(S.proj.19$n.plots)*d1)/a1)
[1] 7598.334
> ## Richness with current, twice, 4x 8x and 10 times the current sample size
> ## A function to calculate the expected richness by linear interpolation from the simulated values
> f.m <- approxfun( x= sim.rich$n.plots, y =sim.rich$mean)