-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleaned selective deaths analysis.R
2960 lines (2501 loc) · 183 KB
/
cleaned selective deaths analysis.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
library('ggplot2')
library('ggpubr')
library('egg')
library('MASS')
library('scales')
install.packages("scales")
install.packages("ggpubr")
getwd()
setwd('..')
options(scipen = 10000)
#FUNCTIONS
#This function is taken from the internet, it may not be modular.
#Source: https://groups.google.com/g/ggplot2/c/a_xhMoQyxZ4
fancy_scientific <- function(l) {
# turn in to character string in scientific notation
l <- format(l, scientific = TRUE)
# quote the part before the exponent to keep all the digits
l <- gsub("^(.*)e", "'\\1'e", l)
# remove + after exponent, if exists. E.g.: (3x10^+2 -> 3x10^2)
l <- gsub("e\\+","e",l)
# turn the 'e+' into plotmath format
l <- gsub("e", "%*%10^", l)
# convert 1x10^ or 1.000x10^ -> 10^
l <- gsub("\\'1[\\.0]*\\'\\%\\*\\%", "", l)
# return this as an expression
parse(text=l)
}
#This function requires a dataset that is NOT aggregated
#and has replicates with no surviving seeds OMITTED
CalculateVarianceStDevandMeaninSeedProduction <- function(nozeroesdata) {
nozeroesdata$Variance <- ave(nozeroesdata$Seeds_by_ind, nozeroesdata$Genotype_id, FUN = var)
nozeroesdata$StDev <- sqrt(nozeroesdata$Variance)
nozeroesdata$Mean <- ave(nozeroesdata$Seeds_by_ind, nozeroesdata$Genotype_id, FUN = mean)
nozeroesdata[is.na(nozeroesdata)] = 0.0
return(nozeroesdata)
}
#I need to add some new columns to the dataset for the main calculation loop.
#I'm also going to set the Replicates column in this function to INCLUDE pots with no surviving seeds.
AddColumns <- function(environmentalconditiondataframe, nreplicatestable) {
environmentalconditiondataframe$Replicates <- c(1:nrow(environmentalconditiondataframe))
environmentalconditiondataframe$Selective_deaths_survival <- c(1:nrow(environmentalconditiondataframe))
environmentalconditiondataframe$Selective_deaths_births <- c(1:nrow(environmentalconditiondataframe))
environmentalconditiondataframe$Genotype_death_rate <- c(1:nrow(environmentalconditiondataframe))
environmentalconditiondataframe$Seeds_for_next_generation <- c(1:nrow(environmentalconditiondataframe))
for (i in 1:nrow(environmentalconditiondataframe)) {
environmentalconditiondataframe$Replicates[i] <- nreplicatestable[i]
}
return(environmentalconditiondataframe)
}
Boxcoxtransform <- function(environmentalconditiondataframe, lambda) {
environmentalconditiondataframe$boxcox_transform_fecundity <- c(1:nrow(environmentalconditiondataframe))
for (i in 1:nrow(environmentalconditiondataframe)) {
environmentalconditiondataframe$boxcox_transform_fecundity[i] <- (environmentalconditiondataframe$Seeds_by_ind[i]^lambda - 1) / lambda
}
return(environmentalconditiondataframe)
}
#This function should take in an aggregated dataset where replicates with
#no surviving seeds are INCLUDED
CalculateSelectiveDeathsSurvival <- function(environmentalconditiondataframe, nreplicatestable, isPopulation) {
for (i in 1:nrow(environmentalconditiondataframe)) {
environmentalconditiondataframe$Surviving_individuals_pot[i] <- (environmentalconditiondataframe$Surviving_individuals_pot[i] * environmentalconditiondataframe$Replicates[i])
if (isPopulation == 1) {
environmentalconditiondataframe$Genotype_death_rate[i] <- (30*environmentalconditiondataframe$Replicates[i] - environmentalconditiondataframe$Surviving_individuals_pot[i]) / (30*environmentalconditiondataframe$Replicates[i])
} else {
environmentalconditiondataframe$Genotype_death_rate[i] <- (environmentalconditiondataframe$Replicates[i] - environmentalconditiondataframe$Surviving_individuals_pot[i]) / (environmentalconditiondataframe$Replicates[i])
}
}
min_death_rate <- min(environmentalconditiondataframe$Genotype_death_rate)
for (i in 1:nrow(environmentalconditiondataframe)) {
if (isPopulation == 1) {
environmentalconditiondataframe$Selective_deaths_survival[i] <- (30*environmentalconditiondataframe$Replicates[i]) * (environmentalconditiondataframe$Genotype_death_rate[i] - min_death_rate)
} else {
environmentalconditiondataframe$Selective_deaths_survival[i] <- (environmentalconditiondataframe$Replicates[i]) * (environmentalconditiondataframe$Genotype_death_rate[i] - min_death_rate)
}
}
colnames(environmentalconditiondataframe)[colnames(environmentalconditiondataframe) == "Surviving_individuals_pot"] <- "Total_surviving_seeds"
return(environmentalconditiondataframe)
}
CalculateSelectiveDeathsSurvivalWithBias <- function(environmentalconditiondataframe, nreplicatestable, meanbias, isPopulation) {
for (i in 1:nrow(environmentalconditiondataframe)) {
environmentalconditiondataframe$Surviving_individuals_pot[i] <- (environmentalconditiondataframe$Surviving_individuals_pot[i] * environmentalconditiondataframe$Replicates[i])
if (isPopulation == 1) {
environmentalconditiondataframe$Genotype_death_rate[i] <- (30*environmentalconditiondataframe$Replicates[i] - environmentalconditiondataframe$Surviving_individuals_pot[i]) / (30*environmentalconditiondataframe$Replicates[i])
} else {
environmentalconditiondataframe$Genotype_death_rate[i] <- (environmentalconditiondataframe$Replicates[i] - environmentalconditiondataframe$Surviving_individuals_pot[i]) / (environmentalconditiondataframe$Replicates[i])
}
}
min_death_rate <- min(environmentalconditiondataframe$Genotype_death_rate)
for (i in 1:nrow(environmentalconditiondataframe)) {
if (isPopulation == 1) {
environmentalconditiondataframe$Selective_deaths_survival[i] <- (30*environmentalconditiondataframe$Replicates[i]) * (environmentalconditiondataframe$Genotype_death_rate[i] - (min_death_rate + meanbias))
} else {
environmentalconditiondataframe$Selective_deaths_survival[i] <- (environmentalconditiondataframe$Replicates[i]) * (environmentalconditiondataframe$Genotype_death_rate[i] - (min_death_rate + meanbias))
}
if (environmentalconditiondataframe$Selective_deaths_survival[i] < 0.0) {
environmentalconditiondataframe$Selective_deaths_survival[i] <- 0.0
}
}
colnames(environmentalconditiondataframe)[colnames(environmentalconditiondataframe) == "Surviving_individuals_pot"] <- "Total_surviving_seeds"
return(environmentalconditiondataframe)
}
#This function should take in an aggregated dataset where replicates with
#no surviving seeds are OMITTED (MUST HAVE BEEN OMITTED FIRST THEN AGGREGATED)
#It also needs a replicates table that has OMITTED replicates with no surviving seeds.
#Note that the $Replicates column INCLUDES these replicates.
CalculateSelectiveDeathsBirths <- function(environmentalconditiondataframe, nreplicatestablewithoutpotswithnosurvivingseeds, isPopulation) {
for (i in 1:nrow(environmentalconditiondataframe)) {
environmentalconditiondataframe$Surviving_individuals_pot[i] <- (environmentalconditiondataframe$Surviving_individuals_pot[i] * nreplicatestablewithoutpotswithnosurvivingseeds[i])
environmentalconditiondataframe$Seeds_total_pot[i] <- (environmentalconditiondataframe$Seeds_total_pot[i] * nreplicatestablewithoutpotswithnosurvivingseeds[i])
if (environmentalconditiondataframe$Surviving_individuals_pot[i] > 0.0) {
environmentalconditiondataframe$Seeds_by_ind[i] <- environmentalconditiondataframe$Seeds_total_pot[i] / environmentalconditiondataframe$Surviving_individuals_pot[i]
} else {
environmentalconditiondataframe$Seeds_by_ind[i] <- 0.0
}
if (isPopulation == 1) {
if (environmentalconditiondataframe$Seeds_total_pot[i] > 30.0*environmentalconditiondataframe$Replicates[i]) {
environmentalconditiondataframe$Seeds_for_next_generation[i] <- 30.0*environmentalconditiondataframe$Replicates[i]
} else {
environmentalconditiondataframe$Seeds_for_next_generation[i] <- environmentalconditiondataframe$Seeds_total_pot[i]
}
} else {
if (environmentalconditiondataframe$Seeds_total_pot[i] > 10.0*environmentalconditiondataframe$Replicates[i]) {
environmentalconditiondataframe$Seeds_for_next_generation[i] <- 10.0*environmentalconditiondataframe$Replicates[i]
} else {
environmentalconditiondataframe$Seeds_for_next_generation[i] <- environmentalconditiondataframe$Seeds_total_pot[i]
}
}
}
max_birth_rate <- max(environmentalconditiondataframe$Seeds_by_ind)
for (i in 1:nrow(environmentalconditiondataframe)) {
environmentalconditiondataframe$Selective_deaths_births[i] <- (max_birth_rate - environmentalconditiondataframe$Seeds_by_ind[i]) * environmentalconditiondataframe$Surviving_individuals_pot[i]
}
return(environmentalconditiondataframe)
}
CalculateSelectiveDeathsBirthsWithBias <- function(environmentalconditiondataframe, nreplicatestablewithoutpotswithnosurvivingseeds, meanbias, isPopulation) {
for (i in 1:nrow(environmentalconditiondataframe)) {
environmentalconditiondataframe$Surviving_individuals_pot[i] <- (environmentalconditiondataframe$Surviving_individuals_pot[i] * nreplicatestablewithoutpotswithnosurvivingseeds[i])
environmentalconditiondataframe$Seeds_total_pot[i] <- (environmentalconditiondataframe$Seeds_total_pot[i] * nreplicatestablewithoutpotswithnosurvivingseeds[i])
if (environmentalconditiondataframe$Surviving_individuals_pot[i] > 0.0) {
environmentalconditiondataframe$Seeds_by_ind[i] <- environmentalconditiondataframe$Seeds_total_pot[i] / environmentalconditiondataframe$Surviving_individuals_pot[i]
} else {
environmentalconditiondataframe$Seeds_by_ind[i] <- 0.0
}
if (isPopulation == 1) {
if (environmentalconditiondataframe$Seeds_total_pot[i] > 30.0*environmentalconditiondataframe$Replicates[i]) {
environmentalconditiondataframe$Seeds_for_next_generation[i] <- 30.0*environmentalconditiondataframe$Replicates[i]
} else {
environmentalconditiondataframe$Seeds_for_next_generation[i] <- environmentalconditiondataframe$Seeds_total_pot[i]
}
} else {
if (environmentalconditiondataframe$Seeds_total_pot[i] > 10.0*environmentalconditiondataframe$Replicates[i]) {
environmentalconditiondataframe$Seeds_for_next_generation[i] <- 10.0*environmentalconditiondataframe$Replicates[i]
} else {
environmentalconditiondataframe$Seeds_for_next_generation[i] <- environmentalconditiondataframe$Seeds_total_pot[i]
}
}
}
max_birth_rate <- max(environmentalconditiondataframe$Seeds_by_ind)
for (i in 1:nrow(environmentalconditiondataframe)) {
environmentalconditiondataframe$Selective_deaths_births[i] <- ((max_birth_rate - meanbias) - environmentalconditiondataframe$Seeds_by_ind[i]) * environmentalconditiondataframe$Surviving_individuals_pot[i]
if (environmentalconditiondataframe$Selective_deaths_births[i] < 0.0) {
environmentalconditiondataframe$Selective_deaths_births[i] <- 0.0
}
}
return(environmentalconditiondataframe)
}
ExtremeValueBiasSurvival <- function(environmentalconditiondataframe, isPopulation) {
simulationdataframe <- data.frame(
genotypesurvivalrates = environmentalconditiondataframe$Genotype_death_rate,
genotypeID = environmentalconditiondataframe$Genotype_id,
resampledgenotypesurvivalrates = environmentalconditiondataframe$Genotype_death_rate
)
resultsdataframe <- data.frame(
vectorofmaximumsurvivalrates = c(1.0:10000.0),
vectoroftruesurvivalrates = c(1.0:10000.0),
vectorofwithingenotypevariances = c(1.0:10000.0),
vectorofbestgenotypeID = c(1.0:10000.0)
)
for (i in 1:10000) {
for(j in 1:nrow(environmentalconditiondataframe)) {
simulationdataframe$genotypesurvivalrates[j] <- (1.0 - environmentalconditiondataframe$Genotype_death_rate[j])
}
if(isPopulation == 0) {
for(j in 1:nrow(environmentalconditiondataframe)) {
simulationdataframe$resampledgenotypesurvivalrates[j] <- (rbinom(1, (environmentalconditiondataframe$Replicates[j]), simulationdataframe$genotypesurvivalrates[j]) / (environmentalconditiondataframe$Replicates[j]))
}
} else {
for(j in 1:nrow(environmentalconditiondataframe)) {
simulationdataframe$resampledgenotypesurvivalrates[j] <- (rbinom(1, (environmentalconditiondataframe$Replicates[j])*30, simulationdataframe$genotypesurvivalrates[j]) / (environmentalconditiondataframe$Replicates[j] * 30))
}
}
resultsdataframe$vectorofmaximumsurvivalrates[i] <- max(simulationdataframe$resampledgenotypesurvivalrates)
resultsdataframe$vectoroftruesurvivalrates[i] <- max(simulationdataframe$genotypesurvivalrates)
resultsdataframe$vectorofbestgenotypeID[i] <- simulationdataframe$genotypeID[which.max(simulationdataframe$genotypesurvivalrates)]
if (isPopulation == 0) {
resultsdataframe$vectorofwithingenotypevariances[i] <- resultsdataframe$vectoroftruesurvivalrates[i]*(1 - resultsdataframe$vectoroftruesurvivalrates[i]) / (environmentalconditiondataframe$Replicates[which(environmentalconditiondataframe$Genotype_id == resultsdataframe$vectorofbestgenotypeID[i], arr.ind = FALSE)])
} else {
resultsdataframe$vectorofwithingenotypevariances[i] <- resultsdataframe$vectoroftruesurvivalrates[i]*(1 - resultsdataframe$vectoroftruesurvivalrates[i]) / (environmentalconditiondataframe$Replicates[which(environmentalconditiondataframe$Genotype_id == resultsdataframe$vectorofbestgenotypeID[i], arr.ind = FALSE)]*30)
}
}
biasvector <- c(1:10000)
for (i in 1:10000) {
biasvector[i] = (resultsdataframe$vectorofmaximumsurvivalrates[i] - resultsdataframe$vectoroftruesurvivalrates[i])
}
meanbias <- mean(biasvector)
return(meanbias)
}
#DATASET IMPORT AND ORGANIZING
#imports full dataset
fullselectivedeathsdata = read.table("Selective deaths/Dataset_Arabidopsis_Exposito-Alonso.txt", header = TRUE)
#sets NA values to zero
#since all NA values are in seed number data entries, they always mean zero seeds found
fullselectivedeathsdata[is.na(fullselectivedeathsdata)] = 0
#there might be a more elegant way to subsection the eight treatment types,
#but since it's a 2x2x2 design with eight combinations of three different variables,
#subsectioning for each variable is the first way I came up with
#subsectioning by seed density treatment (1 seed per pot vs. 20 seeds per pot)
oneseedselectivedeathsdata <- subset(fullselectivedeathsdata, Density_treatment == 'i', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
twentyseedsselectivedeathsdata <- subset(fullselectivedeathsdata, Density_treatment == 'p', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
#subsectioning seed density datasets by watering treatment (low vs. high)
lowwateroneseedselectivedeathsdata <- subset(oneseedselectivedeathsdata, Watering_treatment == 'l', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
highwateroneseedselectivedeathsdata <- subset(oneseedselectivedeathsdata, Watering_treatment == 'h', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
lowwatertwentyseedsselectivedeathsdata <- subset(twentyseedsselectivedeathsdata, Watering_treatment == 'l', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
highwatertwentyseedsselectivedeathsdata <- subset(twentyseedsselectivedeathsdata, Watering_treatment == 'h', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
#subsectioning waterxdensity datasets by climate (madrid vs. tuebingen)
madridlowwateroneseedselectivedeathsdata <- subset(lowwateroneseedselectivedeathsdata, Field_site == 'madrid', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
madridhighwateroneseedselectivedeathsdata <- subset(highwateroneseedselectivedeathsdata, Field_site == 'madrid', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
madridlowwatertwentyseedsselectivedeathsdata <- subset(lowwatertwentyseedsselectivedeathsdata, Field_site == 'madrid', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
madridhighwatertwentyseedsselectivedeathsdata <- subset(highwatertwentyseedsselectivedeathsdata, Field_site == 'madrid', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
tuebingenlowwateroneseedselectivedeathsdata <- subset(lowwateroneseedselectivedeathsdata, Field_site == 'tuebingen', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
tuebingenhighwateroneseedselectivedeathsdata <- subset(highwateroneseedselectivedeathsdata, Field_site == 'tuebingen', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
tuebingenlowwatertwentyseedsselectivedeathsdata <- subset(lowwatertwentyseedsselectivedeathsdata, Field_site == 'tuebingen', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
tuebingenhighwatertwentyseedsselectivedeathsdata <- subset(highwatertwentyseedsselectivedeathsdata, Field_site == 'tuebingen', select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
#I need to calculate variance in seed production per individual for each genotype
#for the purpose of correcting for extreme value bias later.
#This means I need to drop all replicates with no surviving individuals.
onlypotswithsurvivingseedsMLO <- subset(madridlowwateroneseedselectivedeathsdata, Surviving_individuals_pot > 0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
onlypotswithsurvivingseedsMLP <- subset(madridlowwatertwentyseedsselectivedeathsdata, Surviving_individuals_pot > 0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
onlypotswithsurvivingseedsMHO <- subset(madridhighwateroneseedselectivedeathsdata, Surviving_individuals_pot > 0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
onlypotswithsurvivingseedsMHP <- subset(madridhighwatertwentyseedsselectivedeathsdata, Surviving_individuals_pot > 0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
onlypotswithsurvivingseedsTLO <- subset(tuebingenlowwateroneseedselectivedeathsdata, Surviving_individuals_pot > 0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
onlypotswithsurvivingseedsTLP <- subset(tuebingenlowwatertwentyseedsselectivedeathsdata, Surviving_individuals_pot > 0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
onlypotswithsurvivingseedsTHO <- subset(tuebingenhighwateroneseedselectivedeathsdata, Surviving_individuals_pot > 0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
onlypotswithsurvivingseedsTHP <- subset(tuebingenhighwatertwentyseedsselectivedeathsdata, Surviving_individuals_pot > 0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind"))
#Note that the datasets above have replicates for each genotype.
#In order to calculate selective deaths, need to know the optimal genotype at each LH stage
#This requires aggregating data from replicates of each genotype
#INCLUDES POTS WITH NO SURVIVING SEEDS IN SURVIVAL AND BIRTHS
aggregatedpotswithnosurvivingseedsMLO <- aggregate(madridlowwateroneseedselectivedeathsdata, by = list(madridlowwateroneseedselectivedeathsdata$Genotype_id), FUN = mean)
aggregatedpotswithnosurvivingseedsMLP <- aggregate(madridlowwatertwentyseedsselectivedeathsdata, by = list(madridlowwatertwentyseedsselectivedeathsdata$Genotype_id), FUN = mean)
aggregatedpotswithnosurvivingseedsMHO <- aggregate(madridhighwateroneseedselectivedeathsdata, by = list(madridhighwateroneseedselectivedeathsdata$Genotype_id), FUN = mean)
aggregatedpotswithnosurvivingseedsMHP <- aggregate(madridhighwatertwentyseedsselectivedeathsdata, by = list(madridhighwatertwentyseedsselectivedeathsdata$Genotype_id), FUN = mean)
aggregatedpotswithnosurvivingseedsTLO <- aggregate(tuebingenlowwateroneseedselectivedeathsdata, by = list(tuebingenlowwateroneseedselectivedeathsdata$Genotype_id), FUN = mean)
aggregatedpotswithnosurvivingseedsTLP <- aggregate(tuebingenlowwatertwentyseedsselectivedeathsdata, by = list(tuebingenlowwatertwentyseedsselectivedeathsdata$Genotype_id), FUN = mean)
aggregatedpotswithnosurvivingseedsTHO <- aggregate(tuebingenhighwateroneseedselectivedeathsdata, by = list(tuebingenhighwateroneseedselectivedeathsdata$Genotype_id), FUN = mean)
aggregatedpotswithnosurvivingseedsTHP <- aggregate(tuebingenhighwatertwentyseedsselectivedeathsdata, by = list(tuebingenhighwatertwentyseedsselectivedeathsdata$Genotype_id), FUN = mean)
#Same aggregation procedure for data where replicates with no surviving seeds
#are OMITTED.
aggregatedonlypotswithsurvivingseedsMLO <- aggregate(onlypotswithsurvivingseedsMLO, by = list(onlypotswithsurvivingseedsMLO$Genotype_id), FUN = mean)
aggregatedonlypotswithsurvivingseedsMLP <- aggregate(onlypotswithsurvivingseedsMLP, by = list(onlypotswithsurvivingseedsMLP$Genotype_id), FUN = mean)
aggregatedonlypotswithsurvivingseedsMHO <- aggregate(onlypotswithsurvivingseedsMHO, by = list(onlypotswithsurvivingseedsMHO$Genotype_id), FUN = mean)
aggregatedonlypotswithsurvivingseedsMHP <- aggregate(onlypotswithsurvivingseedsMHP, by = list(onlypotswithsurvivingseedsMHP$Genotype_id), FUN = mean)
aggregatedonlypotswithsurvivingseedsTLO <- aggregate(onlypotswithsurvivingseedsTLO, by = list(onlypotswithsurvivingseedsTLO$Genotype_id), FUN = mean)
aggregatedonlypotswithsurvivingseedsTLP <- aggregate(onlypotswithsurvivingseedsTLP, by = list(onlypotswithsurvivingseedsTLP$Genotype_id), FUN = mean)
aggregatedonlypotswithsurvivingseedsTHO <- aggregate(onlypotswithsurvivingseedsTHO, by = list(onlypotswithsurvivingseedsTHO$Genotype_id), FUN = mean)
aggregatedonlypotswithsurvivingseedsTHP <- aggregate(onlypotswithsurvivingseedsTHP, by = list(onlypotswithsurvivingseedsTHP$Genotype_id), FUN = mean)
#After the data has been aggregated into averages by replicate,
#I still need to know the number of replicates to use in the equation for selective deaths.
#This is easily accomplished in a frequency table called on the non-aggregated data
nreplicatestableMLO <- table(madridlowwateroneseedselectivedeathsdata$Genotype_id)
nreplicatestableMHO <- table(madridhighwateroneseedselectivedeathsdata$Genotype_id)
nreplicatestableMLP <- table(madridlowwatertwentyseedsselectivedeathsdata$Genotype_id)
nreplicatestableMHP <- table(madridhighwatertwentyseedsselectivedeathsdata$Genotype_id)
nreplicatestableTLO <- table(tuebingenlowwateroneseedselectivedeathsdata$Genotype_id)
nreplicatestableTHO <- table(tuebingenhighwateroneseedselectivedeathsdata$Genotype_id)
nreplicatestableTLP <- table(tuebingenlowwatertwentyseedsselectivedeathsdata$Genotype_id)
nreplicatestableTHP <- table(tuebingenhighwatertwentyseedsselectivedeathsdata$Genotype_id)
#I also need a table with the number of replicates AFTER OMITTING replicates with no surviving seeds
nreplicatestableomittingreplicateswithnosurvivingseedsMLO <- table(onlypotswithsurvivingseedsMLO$Genotype_id)
nreplicatestableomittingreplicateswithnosurvivingseedsMLP <- table(onlypotswithsurvivingseedsMLP$Genotype_id)
nreplicatestableomittingreplicateswithnosurvivingseedsMHO <- table(onlypotswithsurvivingseedsMHO$Genotype_id)
nreplicatestableomittingreplicateswithnosurvivingseedsMHP <- table(onlypotswithsurvivingseedsMHP$Genotype_id)
nreplicatestableomittingreplicateswithnosurvivingseedsTLO <- table(onlypotswithsurvivingseedsTLO$Genotype_id)
nreplicatestableomittingreplicateswithnosurvivingseedsTLP <- table(onlypotswithsurvivingseedsTLP$Genotype_id)
nreplicatestableomittingreplicateswithnosurvivingseedsTHO <- table(onlypotswithsurvivingseedsTHO$Genotype_id)
nreplicatestableomittingreplicateswithnosurvivingseedsTHP <- table(onlypotswithsurvivingseedsTHP$Genotype_id)
#I also need to pull out the total number of replicates (including those with no surviving seeds)
#but ONLY for genotypes with at least one replicate with surviving seeds.
onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsMLO <- subset(aggregatedwithcolumnsnosurvivingseedsMLO, Surviving_individuals_pot > 0.0, select = c("Replicates"))
onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsMLP <- subset(aggregatedwithcolumnsnosurvivingseedsMLP, Surviving_individuals_pot > 0.0, select = c("Replicates"))
onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsMHO <- subset(aggregatedwithcolumnsnosurvivingseedsMHO, Surviving_individuals_pot > 0.0, select = c("Replicates"))
onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsMHP <- subset(aggregatedwithcolumnsnosurvivingseedsMHP, Surviving_individuals_pot > 0.0, select = c("Replicates"))
onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsTLO <- subset(aggregatedwithcolumnsnosurvivingseedsTLO, Surviving_individuals_pot > 0.0, select = c("Replicates"))
onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsTLP <- subset(aggregatedwithcolumnsnosurvivingseedsTLP, Surviving_individuals_pot > 0.0, select = c("Replicates"))
onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsTHO <- subset(aggregatedwithcolumnsnosurvivingseedsTHO, Surviving_individuals_pot > 0.0, select = c("Replicates"))
onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsTHP <- subset(aggregatedwithcolumnsnosurvivingseedsTHP, Surviving_individuals_pot > 0.0, select = c("Replicates"))
#Now add columns to the aggregated data.
#This function only takes the aggregated data including replicates with no surviving seeds
aggregatedwithcolumnsnosurvivingseedsMLO <- AddColumns(aggregatedpotswithnosurvivingseedsMLO, nreplicatestableMLO)
aggregatedwithcolumnsnosurvivingseedsMLP <- AddColumns(aggregatedpotswithnosurvivingseedsMLP, nreplicatestableMLP)
aggregatedwithcolumnsnosurvivingseedsMHO <- AddColumns(aggregatedpotswithnosurvivingseedsMHO, nreplicatestableMHO)
aggregatedwithcolumnsnosurvivingseedsMHP <- AddColumns(aggregatedpotswithnosurvivingseedsMHP, nreplicatestableMHP)
aggregatedwithcolumnsnosurvivingseedsTLO <- AddColumns(aggregatedpotswithnosurvivingseedsTLO, nreplicatestableTLO)
aggregatedwithcolumnsnosurvivingseedsTLP <- AddColumns(aggregatedpotswithnosurvivingseedsTLP, nreplicatestableTLP)
aggregatedwithcolumnsnosurvivingseedsTHO <- AddColumns(aggregatedpotswithnosurvivingseedsTHO, nreplicatestableTHO)
aggregatedwithcolumnsnosurvivingseedsTHP <- AddColumns(aggregatedpotswithnosurvivingseedsTHP, nreplicatestableTHP)
#Now add columns to aggregated data which OMITS replicates with no surviving seeds.
#The number in the $Replicates column will be the total number of replicates for that genotype,
#INCLUDING replicates with no surviving seeds.
aggregatedwithcolumnsonlyreplicateswithsurvivingseedsMLO <- AddColumns(aggregatedonlypotswithsurvivingseedsMLO, onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsMLO$Replicates)
aggregatedwithcolumnsonlyreplicateswithsurvivingseedsMLP <- AddColumns(aggregatedonlypotswithsurvivingseedsMLP, onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsMLP$Replicates)
aggregatedwithcolumnsonlyreplicateswithsurvivingseedsMHO <- AddColumns(aggregatedonlypotswithsurvivingseedsMHO, onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsMHO$Replicates)
aggregatedwithcolumnsonlyreplicateswithsurvivingseedsMHP <- AddColumns(aggregatedonlypotswithsurvivingseedsMHP, onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsMHP$Replicates)
aggregatedwithcolumnsonlyreplicateswithsurvivingseedsTLO <- AddColumns(aggregatedonlypotswithsurvivingseedsTLO, onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsTLO$Replicates)
aggregatedwithcolumnsonlyreplicateswithsurvivingseedsTLP <- AddColumns(aggregatedonlypotswithsurvivingseedsTLP, onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsTLP$Replicates)
aggregatedwithcolumnsonlyreplicateswithsurvivingseedsTHO <- AddColumns(aggregatedonlypotswithsurvivingseedsTHO, onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsTHO$Replicates)
aggregatedwithcolumnsonlyreplicateswithsurvivingseedsTHP <- AddColumns(aggregatedonlypotswithsurvivingseedsTHP, onlygenotypeswithsomesurvivingseedsbutincludingreplicateswithnosurvivingseedsTHP$Replicates)
#Following lines create datasets to compare the standard deviation within genotypes.
onlypotswithsurvivingseedsstdevforbirthsMLO <- CalculateVarianceStDevandMeaninSeedProduction(onlypotswithsurvivingseedsMLO)
onlypotswithsurvivingseedsstdevforbirthsMLP <- CalculateVarianceStDevandMeaninSeedProduction(onlypotswithsurvivingseedsMLP)
onlypotswithsurvivingseedsstdevforbirthsMHO <- CalculateVarianceStDevandMeaninSeedProduction(onlypotswithsurvivingseedsMHO)
onlypotswithsurvivingseedsstdevforbirthsMHP <- CalculateVarianceStDevandMeaninSeedProduction(onlypotswithsurvivingseedsMHP)
onlypotswithsurvivingseedsstdevforbirthsTLO <- CalculateVarianceStDevandMeaninSeedProduction(onlypotswithsurvivingseedsTLO)
onlypotswithsurvivingseedsstdevforbirthsTLP <- CalculateVarianceStDevandMeaninSeedProduction(onlypotswithsurvivingseedsTLP)
onlypotswithsurvivingseedsstdevforbirthsTHO <- CalculateVarianceStDevandMeaninSeedProduction(onlypotswithsurvivingseedsTHO)
onlypotswithsurvivingseedsstdevforbirthsTHP <- CalculateVarianceStDevandMeaninSeedProduction(onlypotswithsurvivingseedsTHP)
#The following lines remove genotypes with a variance of zero.
onlysurvivingseedsnozeroesinvarianceMLO <- subset(onlypotswithsurvivingseedsstdevforbirthsMLO, Variance > 0.0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind", "Variance", "Mean", "StDev"))
onlysurvivingseedsnozeroesinvarianceMLP <- subset(onlypotswithsurvivingseedsstdevforbirthsMLP, Variance > 0.0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind", "Variance", "Mean", "StDev"))
onlysurvivingseedsnozeroesinvarianceMHO <- subset(onlypotswithsurvivingseedsstdevforbirthsMHO, Variance > 0.0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind", "Variance", "Mean", "StDev"))
onlysurvivingseedsnozeroesinvarianceMHP <- subset(onlypotswithsurvivingseedsstdevforbirthsMHP, Variance > 0.0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind", "Variance", "Mean", "StDev"))
onlysurvivingseedsnozeroesinvarianceTLO <- subset(onlypotswithsurvivingseedsstdevforbirthsTLO, Variance > 0.0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind", "Variance", "Mean", "StDev"))
onlysurvivingseedsnozeroesinvarianceTLP <- subset(onlypotswithsurvivingseedsstdevforbirthsTLP, Variance > 0.0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind", "Variance", "Mean", "StDev"))
onlysurvivingseedsnozeroesinvarianceTHO <- subset(onlypotswithsurvivingseedsstdevforbirthsTHO, Variance > 0.0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind", "Variance", "Mean", "StDev"))
onlysurvivingseedsnozeroesinvarianceTHP <- subset(onlypotswithsurvivingseedsstdevforbirthsTHP, Variance > 0.0, select = c("Genotype_id", "Field_site", "Watering_treatment", "Surviving_individuals_pot", "Seeds_total_pot", "Seeds_by_ind", "Variance", "Mean", "StDev"))
#Now aggregate the resulting dataset to ensure that genotypes with more replicates don't get more represented in the regression.
aggregatedonlysurvivingseedsnozeroesinvarianceMLO <- aggregate(onlysurvivingseedsnozeroesinvarianceMLO, by = list(onlysurvivingseedsnozeroesinvarianceMLO$Genotype_id), FUN = mean)
aggregatedonlysurvivingseedsnozeroesinvarianceMLP <- aggregate(onlysurvivingseedsnozeroesinvarianceMLP, by = list(onlysurvivingseedsnozeroesinvarianceMLP$Genotype_id), FUN = mean)
aggregatedonlysurvivingseedsnozeroesinvarianceMHO <- aggregate(onlysurvivingseedsnozeroesinvarianceMHO, by = list(onlysurvivingseedsnozeroesinvarianceMHO$Genotype_id), FUN = mean)
aggregatedonlysurvivingseedsnozeroesinvarianceMHP <- aggregate(onlysurvivingseedsnozeroesinvarianceMHP, by = list(onlysurvivingseedsnozeroesinvarianceMHP$Genotype_id), FUN = mean)
aggregatedonlysurvivingseedsnozeroesinvarianceTLO <- aggregate(onlysurvivingseedsnozeroesinvarianceTLO, by = list(onlysurvivingseedsnozeroesinvarianceTLO$Genotype_id), FUN = mean)
aggregatedonlysurvivingseedsnozeroesinvarianceTLP <- aggregate(onlysurvivingseedsnozeroesinvarianceTLP, by = list(onlysurvivingseedsnozeroesinvarianceTLP$Genotype_id), FUN = mean)
aggregatedonlysurvivingseedsnozeroesinvarianceTHO <- aggregate(onlysurvivingseedsnozeroesinvarianceTHO, by = list(onlysurvivingseedsnozeroesinvarianceTHO$Genotype_id), FUN = mean)
aggregatedonlysurvivingseedsnozeroesinvarianceTHP <- aggregate(onlysurvivingseedsnozeroesinvarianceTHP, by = list(onlysurvivingseedsnozeroesinvarianceTHP$Genotype_id), FUN = mean)
max(aggregatedonlysurvivingseedsnozeroesinvarianceMHP$Seeds_by_ind)
#For the extreme-value bias analysis on the life history stage of seed production,
#I need to set the standard deviation for within-genotype variation as a function
#of the mean. I calculate that slope by doing a simple regression.
#I require that the line passes through 0,0 -- this simplifies the later math
#and also seems like a more realistic assumption for the regression.
#OMITTED POTS WITH NO SURVIVING SEEDS AND GENOTYPES WITH NO VARIANCE
#MAKE SURE THE DATASET IS THE AGGREGATED VERSION
lm(StDev ~ Mean + 0, data = aggregatedonlysurvivingseedsnozeroesinvarianceMLO)
lm(StDev ~ Mean + 0, data = aggregatedonlysurvivingseedsnozeroesinvarianceMLP)
lm(StDev ~ Mean + 0, data = aggregatedonlysurvivingseedsnozeroesinvarianceMHO)
lm(StDev ~ Mean + 0, data = aggregatedonlysurvivingseedsnozeroesinvarianceMHP)
lm(StDev ~ Mean + 0, data = aggregatedonlysurvivingseedsnozeroesinvarianceTLO)
lm(StDev ~ Mean + 0, data = aggregatedonlysurvivingseedsnozeroesinvarianceTLP)
lm(StDev ~ Mean + 0, data = aggregatedonlysurvivingseedsnozeroesinvarianceTHO)
lm(StDev ~ Mean + 0, data = aggregatedonlysurvivingseedsnozeroesinvarianceTHP)
#ANALYSES
#Following are the basic selective death calculations,
#without accounting for extreme-value bias.
survivalselectivedeathsMLO <- CalculateSelectiveDeathsSurvival(aggregatedwithcolumnsnosurvivingseedsMLO, nreplicatestableMLO, 0)
survivalselectivedeathsMLP <- CalculateSelectiveDeathsSurvival(aggregatedwithcolumnsnosurvivingseedsMLP, nreplicatestableMLP, 1)
survivalselectivedeathsMHO <- CalculateSelectiveDeathsSurvival(aggregatedwithcolumnsnosurvivingseedsMHO, nreplicatestableMHO, 0)
survivalselectivedeathsMHP <- CalculateSelectiveDeathsSurvival(aggregatedwithcolumnsnosurvivingseedsMHP, nreplicatestableMHP, 1)
survivalselectivedeathsTLO <- CalculateSelectiveDeathsSurvival(aggregatedwithcolumnsnosurvivingseedsTLO, nreplicatestableTLO, 0)
survivalselectivedeathsTLP <- CalculateSelectiveDeathsSurvival(aggregatedwithcolumnsnosurvivingseedsTLP, nreplicatestableTLP, 1)
survivalselectivedeathsTHO <- CalculateSelectiveDeathsSurvival(aggregatedwithcolumnsnosurvivingseedsTHO, nreplicatestableTHO, 0)
survivalselectivedeathsTHP <- CalculateSelectiveDeathsSurvival(aggregatedwithcolumnsnosurvivingseedsTHP, nreplicatestableTHP, 1)
birthsselectivedeathsMLO <- CalculateSelectiveDeathsBirths(aggregatedwithcolumnsonlyreplicateswithsurvivingseedsMLO, nreplicatestableomittingreplicateswithnosurvivingseedsMLO, 0)
birthsselectivedeathsMLP <- CalculateSelectiveDeathsBirths(aggregatedwithcolumnsonlyreplicateswithsurvivingseedsMLP, nreplicatestableomittingreplicateswithnosurvivingseedsMLP, 1)
birthsselectivedeathsMHO <- CalculateSelectiveDeathsBirths(aggregatedwithcolumnsonlyreplicateswithsurvivingseedsMHO, nreplicatestableomittingreplicateswithnosurvivingseedsMHO, 0)
birthsselectivedeathsMHP <- CalculateSelectiveDeathsBirths(aggregatedwithcolumnsonlyreplicateswithsurvivingseedsMHP, nreplicatestableomittingreplicateswithnosurvivingseedsMHP, 1)
birthsselectivedeathsTLO <- CalculateSelectiveDeathsBirths(aggregatedwithcolumnsonlyreplicateswithsurvivingseedsTLO, nreplicatestableomittingreplicateswithnosurvivingseedsTLO, 0)
birthsselectivedeathsTLP <- CalculateSelectiveDeathsBirths(aggregatedwithcolumnsonlyreplicateswithsurvivingseedsTLP, nreplicatestableomittingreplicateswithnosurvivingseedsTLP, 1)
birthsselectivedeathsTHO <- CalculateSelectiveDeathsBirths(aggregatedwithcolumnsonlyreplicateswithsurvivingseedsTHO, nreplicatestableomittingreplicateswithnosurvivingseedsTHO, 0)
birthsselectivedeathsTHP <- CalculateSelectiveDeathsBirths(aggregatedwithcolumnsonlyreplicateswithsurvivingseedsTHP, nreplicatestableomittingreplicateswithnosurvivingseedsTHP, 1)
total_selective_deaths_survival_MLO <- sum(survivalselectivedeathsMLO$Selective_deaths_survival)
total_selective_deaths_survival_MLP <- sum(survivalselectivedeathsMLP$Selective_deaths_survival)
total_selective_deaths_survival_MHO <- sum(survivalselectivedeathsMHO$Selective_deaths_survival)
total_selective_deaths_survival_MHP <- sum(survivalselectivedeathsMHP$Selective_deaths_survival)
total_selective_deaths_survival_TLO <- sum(survivalselectivedeathsTLO$Selective_deaths_survival)
total_selective_deaths_survival_TLP <- sum(survivalselectivedeathsTLP$Selective_deaths_survival)
total_selective_deaths_survival_THO <- sum(survivalselectivedeathsTHO$Selective_deaths_survival)
total_selective_deaths_survival_THP <- sum(survivalselectivedeathsTHP$Selective_deaths_survival)
total_selective_deaths_survival_MLO
total_selective_deaths_survival_MLP
total_selective_deaths_births_MLO <- sum(birthsselectivedeathsMLO$Selective_deaths_births)
total_selective_deaths_births_MLP <- sum(birthsselectivedeathsMLP$Selective_deaths_births)
total_selective_deaths_births_MHO <- sum(birthsselectivedeathsMHO$Selective_deaths_births)
total_selective_deaths_births_MHP <- sum(birthsselectivedeathsMHP$Selective_deaths_births)
total_selective_deaths_births_TLO <- sum(birthsselectivedeathsTLO$Selective_deaths_births)
total_selective_deaths_births_TLP <- sum(birthsselectivedeathsTLP$Selective_deaths_births)
total_selective_deaths_births_THO <- sum(birthsselectivedeathsTHO$Selective_deaths_births)
total_selective_deaths_births_THP <- sum(birthsselectivedeathsTHP$Selective_deaths_births)
total_selective_deaths_births_MHP
total_seeds_for_next_generation_MLO <- sum(birthsselectivedeathsMLO$Seeds_for_next_generation)
total_seeds_for_next_generation_MLP <- sum(birthsselectivedeathsMLP$Seeds_for_next_generation)
total_seeds_for_next_generation_MHO <- sum(birthsselectivedeathsMHO$Seeds_for_next_generation)
total_seeds_for_next_generation_MHP <- sum(birthsselectivedeathsMHP$Seeds_for_next_generation)
total_seeds_for_next_generation_TLO <- sum(birthsselectivedeathsTLO$Seeds_for_next_generation)
total_seeds_for_next_generation_TLP <- sum(birthsselectivedeathsTLP$Seeds_for_next_generation)
total_seeds_for_next_generation_THO <- sum(birthsselectivedeathsTHO$Seeds_for_next_generation)
total_seeds_for_next_generation_THP <- sum(birthsselectivedeathsTHP$Seeds_for_next_generation)
total_seeds_for_next_generation_MHP
proportion_deaths_selective_births_MLO <- total_selective_deaths_births_MLO / (sum(birthsselectivedeathsMLO$Surviving_individuals_pot) * max(birthsselectivedeathsMLO$Seeds_by_ind) - total_seeds_for_next_generation_MLO)
proportion_deaths_selective_births_MLP <- total_selective_deaths_births_MLP / (sum(birthsselectivedeathsMLP$Surviving_individuals_pot) * max(birthsselectivedeathsMLP$Seeds_by_ind) - total_seeds_for_next_generation_MLP)
proportion_deaths_selective_births_MHO <- total_selective_deaths_births_MHO / (sum(birthsselectivedeathsMHO$Surviving_individuals_pot) * max(birthsselectivedeathsMHO$Seeds_by_ind) - total_seeds_for_next_generation_MHO)
proportion_deaths_selective_births_MHP <- total_selective_deaths_births_MHP / (sum(birthsselectivedeathsMHP$Surviving_individuals_pot) * max(birthsselectivedeathsMHP$Seeds_by_ind) - total_seeds_for_next_generation_MHP)
proportion_deaths_selective_births_TLO <- total_selective_deaths_births_TLO / (sum(birthsselectivedeathsTLO$Surviving_individuals_pot) * max(birthsselectivedeathsTLO$Seeds_by_ind) - total_seeds_for_next_generation_TLO)
proportion_deaths_selective_births_TLP <- total_selective_deaths_births_TLP / (sum(birthsselectivedeathsTLP$Surviving_individuals_pot) * max(birthsselectivedeathsTLP$Seeds_by_ind) - total_seeds_for_next_generation_TLP)
proportion_deaths_selective_births_THO <- total_selective_deaths_births_THO / (sum(birthsselectivedeathsTHO$Surviving_individuals_pot) * max(birthsselectivedeathsTHO$Seeds_by_ind) - total_seeds_for_next_generation_THO)
proportion_deaths_selective_births_THP <- total_selective_deaths_births_THP / (sum(birthsselectivedeathsTHP$Surviving_individuals_pot) * max(birthsselectivedeathsTHP$Seeds_by_ind) - total_seeds_for_next_generation_THP)
proportion_deaths_selective_births_MLO
proportion_deaths_selective_births_MLP
proportion_deaths_selective_births_MHO
proportion_deaths_selective_deaths_MLO <- total_selective_deaths_survival_MLO / (sum(survivalselectivedeathsMLO$Replicates))
proportion_deaths_selective_deaths_MLP <- total_selective_deaths_survival_MLP / (sum(survivalselectivedeathsMLP$Replicates)*30)
proportion_deaths_selective_deaths_MHO <- total_selective_deaths_survival_MHO / (sum(survivalselectivedeathsMHO$Replicates))
proportion_deaths_selective_deaths_MHP <- total_selective_deaths_survival_MHP / (sum(survivalselectivedeathsMHP$Replicates)*30)
proportion_deaths_selective_deaths_TLO <- total_selective_deaths_survival_TLO / (sum(survivalselectivedeathsTLO$Replicates))
proportion_deaths_selective_deaths_TLP <- total_selective_deaths_survival_TLP / (sum(survivalselectivedeathsTLP$Replicates)*30)
proportion_deaths_selective_deaths_THO <- total_selective_deaths_survival_THO / (sum(survivalselectivedeathsTHO$Replicates))
proportion_deaths_selective_deaths_THP <- total_selective_deaths_survival_THP / (sum(survivalselectivedeathsTHP$Replicates)*30)
proportion_deaths_selective_deaths_MLO
proportion_deaths_selective_deaths_MLP
total_surviving_seeds_MLO <- sum(survivalselectivedeathsMLO$Total_surviving_seeds)
total_surviving_seeds_MLP <- sum(survivalselectivedeathsMLP$Total_surviving_seeds)
total_surviving_seeds_MHO <- sum(survivalselectivedeathsMHO$Total_surviving_seeds)
total_surviving_seeds_MHP <- sum(survivalselectivedeathsMHP$Total_surviving_seeds)
total_surviving_seeds_TLO <- sum(survivalselectivedeathsTLO$Total_surviving_seeds)
total_surviving_seeds_TLP <- sum(survivalselectivedeathsTLP$Total_surviving_seeds)
total_surviving_seeds_THO <- sum(survivalselectivedeathsTHO$Total_surviving_seeds)
total_surviving_seeds_THP <- sum(survivalselectivedeathsTHP$Total_surviving_seeds)
total_seeds_produced_MLO <- sum(birthsselectivedeathsMLO$Seeds_total_pot)
total_seeds_produced_MLP <- sum(birthsselectivedeathsMLP$Seeds_total_pot)
total_seeds_produced_MHO <- sum(birthsselectivedeathsMHO$Seeds_total_pot)
total_seeds_produced_MHP <- sum(birthsselectivedeathsMHP$Seeds_total_pot)
total_seeds_produced_TLO <- sum(birthsselectivedeathsTLO$Seeds_total_pot)
total_seeds_produced_TLP <- sum(birthsselectivedeathsTLP$Seeds_total_pot)
total_seeds_produced_THO <- sum(birthsselectivedeathsTHO$Seeds_total_pot)
total_seeds_produced_THP <- sum(birthsselectivedeathsTHP$Seeds_total_pot)
kfecundityMLO <- (total_seeds_produced_MLO / total_surviving_seeds_MLO)
kfecundityMLP <- (total_seeds_produced_MLP / total_surviving_seeds_MLP)
kfecundityMHO <- (total_seeds_produced_MHO / total_surviving_seeds_MHO)
kfecundityMHP <- (total_seeds_produced_MHP / total_surviving_seeds_MHP)
kfecundityTLO <- (total_seeds_produced_TLO / total_surviving_seeds_TLO)
kfecundityTLP <- (total_seeds_produced_TLP / total_surviving_seeds_TLP)
kfecundityTHO <- (total_seeds_produced_THO / total_surviving_seeds_THO)
kfecundityTHP <- (total_seeds_produced_THP / total_surviving_seeds_THP)
kfecundityMLO
kfecundityMLP
kfecundityMHO
kfecundityMHP
kfecundityTLO
kfecundityTLP
kfecundityTHO
kfecundityTHP
kbestsurvivalMLO <- 1 - (min(survivalselectivedeathsMLO$Genotype_death_rate))
kbestsurvivalMHO <- 1 - (min(survivalselectivedeathsMHO$Genotype_death_rate))
kbestsurvivalTLO <- 1 - (min(survivalselectivedeathsTLO$Genotype_death_rate))
kbestsurvivalTHO <- 1 - (min(survivalselectivedeathsTHO$Genotype_death_rate))
kbestsurvivalMLP <- 1 - (min(survivalselectivedeathsMLP$Genotype_death_rate))
kbestsurvivalMHP <- 1 - (min(survivalselectivedeathsMHP$Genotype_death_rate))
kbestsurvivalTLP <- 1 - (min(survivalselectivedeathsTLP$Genotype_death_rate))
kbestsurvivalTHP <- 1 - (min(survivalselectivedeathsTHP$Genotype_death_rate))
kmeansurvivalMLO <- total_surviving_seeds_MLO / (sum(survivalselectivedeathsMLO$Replicates))
kmeansurvivalMHO <- total_surviving_seeds_MHO / (sum(survivalselectivedeathsMHO$Replicates))
kmeansurvivalTLO <- total_surviving_seeds_TLO / (sum(survivalselectivedeathsTLO$Replicates))
kmeansurvivalTHO <- total_surviving_seeds_THO / (sum(survivalselectivedeathsTHO$Replicates))
kmeansurvivalMLP <- total_surviving_seeds_MLP / (30*sum(survivalselectivedeathsMLP$Replicates))
kmeansurvivalMHP <- total_surviving_seeds_MHP / (30*sum(survivalselectivedeathsMHP$Replicates))
kmeansurvivalTLP <- total_surviving_seeds_TLP / (30*sum(survivalselectivedeathsTLP$Replicates))
kmeansurvivalTHP <- total_surviving_seeds_THP / (30*sum(survivalselectivedeathsTHP$Replicates))
reproductive_excess_fecundity_lowdispersal_MLO <- total_surviving_seeds_MLO * (kfecundityMLO - (1 / (0.001 * kbestsurvivalMLO)))
reproductive_excess_fecundity_lowdispersal_MHO <- total_surviving_seeds_MHO * (kfecundityMHO - (1 / (0.001 * kbestsurvivalMHO)))
reproductive_excess_fecundity_lowdispersal_TLO <- total_surviving_seeds_TLO * (kfecundityTLO - (1 / (0.001 * kbestsurvivalTLO)))
reproductive_excess_fecundity_lowdispersal_THO <- total_surviving_seeds_THO * (kfecundityTHO - (1 / (0.001 * kbestsurvivalTHO)))
reproductive_excess_fecundity_lowdispersal_MLP <- total_surviving_seeds_MLP * (kfecundityMLP - (1 / (0.01 * kbestsurvivalMLP)))
reproductive_excess_fecundity_lowdispersal_MHP <- total_surviving_seeds_MHP * (kfecundityMHP - (1 / (0.01 * kbestsurvivalMHP)))
reproductive_excess_fecundity_lowdispersal_TLP <- total_surviving_seeds_TLP * (kfecundityTLP - (1 / (0.01 * kbestsurvivalTLP)))
reproductive_excess_fecundity_lowdispersal_THP <- total_surviving_seeds_THP * (kfecundityTHP - (1 / (0.01 * kbestsurvivalTHP)))
reproductive_excess_fecundity_highdispersal_MLO <- total_surviving_seeds_MLO * (kfecundityMLO - (1 / (0.01 * kbestsurvivalMLO)))
reproductive_excess_fecundity_highdispersal_MHO <- total_surviving_seeds_MHO * (kfecundityMHO - (1 / (0.01 * kbestsurvivalMHO)))
reproductive_excess_fecundity_highdispersal_TLO <- total_surviving_seeds_TLO * (kfecundityTLO - (1 / (0.01 * kbestsurvivalTLO)))
reproductive_excess_fecundity_highdispersal_THO <- total_surviving_seeds_THO * (kfecundityTHO - (1 / (0.01 * kbestsurvivalTHO)))
reproductive_excess_fecundity_highdispersal_MLP <- total_surviving_seeds_MLP * (kfecundityMLP - (1 / (0.1 * kbestsurvivalMLP)))
reproductive_excess_fecundity_highdispersal_MHP <- total_surviving_seeds_MHP * (kfecundityMHP - (1 / (0.1 * kbestsurvivalMHP)))
reproductive_excess_fecundity_highdispersal_TLP <- total_surviving_seeds_TLP * (kfecundityTLP - (1 / (0.1 * kbestsurvivalTLP)))
reproductive_excess_fecundity_highdispersal_THP <- total_surviving_seeds_THP * (kfecundityTHP - (1 / (0.1 * kbestsurvivalTHP)))
reproductive_excess_survival_lowdispersal_MLO <- sum(survivalselectivedeathsMLO$Replicates) * (kbestsurvivalMLO - (1 / (0.001 * kfecundityMLO)))
reproductive_excess_survival_lowdispersal_MHO <- sum(survivalselectivedeathsMHO$Replicates) * (kbestsurvivalMHO - (1 / (0.001 * kfecundityMHO)))
reproductive_excess_survival_lowdispersal_TLO <- sum(survivalselectivedeathsTLO$Replicates) * (kbestsurvivalTLO - (1 / (0.001 * kfecundityTLO)))
reproductive_excess_survival_lowdispersal_THO <- sum(survivalselectivedeathsTHO$Replicates) * (kbestsurvivalTHO - (1 / (0.001 * kfecundityTHO)))
reproductive_excess_survival_lowdispersal_MLP <- (30*sum(survivalselectivedeathsMLP$Replicates)) * (kbestsurvivalMLP - (1 / (0.01 * kfecundityMLP)))
reproductive_excess_survival_lowdispersal_MHP <- (30*sum(survivalselectivedeathsMHP$Replicates)) * (kbestsurvivalMHP - (1 / (0.01 * kfecundityMHP)))
reproductive_excess_survival_lowdispersal_TLP <- (30*sum(survivalselectivedeathsTLP$Replicates)) * (kbestsurvivalTLP - (1 / (0.01 * kfecundityTLP)))
reproductive_excess_survival_lowdispersal_THP <- (30*sum(survivalselectivedeathsTHP$Replicates)) * (kbestsurvivalTHP - (1 / (0.01 * kfecundityTHP)))
reproductive_excess_survival_highdispersal_MLO <- sum(survivalselectivedeathsMLO$Replicates) * (kbestsurvivalMLO - (1 / (0.01 * kfecundityMLO)))
reproductive_excess_survival_highdispersal_MHO <- sum(survivalselectivedeathsMHO$Replicates) * (kbestsurvivalMHO - (1 / (0.01 * kfecundityMHO)))
reproductive_excess_survival_highdispersal_TLO <- sum(survivalselectivedeathsTLO$Replicates) * (kbestsurvivalTLO - (1 / (0.01 * kfecundityTLO)))
reproductive_excess_survival_highdispersal_THO <- sum(survivalselectivedeathsTHO$Replicates) * (kbestsurvivalTHO - (1 / (0.01 * kfecundityTHO)))
reproductive_excess_survival_highdispersal_MLP <- (30*sum(survivalselectivedeathsMLP$Replicates)) * (kbestsurvivalMLP - (1 / (0.1 * kfecundityMLP)))
reproductive_excess_survival_highdispersal_MHP <- (30*sum(survivalselectivedeathsMHP$Replicates)) * (kbestsurvivalMHP - (1 / (0.1 * kfecundityMHP)))
reproductive_excess_survival_highdispersal_TLP <- (30*sum(survivalselectivedeathsTLP$Replicates)) * (kbestsurvivalTLP - (1 / (0.1 * kfecundityTLP)))
reproductive_excess_survival_highdispersal_THP <- (30*sum(survivalselectivedeathsTHP$Replicates)) * (kbestsurvivalTHP - (1 / (0.1 * kfecundityTHP)))
reproductive_excess_fecundity_lowdispersal_MLO / sum(survivalselectivedeathsMLO$Replicates)
reproductive_excess_fecundity_lowdispersal_MHO / sum(survivalselectivedeathsMHO$Replicates)
reproductive_excess_fecundity_lowdispersal_TLO / sum(survivalselectivedeathsTLO$Replicates)
reproductive_excess_fecundity_lowdispersal_THO / sum(survivalselectivedeathsTHO$Replicates)
reproductive_excess_fecundity_lowdispersal_MLP / sum(survivalselectivedeathsMLP$Replicates)
reproductive_excess_fecundity_lowdispersal_MHP / sum(survivalselectivedeathsMHP$Replicates)
reproductive_excess_fecundity_lowdispersal_TLP / sum(survivalselectivedeathsTLP$Replicates)
reproductive_excess_fecundity_lowdispersal_THP / sum(survivalselectivedeathsTHP$Replicates)
reproductive_excess_survival_lowdispersal_MLO
reproductive_excess_survival_lowdispersal_MHO
reproductive_excess_survival_lowdispersal_TLO
reproductive_excess_survival_lowdispersal_THO
reproductive_excess_survival_lowdispersal_MLP
reproductive_excess_survival_lowdispersal_MHP
reproductive_excess_survival_lowdispersal_TLP
reproductive_excess_survival_lowdispersal_THP
reproductive_excess_survival_lowdispersal_MLO / sum(survivalselectivedeathsMLO$Replicates)
reproductive_excess_survival_lowdispersal_MHO / sum(survivalselectivedeathsMHO$Replicates)
reproductive_excess_survival_lowdispersal_TLO / sum(survivalselectivedeathsTLO$Replicates)
reproductive_excess_survival_lowdispersal_THO / sum(survivalselectivedeathsTHO$Replicates)
reproductive_excess_survival_lowdispersal_MLP / sum(survivalselectivedeathsMLP$Replicates)
reproductive_excess_survival_lowdispersal_MHP / sum(survivalselectivedeathsMHP$Replicates)
reproductive_excess_survival_lowdispersal_TLP / sum(survivalselectivedeathsTLP$Replicates)
reproductive_excess_survival_lowdispersal_THP / sum(survivalselectivedeathsTHP$Replicates)
reproductive_excess_fecundity_highdispersal_MLO / sum(survivalselectivedeathsMLO$Replicates)
reproductive_excess_fecundity_highdispersal_MHO / sum(survivalselectivedeathsMHO$Replicates)
reproductive_excess_fecundity_highdispersal_TLO / sum(survivalselectivedeathsTLO$Replicates)
reproductive_excess_fecundity_highdispersal_THO / sum(survivalselectivedeathsTHO$Replicates)
reproductive_excess_fecundity_highdispersal_MLP / sum(survivalselectivedeathsMLP$Replicates)
reproductive_excess_fecundity_highdispersal_MHP / sum(survivalselectivedeathsMHP$Replicates)
reproductive_excess_fecundity_highdispersal_TLP / sum(survivalselectivedeathsTLP$Replicates)
reproductive_excess_fecundity_highdispersal_THP / sum(survivalselectivedeathsTHP$Replicates)
reproductive_excess_survival_highdispersal_MLO
reproductive_excess_survival_highdispersal_MHO
reproductive_excess_survival_highdispersal_TLO
reproductive_excess_survival_highdispersal_THO
reproductive_excess_survival_highdispersal_MLP
reproductive_excess_survival_highdispersal_MHP
reproductive_excess_survival_highdispersal_TLP
reproductive_excess_survival_highdispersal_THP
reproductive_excess_survival_highdispersal_MLO / sum(survivalselectivedeathsMLO$Replicates)
reproductive_excess_survival_highdispersal_MHO / sum(survivalselectivedeathsMHO$Replicates)
reproductive_excess_survival_highdispersal_TLO / sum(survivalselectivedeathsTLO$Replicates)
reproductive_excess_survival_highdispersal_THO / sum(survivalselectivedeathsTHO$Replicates)
reproductive_excess_survival_highdispersal_MLP / sum(survivalselectivedeathsMLP$Replicates)
reproductive_excess_survival_highdispersal_MHP / sum(survivalselectivedeathsMHP$Replicates)
reproductive_excess_survival_highdispersal_TLP / sum(survivalselectivedeathsTLP$Replicates)
reproductive_excess_survival_highdispersal_THP / sum(survivalselectivedeathsTHP$Replicates)
diffwithandwithoutsinglepotgenotypesMLO <- sum(birthsselectivedeathsMLO$Seeds_total_pot)/sum(birthsselectivedeathsMLO$Surviving_individuals_pot) - mean(aggregatedonlysurvivingseedsnozeroesinvarianceMLO$Mean)
diffwithandwithoutsinglepotgenotypesMLP <- sum(birthsselectivedeathsMLP$Seeds_total_pot)/sum(birthsselectivedeathsMLP$Surviving_individuals_pot) - mean(aggregatedonlysurvivingseedsnozeroesinvarianceMLP$Mean)
diffwithandwithoutsinglepotgenotypesMHO <- sum(birthsselectivedeathsMHO$Seeds_total_pot)/sum(birthsselectivedeathsMHO$Surviving_individuals_pot) - mean(aggregatedonlysurvivingseedsnozeroesinvarianceMHO$Mean)
diffwithandwithoutsinglepotgenotypesMHP <- sum(birthsselectivedeathsMHP$Seeds_total_pot)/sum(birthsselectivedeathsMHP$Surviving_individuals_pot) - mean(aggregatedonlysurvivingseedsnozeroesinvarianceMHP$Mean)
diffwithandwithoutsinglepotgenotypesTLO <- sum(birthsselectivedeathsTLO$Seeds_total_pot)/sum(birthsselectivedeathsTLO$Surviving_individuals_pot) - mean(aggregatedonlysurvivingseedsnozeroesinvarianceTLO$Mean)
diffwithandwithoutsinglepotgenotypesTLP <- sum(birthsselectivedeathsTLP$Seeds_total_pot)/sum(birthsselectivedeathsTLP$Surviving_individuals_pot) - mean(aggregatedonlysurvivingseedsnozeroesinvarianceTLP$Mean)
diffwithandwithoutsinglepotgenotypesTHO <- sum(birthsselectivedeathsTHO$Seeds_total_pot)/sum(birthsselectivedeathsTHO$Surviving_individuals_pot) - mean(aggregatedonlysurvivingseedsnozeroesinvarianceTHO$Mean)
diffwithandwithoutsinglepotgenotypesTHP <- sum(birthsselectivedeathsTHP$Seeds_total_pot)/sum(birthsselectivedeathsTHP$Surviving_individuals_pot) - mean(aggregatedonlysurvivingseedsnozeroesinvarianceTHP$Mean)
diffwithandwithoutsinglepotgenotypesMLO
diffwithandwithoutsinglepotgenotypesMLP
diffwithandwithoutsinglepotgenotypesMHO
diffwithandwithoutsinglepotgenotypesMHP
diffwithandwithoutsinglepotgenotypesTLO
diffwithandwithoutsinglepotgenotypesTLP
diffwithandwithoutsinglepotgenotypesTHO
diffwithandwithoutsinglepotgenotypesTHP
diffwithandwithoutsinglepotgenotypesMLO/(sum(birthsselectivedeathsMLO$Seeds_total_pot)/sum(birthsselectivedeathsMLO$Surviving_individuals_pot))
diffwithandwithoutsinglepotgenotypesMLP/(sum(birthsselectivedeathsMLP$Seeds_total_pot)/sum(birthsselectivedeathsMLP$Surviving_individuals_pot))
diffwithandwithoutsinglepotgenotypesMHO/(sum(birthsselectivedeathsMHO$Seeds_total_pot)/sum(birthsselectivedeathsMHO$Surviving_individuals_pot))
diffwithandwithoutsinglepotgenotypesMHP/(sum(birthsselectivedeathsMHP$Seeds_total_pot)/sum(birthsselectivedeathsMHP$Surviving_individuals_pot))
diffwithandwithoutsinglepotgenotypesTLO/(sum(birthsselectivedeathsTLO$Seeds_total_pot)/sum(birthsselectivedeathsTLO$Surviving_individuals_pot))
diffwithandwithoutsinglepotgenotypesTLP/(sum(birthsselectivedeathsTLP$Seeds_total_pot)/sum(birthsselectivedeathsTLP$Surviving_individuals_pot))
diffwithandwithoutsinglepotgenotypesTHO/(sum(birthsselectivedeathsTHO$Seeds_total_pot)/sum(birthsselectivedeathsTHO$Surviving_individuals_pot))
diffwithandwithoutsinglepotgenotypesTHP/(sum(birthsselectivedeathsTHP$Seeds_total_pot)/sum(birthsselectivedeathsTHP$Surviving_individuals_pot))
#The following analysis performs a Box-cox transformation on the data and then does an ANOVA on the resulting transform
#The intent is to investigate whether there is any evidence for differences in mean fecundity between genotypes
#or if the variance between replicates is so large that it swamps any signal.
bcMLO <- boxcox(lm(onlypotswithsurvivingseedsMLO$Seeds_by_ind ~ 1))
bcMHO <- boxcox(lm(onlypotswithsurvivingseedsMHO$Seeds_by_ind ~ 1))
bcMLP <- boxcox(lm(onlypotswithsurvivingseedsMLP$Seeds_by_ind ~ 1))
bcMHP <- boxcox(lm(onlypotswithsurvivingseedsMHP$Seeds_by_ind ~ 1))
bcTLO <- boxcox(lm(onlypotswithsurvivingseedsTLO$Seeds_by_ind ~ 1))
bcTHO <- boxcox(lm(onlypotswithsurvivingseedsTHO$Seeds_by_ind ~ 1))
bcTLP <- boxcox(lm(onlypotswithsurvivingseedsTLP$Seeds_by_ind ~ 1))
bcTHP <- boxcox(lm(onlypotswithsurvivingseedsTHP$Seeds_by_ind ~ 1))
bcMLO
boxcox(lm(onlypotswithsurvivingseedsMLO$Seeds_by_ind ~ 1))
boxcox(lm(onlypotswithsurvivingseedsMHO$Seeds_by_ind ~ 1))
boxcox(lm(onlypotswithsurvivingseedsMLP$Seeds_by_ind ~ 1))
boxcox(lm(onlypotswithsurvivingseedsMHP$Seeds_by_ind ~ 1))
boxcox(lm(onlypotswithsurvivingseedsTLO$Seeds_by_ind ~ 1))
boxcox(lm(onlypotswithsurvivingseedsTHO$Seeds_by_ind ~ 1))
boxcox(lm(onlypotswithsurvivingseedsTLP$Seeds_by_ind ~ 1))
boxcox(lm(onlypotswithsurvivingseedsTHP$Seeds_by_ind ~ 1))
lambdaMLO <- bcMLO$x[which.max(bcMLO$y)]
lambdaMHO <- bcMLO$x[which.max(bcMHO$y)]
lambdaMLP <- bcMLO$x[which.max(bcMLP$y)]
lambdaMHP <- bcMLO$x[which.max(bcMHP$y)]
lambdaTLO <- bcMLO$x[which.max(bcTLO$y)]
lambdaTHO <- bcMLO$x[which.max(bcTHO$y)]
lambdaTLP <- bcMLO$x[which.max(bcTLP$y)]
lambdaTHP <- bcMLO$x[which.max(bcTHP$y)]
boxcoxtransformonlypotswithsurvivingseedsMLO <- Boxcoxtransform(onlypotswithsurvivingseedsMLO, lambdaMLO)
boxcoxtransformonlypotswithsurvivingseedsMHO <- Boxcoxtransform(onlypotswithsurvivingseedsMHO, lambdaMHO)
boxcoxtransformonlypotswithsurvivingseedsMLP <- Boxcoxtransform(onlypotswithsurvivingseedsMLP, lambdaMLP)
boxcoxtransformonlypotswithsurvivingseedsMHP <- Boxcoxtransform(onlypotswithsurvivingseedsMHP, lambdaMHP)
boxcoxtransformonlypotswithsurvivingseedsTLO <- Boxcoxtransform(onlypotswithsurvivingseedsTLO, lambdaTLO)
boxcoxtransformonlypotswithsurvivingseedsTHO <- Boxcoxtransform(onlypotswithsurvivingseedsTHO, lambdaTHO)
boxcoxtransformonlypotswithsurvivingseedsTLP <- Boxcoxtransform(onlypotswithsurvivingseedsTLP, lambdaTLP)
boxcoxtransformonlypotswithsurvivingseedsTHP <- Boxcoxtransform(onlypotswithsurvivingseedsTHP, lambdaTHP)
anovaMLO <- aov(boxcox_transform_fecundity ~ Genotype_id, data = boxcoxtransformonlypotswithsurvivingseedsMLO)
anovaMHO <- aov(boxcox_transform_fecundity ~ Genotype_id, data = boxcoxtransformonlypotswithsurvivingseedsMHO)
anovaMLP <- aov(boxcox_transform_fecundity ~ Genotype_id, data = boxcoxtransformonlypotswithsurvivingseedsMLP)
anovaMHP <- aov(boxcox_transform_fecundity ~ Genotype_id, data = boxcoxtransformonlypotswithsurvivingseedsMHP)
anovaTLO <- aov(boxcox_transform_fecundity ~ Genotype_id, data = boxcoxtransformonlypotswithsurvivingseedsTLO)
anovaTHO <- aov(boxcox_transform_fecundity ~ Genotype_id, data = boxcoxtransformonlypotswithsurvivingseedsTHO)
anovaTLP <- aov(boxcox_transform_fecundity ~ Genotype_id, data = boxcoxtransformonlypotswithsurvivingseedsTLP)
anovaTHP <- aov(boxcox_transform_fecundity ~ Genotype_id, data = boxcoxtransformonlypotswithsurvivingseedsTHP)
summary(anovaMLO)
summary(anovaMHO)
summary(anovaMLP)
summary(anovaMHP)
summary(anovaTLO)
summary(anovaTHO)
summary(anovaTLP)
summary(anovaTHP)
hist(boxcoxtransformonlypotswithsurvivingseedsMLO$boxcox_transform_fecundity)
qqnorm(boxcoxtransformonlypotswithsurvivingseedsMLO$boxcox_transform_fecundity)
qqnorm(boxcoxtransformonlypotswithsurvivingseedsMHO$boxcox_transform_fecundity)
qqnorm(boxcoxtransformonlypotswithsurvivingseedsTLO$boxcox_transform_fecundity)
qqnorm(boxcoxtransformonlypotswithsurvivingseedsTHO$boxcox_transform_fecundity)
qqnorm(boxcoxtransformonlypotswithsurvivingseedsMLP$boxcox_transform_fecundity)
qqnorm(boxcoxtransformonlypotswithsurvivingseedsMHP$boxcox_transform_fecundity)
qqnorm(boxcoxtransformonlypotswithsurvivingseedsTLP$boxcox_transform_fecundity)
qqnorm(boxcoxtransformonlypotswithsurvivingseedsTHP$boxcox_transform_fecundity)
ggplot(data = boxcoxtransformonlypotswithsurvivingseedsMLO, mapping = aes(x = boxcox_transform_fecundity)) +
xlab("Transformed fecundity") +
geom_histogram() +
theme_classic(base_size = 18)
ggplot(data = boxcoxtransformonlypotswithsurvivingseedsMHO, mapping = aes(x = boxcox_transform_fecundity)) +
xlab("Transformed fecundity") +
geom_histogram() +
theme_classic(base_size = 18)
ggplot(data = boxcoxtransformonlypotswithsurvivingseedsTLO, mapping = aes(x = boxcox_transform_fecundity)) +
xlab("Transformed fecundity") +
geom_histogram() +
theme_classic(base_size = 18)
ggplot(data = boxcoxtransformonlypotswithsurvivingseedsTHO, mapping = aes(x = boxcox_transform_fecundity)) +
xlab("Transformed fecundity") +
geom_histogram() +
theme_classic(base_size = 18)
ggplot(data = boxcoxtransformonlypotswithsurvivingseedsMLP, mapping = aes(x = boxcox_transform_fecundity)) +
xlab("Transformed fecundity") +
geom_histogram() +
theme_classic(base_size = 18)
ggplot(data = boxcoxtransformonlypotswithsurvivingseedsMHP, mapping = aes(x = boxcox_transform_fecundity)) +
xlab("Transformed fecundity") +
geom_histogram() +
theme_classic(base_size = 18)
ggplot(data = boxcoxtransformonlypotswithsurvivingseedsTLP, mapping = aes(x = boxcox_transform_fecundity)) +
xlab("Transformed fecundity") +
geom_histogram() +
theme_classic(base_size = 18)
ggplot(data = boxcoxtransformonlypotswithsurvivingseedsTHP, mapping = aes(x = boxcox_transform_fecundity)) +
xlab("Transformed fecundity") +
geom_histogram() +
theme_classic(base_size = 18)
#Following data frames are to perform a statistical test for significance
#on the relationship between reproductive excess and proportion of deaths selective
#across environmental conditions.
#It will also be used to create a scatter plot of this relationship.
scatterplotlowdensitydeathsdataframe <- data.frame(
environmental_condition = c("MLI", "MHI", "TLI", "THI"),
reproductive_excess_fecundity_low = c(reproductive_excess_fecundity_lowdispersal_MLO, reproductive_excess_fecundity_lowdispersal_MHO, reproductive_excess_fecundity_lowdispersal_TLO, reproductive_excess_fecundity_lowdispersal_THO),
reproductive_excess_fecundity_high = c(reproductive_excess_fecundity_highdispersal_MLO, reproductive_excess_fecundity_highdispersal_MHO, reproductive_excess_fecundity_highdispersal_TLO, reproductive_excess_fecundity_highdispersal_THO),
reproductive_excess_survival_low = c(reproductive_excess_survival_lowdispersal_MLO, reproductive_excess_survival_lowdispersal_MHO, reproductive_excess_survival_lowdispersal_TLO, reproductive_excess_survival_lowdispersal_THO),
reproductive_excess_survival_high = c(reproductive_excess_survival_highdispersal_MLO, reproductive_excess_survival_highdispersal_MHO, reproductive_excess_survival_highdispersal_TLO, reproductive_excess_survival_highdispersal_THO),
proportion_of_deaths_selective = c(proportion_deaths_selective_deaths_MLO, proportion_deaths_selective_deaths_MHO, proportion_deaths_selective_deaths_TLO, proportion_deaths_selective_deaths_THO)
)
scatterplothighdensitydeathsdataframe <- data.frame(
environmental_condition = c("MLP", "MHP", "TLP", "THP"),
reproductive_excess_fecundity_low = c(reproductive_excess_fecundity_lowdispersal_MLP, reproductive_excess_fecundity_lowdispersal_MHP, reproductive_excess_fecundity_lowdispersal_TLP, reproductive_excess_fecundity_lowdispersal_THP),
reproductive_excess_fecundity_high = c(reproductive_excess_fecundity_highdispersal_MLP, reproductive_excess_fecundity_highdispersal_MHP, reproductive_excess_fecundity_highdispersal_TLP, reproductive_excess_fecundity_highdispersal_THP),
reproductive_excess_survival_low = c(reproductive_excess_survival_lowdispersal_MLP, reproductive_excess_survival_lowdispersal_MHP, reproductive_excess_survival_lowdispersal_TLP, reproductive_excess_survival_lowdispersal_THP),
reproductive_excess_survival_high = c(reproductive_excess_survival_highdispersal_MLP, reproductive_excess_survival_highdispersal_MHP, reproductive_excess_survival_highdispersal_TLP, reproductive_excess_survival_highdispersal_THP),
proportion_of_deaths_selective = c(proportion_deaths_selective_deaths_MLP, proportion_deaths_selective_deaths_MHP, proportion_deaths_selective_deaths_TLP, proportion_deaths_selective_deaths_THP)
)
cor.test(scatterplothighdensitydeathsdataframe$reproductive_excess, scatterplothighdensitydeathsdataframe$proportion_of_deaths_selective, method = "spearman")
cor.test(scatterplotlowdensitydeathsdataframe$reproductive_excess, scatterplotlowdensitydeathsdataframe$proportion_of_deaths_selective, method = "spearman")
pvaluesexcessvspropdeathsselective <- c(0.4167, 0.08333)
pchisq(-2*sum(log(pvaluesexcessvspropdeathsselective)), 6, lower.tail = FALSE)
#PLOTS
#Following plots show standard deviation and mean in seed production
#OMITTED POTS WITH NO SURVIVING SEEDS AND GENOTYPES WITH NO VARIANCE
stdevvsmeanplotMLO <- ggplot(data = onlysurvivingseedsnozeroesinvarianceMLO, mapping = aes(x = Mean, y = StDev)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
theme_classic(base_size = 15)
stdevvsmeanplotMLP <- ggplot(data = onlysurvivingseedsnozeroesinvarianceMLP, mapping = aes(x = Mean, y = StDev)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
theme_classic(base_size = 15)
stdevvsmeanplotMHO <- ggplot(data = onlysurvivingseedsnozeroesinvarianceMHO, mapping = aes(x = Mean, y = StDev)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
theme_classic(base_size = 15)
stdevvsmeanplotMHP <- ggplot(data = onlysurvivingseedsnozeroesinvarianceMHP, mapping = aes(x = Mean, y = StDev)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
theme_classic(base_size = 15)
stdevvsmeanplotTLO <- ggplot(data = onlysurvivingseedsnozeroesinvarianceTLO, mapping = aes(x = Mean, y = StDev)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
theme_classic(base_size = 15)
stdevvsmeanplotTLP <- ggplot(data = onlysurvivingseedsnozeroesinvarianceTLP, mapping = aes(x = Mean, y = StDev)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
theme_classic(base_size = 15)
stdevvsmeanplotTHO <- ggplot(data = onlysurvivingseedsnozeroesinvarianceTHO, mapping = aes(x = Mean, y = StDev)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
theme_classic(base_size = 15)
stdevvsmeanplotTHP <- ggplot(data = onlysurvivingseedsnozeroesinvarianceTHP, mapping = aes(x = Mean, y = StDev)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE) +
theme_classic(base_size = 15)
stdevvsmeanplotMLO
stdevvsmeanplotMLP
stdevvsmeanplotMHO
stdevvsmeanplotMHP
stdevvsmeanplotTLO
stdevvsmeanplotTLP
stdevvsmeanplotTHO
stdevvsmeanplotTHP
genotypemeanseedproductionhistMLO <- ggplot(data = aggregatedonlysurvivingseedsnozeroesinvarianceMLO, aes(x = Seeds_by_ind)) +
geom_histogram() +
xlab("Genotype mean seed production") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 12000, y = 40, label = "MLI", size = 8)
genotypemeanseedproductionhistMLP <- ggplot(data = aggregatedonlysurvivingseedsnozeroesinvarianceMLP, aes(x = Seeds_by_ind)) +
geom_histogram() +
xlab("Genotype mean seed production") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 4000, y = 4, label = "MLP", size = 8)
genotypemeanseedproductionhistMHO <- ggplot(data = aggregatedonlysurvivingseedsnozeroesinvarianceMHO, aes(x = Seeds_by_ind)) +
geom_histogram() +
xlab("Genotype mean seed production") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 25000, y = 40, label = "MHI", size = 8)
genotypemeanseedproductionhistMHP <- ggplot(data = aggregatedonlysurvivingseedsnozeroesinvarianceMHP, aes(x = Seeds_by_ind)) +
geom_histogram() +
xlab("Genotype mean seed production") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 20000, y = 40, label = "MHP", size = 8)
genotypemeanseedproductionhistTLO <- ggplot(data = aggregatedonlysurvivingseedsnozeroesinvarianceTLO, aes(x = Seeds_by_ind)) +
geom_histogram() +
xlab("Genotype mean seed production") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 9000, y = 40, label = "TLI", size = 8)
genotypemeanseedproductionhistTLP <- ggplot(data = aggregatedonlysurvivingseedsnozeroesinvarianceTLP, aes(x = Seeds_by_ind)) +
geom_histogram() +
xlab("Genotype mean seed production") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 2500, y = 40, label = "TLP", size = 8)
genotypemeanseedproductionhistTHO <- ggplot(data = aggregatedonlysurvivingseedsnozeroesinvarianceTHO, aes(x = Seeds_by_ind)) +
geom_histogram() +
xlab("Genotype mean seed production") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 16000, y = 40, label = "THI", size = 8)
genotypemeanseedproductionhistTHP <- ggplot(data = aggregatedonlysurvivingseedsnozeroesinvarianceTHP, aes(x = Seeds_by_ind)) +
geom_histogram() +
xlab("Genotype mean seed production") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 6000, y = 150, label = "THP", size = 8)
genotypemeanseedproductionhistMLO
genotypemeanseedproductionhistMLP
genotypemeanseedproductionhistMHO
genotypemeanseedproductionhistMHP
genotypemeanseedproductionhistTLO
genotypemeanseedproductionhistTLP
genotypemeanseedproductionhistTHO
genotypemeanseedproductionhistTHP
genotypemeanseedsurvivalhistMLO <- ggplot(data = survivalselectivedeathsMLO, aes(x = (1 - Genotype_death_rate))) +
geom_histogram() +
xlab("Genotype mean seed survival") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 0.8, y = 80, label = "MLI", size = 8)
genotypemeanseedsurvivalhistMLP <- ggplot(data = survivalselectivedeathsMLP, aes(x = (1 - Genotype_death_rate))) +
geom_histogram() +
xlab("Genotype mean seed survival") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 0.8, y = 300, label = "MLP", size = 8)
genotypemeanseedsurvivalhistMHO <- ggplot(data = survivalselectivedeathsMHO, aes(x = (1 - Genotype_death_rate))) +
geom_histogram() +
xlab("Genotype mean seed survival") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 0.8, y = 280, label = "MHI", size = 8)
genotypemeanseedsurvivalhistMHP <- ggplot(data = survivalselectivedeathsMHP, aes(x = (1 - Genotype_death_rate))) +
geom_histogram() +
xlab("Genotype mean seed survival") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 0.8, y = 40, label = "MHP", size = 8)
genotypemeanseedsurvivalhistTLO <- ggplot(data = survivalselectivedeathsTLO, aes(x = (1 - Genotype_death_rate))) +
geom_histogram() +
xlab("Genotype mean seed survival") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 0.8, y = 120, label = "TLI", size = 8)
genotypemeanseedsurvivalhistTLP <- ggplot(data = survivalselectivedeathsTLP, aes(x = (1 - Genotype_death_rate))) +
geom_histogram() +
xlab("Genotype mean seed survival") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 0.7, y = 100, label = "TLP", size = 8)
genotypemeanseedsurvivalhistTHO <- ggplot(data = survivalselectivedeathsTHO, aes(x = (1 - Genotype_death_rate))) +
geom_histogram() +
xlab("Genotype mean seed survival") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 0.7, y = 180, label = "THI", size = 8)
genotypemeanseedsurvivalhistTHP <- ggplot(data = survivalselectivedeathsTHP, aes(x = (1 - Genotype_death_rate))) +
geom_histogram() +
xlab("Genotype mean seed survival") +
ylab("Count") +
theme_classic(base_size = 15) +
annotate("text", x = 0.8, y = 40, label = "THP", size = 8)
genotypemeanseedsurvivalhistMLO
genotypemeanseedsurvivalhistMLP
genotypemeanseedsurvivalhistMHO
genotypemeanseedsurvivalhistMHP
genotypemeanseedsurvivalhistTLO
genotypemeanseedsurvivalhistTLP
genotypemeanseedsurvivalhistTHO
genotypemeanseedsurvivalhistTHP
#Following lines are only to visualize proportion of deaths selective
#and minimum reproductive excess required in a model similar to
#Desai and Fisher 2007
#the following is the transcendental equation for q,
#expressed as a function where the equation is true at 0
#so I can use uniroot to solve it later
qfunction = function(q, s, N, U) {q - (2*log(N*q*s)) / (log((s/U)*((q-1)*sin(pi/q)/pi*exp(pi/q))))}
qapproximatefunction = function(s, N, U) {2*log(N*s) / log(s/U)}
xvaluesfors <- c(0.0035, 0.005, 0.0075, 0.01, 0.02, 0.035, 0.05, 0.075, 0.1, 0.125, 0.15, 0.2, 0.25)
xvaluesforN <- c(100000, 200000, 350000, 500000, 750000, 1000000, 2000000, 3500000, 5000000, 7500000, 10000000)
xvaluesforU <- c(0.0001, 0.0002, 0.00035, 0.0005, 0.00075, 0.001, 0.002, 0.0025)
approximateqvaluesfors <- c(1:13)
approximateqvaluesforN <- c(1:11)
approximateqvaluesforU <- c(1:8)
for (i in 1:length(approximateqvaluesfors)) {
approximateqvaluesfors[i] <- qapproximatefunction(xvaluesfors[i], 10^6, 0.001)
}
for (i in 1:length(approximateqvaluesforN)) {