This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
sad-comparison-graphs.py
1285 lines (1149 loc) · 56.6 KB
/
sad-comparison-graphs.py
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
""" Project code for graphing the results of the comparisions for species abundance distribution (SAD) models """
from __future__ import division
import matplotlib.pyplot as plt
import numpy as np
import sqlite3 as dbapi
import pandas as pd
import sqlalchemy
# Set up database capabilities
# Set up ability to query data
con = dbapi.connect('./sad-data/chapter1/SummarizedResults.sqlite')
cur = con.cursor()
# Switch con data type to string
con.text_factory = str
'''Summarize the number of wins for each model/dataset'''
# Make histogram
# Set up figure
total_wins_fig= plt.figure()
# Extract number of wins for all datasets combined.
total_wins = cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
GROUP BY model_code""")
total_wins = cur.fetchall()
# Plot variables for total wins
N = len(total_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in total_wins ]
labels = [ s for (s, num) in total_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="grey" )
plt.ylabel( 'Number of Wins' )
plt.xticks(x + width/2.0, labels, fontsize = 'small' )
plt.xlabel( 'Species abundance distribution models' )
#Output figure
fileName = "./sad-data/chapter1/total_wins.png"
plt.savefig(fileName, format="png" )
plt.close()
''' Extract number of wins for each model and dataset'''
# BBS
bbs_wins = cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
WHERE dataset_code == 'bbs'
GROUP BY model_code""")
bbs_wins = cur.fetchall()
#CBC
cbc_wins = g= cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
WHERE dataset_code == 'cbc'
GROUP BY model_code""")
cbc_wins = cur.fetchall()
#FIA
fia_wins = cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
WHERE dataset_code == 'fia'
GROUP BY model_code""")
fia_wins = cur.fetchall()
#Gentry
gentry_wins = cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
WHERE dataset_code == 'gentry'
GROUP BY model_code""")
gentry_wins = cur.fetchall()
#MCDB
mcdb_wins = cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
WHERE dataset_code == 'mcdb'
GROUP BY model_code""")
mcdb_wins = cur.fetchall()
#NABA
naba_wins = cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
WHERE dataset_code == 'naba'
GROUP BY model_code""")
naba_wins = cur.fetchall()
#beetles
beetle_wins = cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
WHERE dataset_code == 'Coleoptera'
GROUP BY model_code""")
beetle_wins = cur.fetchall()
#spiders
spider_wins = cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
WHERE dataset_code == 'Arachnida'
GROUP BY model_code""")
spider_wins = cur.fetchall()
#amphibians
amphibian_wins = cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
WHERE dataset_code == 'Amphibia'
GROUP BY model_code""")
amphibian_wins = cur.fetchall()
#fish
fish_wins = cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
WHERE dataset_code == 'Actinopterygii'
GROUP BY model_code""")
fish_wins = cur.fetchall()
#reptiles
reptile_wins = cur.execute("""SELECT model_name, COUNT(model_code) AS total_wins FROM ResultsWin
WHERE dataset_code == 'Reptilia'
GROUP BY model_code""")
reptile_wins = cur.fetchall()
# Make histogram
# Set up figure
wins_by_dataset_fig = plt.figure()
# Plot variables for bbs subplot
plt.subplot(4,3,1)
N = len(bbs_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in bbs_wins ]
labels = [ s for (s, num) in bbs_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="red" )
plt.yticks(fontsize = 'x-small')
plt.ylabel( 'Wins', fontsize = 'small')
plt.xticks(x + width/2.0, labels, fontsize = 'x-small', rotation=15, horizontalalignment = 'right' )
plt.xlabel( 'BBS' )
# Plot variables for cbc subplot
plt.subplot(4,3,2)
N = len(cbc_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in cbc_wins ]
labels = [ s for (s, num) in cbc_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="tomato" )
plt.yticks(fontsize = 'x-small')
plt.ylabel( 'Wins', fontsize = 'small' )
plt.xticks(x + width/2.0, labels, fontsize = 'x-small', rotation=15 , horizontalalignment = 'right' )
plt.xlabel( 'CBC' )
# Plot variables for fia subplot
plt.subplot(4,3,3)
N = len(fia_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in fia_wins ]
labels = [ s for (s, num) in fia_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="green" )
plt.yticks(fontsize = 'x-small')
plt.ylabel( 'Wins', fontsize = 'small' )
plt.xticks(x + width/2.0, labels, fontsize = 'x-small', rotation=15, horizontalalignment = 'right' )
plt.xlabel( 'FIA' )
# Plot variables for Gentry subplot
plt.subplot(4,3,4)
N = len(gentry_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in gentry_wins ]
labels = [ s for (s, num) in gentry_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="olivedrab" )
plt.yticks(fontsize = 'x-small')
plt.ylabel( 'Wins', fontsize = 'small' )
plt.xticks(x + width/2.0, labels, fontsize = 'x-small', rotation=15, horizontalalignment = 'right' )
plt.xlabel( 'Gentry' )
# Plot variables for mcdb subplot
plt.subplot(4,3,5)
N = len(mcdb_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in mcdb_wins ]
labels = [ s for (s, num) in mcdb_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="sienna" )
plt.yticks(fontsize = 'x-small')
plt.ylabel( 'Wins', fontsize = 'small' )
plt.xticks(x + width/2.0, labels, fontsize = 'x-small', rotation=15, horizontalalignment = 'right' )
plt.xlabel( 'MCDB' )
# Plot variables for NABA subplot
plt.subplot(4,3,6)
N = len(naba_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in naba_wins ]
labels = [ s for (s, num) in naba_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="blue" )
plt.yticks(fontsize = 'x-small')
plt.ylabel( 'Wins', fontsize = 'small' )
plt.xticks(x + width/2.0, labels, fontsize = 'x-small', rotation=15, horizontalalignment = 'right' )
plt.xlabel( 'NABA' )
plt.tight_layout()
#beetle subplot
plt.subplot(4,3,7)
N = len(beetle_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in beetle_wins ]
labels = [ s for (s, num) in beetle_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="orange" )
plt.yticks(fontsize = 'x-small')
plt.ylabel( 'Wins', fontsize = 'small' )
plt.xticks(x + width/2.0, labels, fontsize = 'x-small', rotation=15, horizontalalignment = 'right' )
plt.xlabel( 'Coleoptera' )
plt.tight_layout()
# spider subplot
plt.subplot(4,3,8)
N = len(spider_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in spider_wins ]
labels = [ s for (s, num) in spider_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="magenta" )
plt.yticks(fontsize = 'x-small')
plt.ylabel( 'Wins', fontsize = 'small' )
plt.xticks(x + width/2.0, labels, fontsize = 'x-small', rotation=15, horizontalalignment = 'right' )
plt.xlabel( 'Arachnida' )
plt.tight_layout()
#amphibian subplot
plt.subplot(4,3,9)
N = len(amphibian_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in amphibian_wins ]
labels = [ s for (s, num) in amphibian_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="indigo" )
plt.yticks(fontsize = 'x-small')
plt.ylabel( 'Wins', fontsize = 'small' )
plt.xticks(x + width/2.0, labels, fontsize = 'x-small', rotation=15, horizontalalignment = 'right' )
plt.xlabel( 'Amphibians' )
plt.tight_layout()
# fish subplot
plt.subplot(4,3,10)
N = len(fish_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in fish_wins ]
labels = [ s for (s, num) in fish_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="teal" )
plt.yticks(fontsize = 'x-small')
plt.ylabel( 'Wins', fontsize = 'small' )
plt.xticks(x + width/2.0, labels, fontsize = 'x-small', rotation=15, horizontalalignment = 'right' )
plt.xlabel( 'Actinopterygii' )
plt.tight_layout()
# reptile subplot
plt.subplot(4,3,11)
N = len(reptile_wins)
x = np.arange(1, N+1)
y = [ num for (s, num) in reptile_wins ]
labels = [ s for (s, num) in reptile_wins ]
width = 1
bar1 = plt.bar( x, y, width, color="goldenrod" )
plt.yticks(fontsize = 'x-small')
plt.ylabel( 'Wins', fontsize = 'small' )
plt.xticks(x + width/2.0, labels, fontsize = 'x-small', rotation=15, horizontalalignment = 'right' )
plt.xlabel( 'Reptilia' )
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/wins_by_dataset.png"
plt.savefig(fileName, format="png" )
plt.close()
'''AIC_c weight distributions graphs'''
# Make histogram
# Set up figure
AIC_c_weights = plt.figure()
# Extract AICc weights for each model.
#Logseries
logseries = cur.execute("""SELECT model_name, value FROM RawResults
WHERE model_name == 'Logseries' AND value_type =='AICc weight' AND value IS NOT NULL
ORDER BY value""")
logseries = cur.fetchall()
#Poisson lognormal
pln = cur.execute("""SELECT model_name, value FROM RawResults
WHERE model_name =='Poisson lognormal' AND value_type =='AICc weight' AND value IS NOT NULL
ORDER BY value""")
pln = cur.fetchall()
#Negative binomial
neg_bin = cur.execute("""SELECT model_name, value FROM RawResults
WHERE model_name =='Negative binomial' AND value_type =='AICc weight' AND value IS NOT NULL
ORDER BY value""")
neg_bin = cur.fetchall()
#Geometric series
geometric = cur.execute("""SELECT model_name, value FROM RawResults
WHERE model_name =='Geometric series' AND value_type =='AICc weight' AND value IS NOT NULL
ORDER BY value""")
geometric = cur.fetchall()
#Zipf distribution
zipf = cur.execute("""SELECT model_name, value FROM RawResults
WHERE model_name =='Zipf distribution' AND value_type =='AICc weight' AND value IS NOT NULL
ORDER BY value""")
zipf = cur.fetchall()
# Plot variables for weights
bins = 50
#Logseries
model0 = [ num for (s, num) in logseries ]
plt.hist(model0, bins, range = (0,1), facecolor = 'magenta', histtype="stepfilled", alpha=1, label = "Logseries")
#Poisson lognormal
model1 = [ num for (s, num) in pln]
plt.hist(model1, bins, range = (0,1), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
#Negative binomial
model2 = [ num for (s, num) in neg_bin]
plt.hist(model2, bins, range = (0,1), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
#Geometric series
model3 = [ num for (s, num) in geometric]
plt.hist(model3, bins, range = (0,1), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
#Zipf distribution
model4 = [ num for (s, num) in zipf]
plt.hist(model4, bins, range = (0,1), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf")
plt.legend(loc = 'upper right', fontsize = 11)
plt.xlabel("AICc weights")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/AICc_weights.png"
plt.savefig(fileName, format="png" )
plt.close()
'''Plot weights for each model individually'''
bins = 50
#Logseries
plt.figure()
plt.hist(model0, bins, range = (0,1), facecolor = 'magenta', histtype="stepfilled", alpha=1, label = "Logseries")
plt.xlabel("Logseries AICc weights")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/Logseries_weights.png"
plt.savefig(fileName, format="png" )
plt.close()
#Poisson lognormal
plt.figure()
plt.hist(model1, bins, range = (0,1), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
plt.xlabel("Poisson lognormal AICc weights")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/Poisson_lognormal_weights.png"
plt.savefig(fileName, format="png" )
plt.close()
#Negative binomial
plt.figure()
model2 = [ num for (s, num) in neg_bin]
plt.hist(model2, bins, range = (0,1), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
plt.xlabel("Negative binomial AICc weights")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/Negative_binomial_weights.png"
plt.savefig(fileName, format="png" )
plt.close()
#Geometric series
plt.figure()
model3 = [ num for (s, num) in geometric]
plt.hist(model3, bins, range = (0,1), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
plt.xlabel("Geometric AICc weights")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/Geometric_weights.png"
plt.savefig(fileName, format="png" )
plt.close()
#Zipf distribution
plt.figure()
model4 = [ num for (s, num) in zipf]
plt.hist(model4, bins, range = (0,1), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf")
plt.xlabel("Zipf distribution AICc weights")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/Zipf_weights.png"
plt.savefig(fileName, format="png" )
plt.close()
'''Likelihoods graph'''
# Make histogram
# Set up figure
l_likelihood = plt.figure()
# Extract log-likelihoods for each model.
#Logseries
ll_logseries = cur.execute("""SELECT model_name, value FROM RawResults
WHERE model_name == 'Logseries' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
ll_logseries = cur.fetchall()
#Poisson lognormal
ll_pln = cur.execute("""SELECT model_name, value FROM RawResults
WHERE model_name =='Poisson lognormal' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
ll_pln = cur.fetchall()
#Negative binomial
ll_neg_bin = cur.execute("""SELECT model_name, value FROM RawResults
WHERE model_name =='Negative binomial' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
ll_neg_bin = cur.fetchall()
#Geometric series
ll_geometric = cur.execute("""SELECT model_name, value FROM RawResults
WHERE model_name =='Geometric series' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
ll_geometric = cur.fetchall()
#Zipf distribution
ll_zipf = cur.execute("""SELECT model_name, value FROM RawResults
WHERE model_name =='Zipf distribution' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
ll_zipf = cur.fetchall()
# Plot variables for combined likelihoods graph
#Zipf distribution
ll_model5 = [ num for (s, num) in ll_zipf]
plt.hist(ll_model5, bins = range(-750, 0, 10), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf distribution")
#Geometric series
ll_model4 = [ num for (s, num) in ll_geometric]
plt.hist(ll_model4, bins = range(-750, 0, 10), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
#Negative binomial
ll_model3 = [ num for (s, num) in ll_neg_bin]
plt.hist(ll_model3, bins = range(-750, 0, 10), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
#Poisson lognormal
ll_model2 = [ num for (s, num) in ll_pln]
plt.hist(ll_model2, bins = range(-750, 0, 10), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
#Logseries
ll_model0 = [ num for (s, num) in ll_logseries ]
plt.hist(ll_model0, bins = range(-750, 0, 10), facecolor = 'magenta', histtype="stepfilled", alpha=.4, label = "Logseries")
plt.legend(loc = 'upper left', fontsize = 11)
plt.xlabel("Log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
''' Plot likelihoods for each model individually'''
#Logseries
plt.figure()
plt.hist(ll_model0, bins = range(-750, 0, 10), facecolor = 'magenta', histtype="stepfilled", alpha=1, label = "Logseries")
plt.xlabel("Logseries log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/logseries_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
#Poisson lognormal
plt.figure()
plt.hist(ll_model2, bins = range(-750, 0, 10), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
plt.xlabel("Poisson lognormal log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/pln_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
#Negative binomial
plt.figure()
plt.hist(ll_model3, bins = range(-750, 0, 10), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
plt.xlabel("Negative binomial log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/neg_bin_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
#Geometric
plt.figure()
plt.hist(ll_model4, bins = range(-750, 0, 10), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
plt.xlabel("Geometric log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/geometric_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
#Zipf distribution
plt.figure()
plt.hist(ll_model5, bins = range(-750, 0, 10), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf distribution")
plt.xlabel("Zipf distribution log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/Zipf_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
'''Plot likelihoods by dataset and model'''
# BBS
#BBS logseries
bbs_ll_logser = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'bbs' AND model_name == 'Logseries' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
bbs_ll_logser = cur.fetchall()
#BBS Poisson lognormal
bbs_ll_pln = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'bbs' AND model_name == 'Poisson lognormal' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
bbs_ll_pln = cur.fetchall()
#BBS negative binomial
bbs_ll_neg_bin = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'bbs' AND model_name == 'Negative binomial' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
bbs_ll_neg_bin = cur.fetchall()
#BBS geometric
bbs_ll_geometric = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'bbs' AND model_name == 'Geometric series' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
bbs_ll_geometric = cur.fetchall()
#BBS Zipf
bbs_ll_zipf = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'bbs' AND model_name == 'Zipf distribution' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
bbs_ll_zipf = cur.fetchall()
# Plot variables for BBS combined likelihoods graph
plt.figure()
#Zipf distribution
bbs_ll_model5 = [ num for (s, num) in bbs_ll_zipf]
plt.hist(bbs_ll_model5, bins = range(-750, 0, 10), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf distribution")
#Geometric series
bbs_ll_model4 = [ num for (s, num) in bbs_ll_geometric]
plt.hist(bbs_ll_model4, bins = range(-750, 0, 10), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
#Negative binomial
bbs_ll_model3 = [ num for (s, num) in bbs_ll_neg_bin]
plt.hist(bbs_ll_model3, bins = range(-750, 0, 10), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
#Poisson lognormal
bbs_ll_model2 = [ num for (s, num) in bbs_ll_pln]
plt.hist(bbs_ll_model2, bins = range(-750, 0, 10), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
#Logseries
bbs_ll_model0 = [ num for (s, num) in bbs_ll_logser]
plt.hist(bbs_ll_model0, bins = range(-750, 0, 10), facecolor = 'magenta', histtype="stepfilled", alpha=.4, label = "Logseries")
plt.legend(loc = 'upper left', fontsize = 11)
plt.xlabel("BBS log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/bbs_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
# CBC
plt.figure()
#CBC Logseries
cbc_ll_logser = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'cbc' AND model_name == 'Logseries' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
cbc_ll_logser = cur.fetchall()
#CBC Poisson lognormal
cbc_ll_pln = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'cbc' AND model_name == 'Poisson lognormal' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
cbc_ll_pln = cur.fetchall()
#CBC negative binomial
cbc_ll_neg_bin = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'cbc' AND model_name == 'Negative binomial' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
cbc_ll_neg_bin = cur.fetchall()
#CBC geometric
cbc_ll_geometric = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'cbc' AND model_name == 'Geometric series' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
cbc_ll_geometric = cur.fetchall()
#CBC Zipf
cbc_ll_zipf = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'cbc' AND model_name == 'Zipf distribution' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
cbc_ll_zipf = cur.fetchall()
# Plot variables for CBC combined likelihoods graph
plt.figure()
#Zipf distribution
cbc_ll_model5 = [ num for (s, num) in cbc_ll_zipf]
plt.hist(cbc_ll_model5, bins = range(-750, 0, 10), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf distribution")
#Geometric series
cbc_ll_model4 = [ num for (s, num) in cbc_ll_geometric]
plt.hist(cbc_ll_model4, bins = range(-750, 0, 10), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
#Negative binomial
cbc_ll_model3 = [ num for (s, num) in cbc_ll_neg_bin]
plt.hist(cbc_ll_model3, bins = range(-750, 0, 10), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
#Poisson lognormal
cbc_ll_model2 = [ num for (s, num) in cbc_ll_pln]
plt.hist(cbc_ll_model2, bins = range(-750, 0, 10), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
#Logseries
cbc_ll_model0 = [ num for (s, num) in cbc_ll_logser]
plt.hist(cbc_ll_model0, bins = range(-750, 0, 10), facecolor = 'magenta', histtype="stepfilled", alpha=.4, label = "Logseries")
plt.legend(loc = 'upper left', fontsize = 11)
plt.xlabel("CBC log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/cbc_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
# FIA
#FIA logseries
fia_ll_logser = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'fia' AND model_name == 'Logseries' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
fia_ll_logser = cur.fetchall()
#FIA Poisson lognormal
fia_ll_pln = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'fia' AND model_name == 'Poisson lognormal' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
fia_ll_pln = cur.fetchall()
#FIA negative binomial
fia_ll_neg_bin = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'fia' AND model_name == 'Negative binomial' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
fia_ll_neg_bin = cur.fetchall()
#FIA geometric
fia_ll_geometric = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'fia' AND model_name == 'Geometric series' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
fia_ll_geometric = cur.fetchall()
#FIA Zipf
fia_ll_zipf = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'fia' AND model_name == 'Zipf distribution' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
fia_ll_zipf = cur.fetchall()
# Plot variables for FIA combined likelihoods graph
plt.figure()
#Zipf distribution
fia_ll_model5 = [ num for (s, num) in fia_ll_zipf]
plt.hist(fia_ll_model5, bins = range(-750, 0, 10), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf distribution")
#Geometric series
fia_ll_model4 = [ num for (s, num) in fia_ll_geometric]
plt.hist(fia_ll_model4, bins = range(-750, 0, 10), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
#Negative binomial
fia_ll_model3 = [ num for (s, num) in fia_ll_neg_bin]
plt.hist(fia_ll_model3, bins = range(-750, 0, 10), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
#Poisson lognormal
fia_ll_model2 = [ num for (s, num) in fia_ll_pln]
plt.hist(fia_ll_model2, bins = range(-750, 0, 10), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
#Logseries
fia_ll_model0 = [ num for (s, num) in fia_ll_logser]
plt.hist(fia_ll_model0, bins = range(-750, 0, 10), facecolor = 'magenta', histtype="stepfilled", alpha=.4, label = "Logseries")
plt.legend(loc = 'upper left', fontsize = 11)
plt.xlabel("FIA log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/fia_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
# Gentry
#Gentry logseries
gentry_ll_logser = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'gentry' AND model_name == 'Logseries' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
gentry_ll_logser = cur.fetchall()
#Gentry Poisson lognormal
gentry_ll_pln = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'gentry' AND model_name == 'Poisson lognormal' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
gentry_ll_pln = cur.fetchall()
#CBC negative binomial
gentry_ll_neg_bin = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'gentry' AND model_name == 'Negative binomial' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
gentry_ll_neg_bin = cur.fetchall()
#Gentry geometric
gentry_ll_geometric = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'gentry' AND model_name == 'Geometric series' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
gentry_ll_geometric = cur.fetchall()
#Gentry Zipf
gentry_ll_zipf = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'gentry' AND model_name == 'Zipf distribution' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
gentry_ll_zipf = cur.fetchall()
# Plot variables for Gentry combined likelihoods graph
plt.figure()
#Zipf distribution
gentry_ll_model5 = [ num for (s, num) in gentry_ll_zipf]
plt.hist(gentry_ll_model5, bins = range(-750, 0, 10), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf distribution")
#Geometric series
gentry_ll_model4 = [ num for (s, num) in gentry_ll_geometric]
plt.hist(gentry_ll_model4, bins = range(-750, 0, 10), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
#Negative binomial
gentry_ll_model3 = [ num for (s, num) in gentry_ll_neg_bin]
plt.hist(gentry_ll_model3, bins = range(-750, 0, 10), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
#Poisson lognormal
gentry_ll_model2 = [ num for (s, num) in gentry_ll_pln]
plt.hist(gentry_ll_model2, bins = range(-750, 0, 10), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
#Logseries
gentry_ll_model0 = [ num for (s, num) in gentry_ll_logser]
plt.hist(gentry_ll_model0, bins = range(-750, 0, 10), facecolor = 'magenta', histtype="stepfilled", alpha=.4, label = "Logseries")
plt.legend(loc = 'upper left', fontsize = 11)
plt.xlabel("Gentry log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/gentry_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
# MCDB
#MCDB logseries
mcdb_ll_logser = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'mcdb' AND model_name == 'Logseries' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
mcdb_ll_logser = cur.fetchall()
#MCDB Poisson lognormal
mcdb_ll_pln = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'mcdb' AND model_name == 'Poisson lognormal' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
mcdb_ll_pln = cur.fetchall()
#MCDB negative binomial
mcdb_ll_neg_bin = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'mcdb' AND model_name == 'Negative binomial' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
mcdb_ll_neg_bin = cur.fetchall()
#MCDB geometric
mcdb_ll_geometric = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'mcdb' AND model_name == 'Geometric series' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
mcdb_ll_geometric = cur.fetchall()
#Gentry Zipf
mcdb_ll_zipf = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'mcdb' AND model_name == 'Zipf distribution' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
mcdb_ll_zipf = cur.fetchall()
# Plot variables for MCDB combined likelihoods graph
plt.figure()
#Zipf distribution
mcdb_ll_model5 = [ num for (s, num) in mcdb_ll_zipf]
plt.hist(mcdb_ll_model5, bins = range(-750, 0, 10), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf distribution")
#Geometric series
mcdb_ll_model4 = [ num for (s, num) in mcdb_ll_geometric]
plt.hist(mcdb_ll_model4, bins = range(-750, 0, 10), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
#Negative binomial
mcdb_ll_model3 = [ num for (s, num) in mcdb_ll_neg_bin]
plt.hist(mcdb_ll_model3, bins = range(-750, 0, 10), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
#Poisson lognormal
mcdb_ll_model2 = [ num for (s, num) in mcdb_ll_pln]
plt.hist(mcdb_ll_model2, bins = range(-750, 0, 10), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
#Logseries
mcdb_ll_model0 = [ num for (s, num) in mcdb_ll_logser]
plt.hist(mcdb_ll_model0, bins = range(-750, 0, 10), facecolor = 'magenta', histtype="stepfilled", alpha=.4, label = "Logseries")
plt.legend(loc = 'upper left', fontsize = 11)
plt.xlabel("MCDB log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/mcdb_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
# NABA
#NABA logseries
naba_ll_logser = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'naba' AND model_name == 'Logseries' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
naba_ll_logser = cur.fetchall()
#NABA Poisson lognormal
naba_ll_pln = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'naba' AND model_name == 'Poisson lognormal' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
naba_ll_pln = cur.fetchall()
#NABA negative binomial
naba_ll_neg_bin = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'naba' AND model_name == 'Negative binomial' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
naba_ll_neg_bin = cur.fetchall()
#NABA geometric
naba_ll_geometric = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'naba'AND model_name == 'Geometric series' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
naba_ll_geometric = cur.fetchall()
#NABA Zipf
naba_ll_zipf = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'naba' AND model_name == 'Zipf distribution' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
naba_ll_zipf = cur.fetchall()
# Plot variables for NABA combined likelihoods graph
plt.figure()
#Zipf distribution
naba_ll_model5 = [ num for (s, num) in naba_ll_zipf]
plt.hist(naba_ll_model5, bins = range(-750, 0, 10), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf distribution")
#Geometric series
naba_ll_model4 = [ num for (s, num) in naba_ll_geometric]
plt.hist(naba_ll_model4, bins = range(-750, 0, 10), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
#Negative binomial
naba_ll_model3 = [ num for (s, num) in naba_ll_neg_bin]
plt.hist(naba_ll_model3, bins = range(-750, 0, 10), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
#Poisson lognormal
naba_ll_model2 = [ num for (s, num) in naba_ll_pln]
plt.hist(naba_ll_model2, bins = range(-750, 0, 10), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
#Logseries
naba_ll_model0 = [ num for (s, num) in naba_ll_logser]
plt.hist(naba_ll_model0, bins = range(-750, 0, 10), facecolor = 'magenta', histtype="stepfilled", alpha=.4, label = "Logseries")
plt.legend(loc = 'upper left', fontsize = 11)
plt.xlabel("NABA log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/naba_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
# beetles
#beetle logseries
beetle_ll_logser = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Coleoptera' AND model_name == 'Logseries' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
beetle_ll_logser = cur.fetchall()
#beetle Poisson lognormal
beetle_ll_pln = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Coleoptera' AND model_name == 'Poisson lognormal' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
beetle_ll_pln = cur.fetchall()
#beetle negative binomial
beetle_ll_neg_bin = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Coleoptera' AND model_name == 'Negative binomial' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
beetle_ll_neg_bin = cur.fetchall()
#beetle geometric
beetle_ll_geometric = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Coleoptera'AND model_name == 'Geometric series' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
beetle_ll_geometric = cur.fetchall()
#beetle Zipf
beetle_ll_zipf = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Coleoptera' AND model_name == 'Zipf distribution' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
beetle_ll_zipf = cur.fetchall()
# Plot variables for beetle combined likelihoods graph
plt.figure()
#Zipf distribution
beetle_ll_model5 = [ num for (s, num) in beetle_ll_zipf]
plt.hist(beetle_ll_model5, bins = range(-750, 0, 10), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf distribution")
#Geometric series
beetle_ll_model4 = [ num for (s, num) in beetle_ll_geometric]
plt.hist(beetle_ll_model4, bins = range(-750, 0, 10), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
#Negative binomial
beetle_ll_model3 = [ num for (s, num) in beetle_ll_neg_bin]
plt.hist(beetle_ll_model3, bins = range(-750, 0, 10), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
#Poisson lognormal
beetle_ll_model2 = [ num for (s, num) in beetle_ll_pln]
plt.hist(beetle_ll_model2, bins = range(-750, 0, 10), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
#Logseries
beetle_ll_model0 = [ num for (s, num) in beetle_ll_logser]
plt.hist(beetle_ll_model0, bins = range(-750, 0, 10), facecolor = 'magenta', histtype="stepfilled", alpha=.4, label = "Logseries")
plt.legend(loc = 'upper left', fontsize = 11)
plt.xlabel("Coleoptera log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/beetle_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
# spiders
#spiders logseries
spiders_ll_logser = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Arachnida' AND model_name == 'Logseries' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
spiders_ll_logser = cur.fetchall()
#spiders Poisson lognormal
spiders_ll_pln = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Arachnida' AND model_name == 'Poisson lognormal' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
spiders_ll_pln = cur.fetchall()
#spiders negative binomial
spiders_ll_neg_bin = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Arachnida' AND model_name == 'Negative binomial' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
spiders_ll_neg_bin = cur.fetchall()
#spiders geometric
spiders_ll_geometric = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Arachnida'AND model_name == 'Geometric series' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
spiders_ll_geometric = cur.fetchall()
#spiders Zipf
spiders_ll_zipf = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Arachnida' AND model_name == 'Zipf distribution' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
spiders_ll_zipf = cur.fetchall()
# Plot variables for spiders combined likelihoods graph
plt.figure()
#Zipf distribution
spiders_ll_model5 = [ num for (s, num) in spiders_ll_zipf]
plt.hist(spiders_ll_model5, bins = range(-750, 0, 10), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf distribution")
#Geometric series
spiders_ll_model4 = [ num for (s, num) in spiders_ll_geometric]
plt.hist(spiders_ll_model4, bins = range(-750, 0, 10), facecolor = 'olivedrab', histtype="stepfilled", alpha=.7, label = "Geometric")
#Negative binomial
spiders_ll_model3 = [ num for (s, num) in spiders_ll_neg_bin]
plt.hist(spiders_ll_model3, bins = range(-750, 0, 10), facecolor = 'gray', histtype="stepfilled", alpha=.7, label = "Negative binomial")
#Poisson lognormal
spiders_ll_model2 = [ num for (s, num) in spiders_ll_pln]
plt.hist(spiders_ll_model2, bins = range(-750, 0, 10), facecolor = 'teal', histtype="stepfilled", alpha=.7, label = "Poisson lognormal")
#Logseries
spiders_ll_model0 = [ num for (s, num) in spiders_ll_logser]
plt.hist(spiders_ll_model0, bins = range(-750, 0, 10), facecolor = 'magenta', histtype="stepfilled", alpha=.4, label = "Logseries")
plt.legend(loc = 'upper left', fontsize = 11)
plt.xlabel("Arachnida log-likelihoods")
plt.ylabel("Frequency")
plt.tight_layout()
#Output figure
fileName = "./sad-data/chapter1/spider_likelihoods.png"
plt.savefig(fileName, format="png" )
plt.close()
# amphibians
#amphibians logseries
amphibians_ll_logser = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Amphibia' AND model_name == 'Logseries' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
amphibians_ll_logser = cur.fetchall()
#amphibians Poisson lognormal
amphibians_ll_pln = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Amphibia' AND model_name == 'Poisson lognormal' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
amphibians_ll_pln = cur.fetchall()
#amphibians negative binomial
amphibians_ll_neg_bin = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Amphibia' AND model_name == 'Negative binomial' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
amphibians_ll_neg_bin = cur.fetchall()
#amphibians geometric
amphibians_ll_geometric = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Amphibia'AND model_name == 'Geometric series' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
amphibians_ll_geometric = cur.fetchall()
#amphibians Zipf
amphibians_ll_zipf = cur.execute("""SELECT model_name, value FROM RawResults
WHERE dataset_code == 'Amphibia' AND model_name == 'Zipf distribution' AND value_type =='likelihood' AND value IS NOT NUll
ORDER BY value""")
amphibians_ll_zipf = cur.fetchall()
# Plot variables for amphibians combined likelihoods graph
plt.figure()
#Zipf distribution
amphibians_ll_model5 = [ num for (s, num) in amphibians_ll_zipf]
plt.hist(amphibians_ll_model5, bins = range(-750, 0, 10), facecolor = 'orange', histtype="stepfilled", alpha=.7, label = "Zipf distribution")