Notes

Packages

library("dplyr")
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library("ggplot2")
library(ggmosaic)
library("lme4")
## Loading required package: Matrix
library("scales")
library("car")
## Loading required package: carData
## 
## Attaching package: 'car'
## The following object is masked from 'package:dplyr':
## 
##     recode
library("optimx")
library(emmeans)
library(ggsci)
library(lmerTest)
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
library(tidyr)
## 
## Attaching package: 'tidyr'
## The following objects are masked from 'package:Matrix':
## 
##     expand, pack, unpack
library(survival)
library(coxme)
## Loading required package: bdsmatrix
## 
## Attaching package: 'bdsmatrix'
## The following object is masked from 'package:base':
## 
##     backsolve
library(ggpubr)
library(survminer)
## 
## Attaching package: 'survminer'
## The following object is masked from 'package:survival':
## 
##     myeloma
library(viridis)
## Loading required package: viridisLite
## 
## Attaching package: 'viridis'
## The following object is masked from 'package:scales':
## 
##     viridis_pal
mate_fight <- read.csv("mate.fight.csv", fileEncoding="UTF-8-BOM")
str(mate_fight)
## 'data.frame':    324 obs. of  32 variables:
##  $ grp           : int  2 2 2 2 2 2 3 3 3 3 ...
##  $ Experiment    : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ morph         : chr  "F" "F" "F" "F" ...
##  $ trmnt_type    : chr  "FF" "FF" "FF" "FF" ...
##  $ competitor    : chr  "F" "F" "F" "F" ...
##  $ trmt          : int  75 73 73 74 74 75 2 3 3 1 ...
##  $ mate          : int  1 1 1 0 0 0 1 1 1 0 ...
##  $ mate.order    : int  1 1 2 0 0 0 1 1 2 0 ...
##  $ times.mated   : int  1 2 2 NA NA NA 1 2 2 NA ...
##  $ time.mate     : int  2426 646 1313 NA NA NA 918 909 2224 NA ...
##  $ fight         : int  1 1 1 1 1 1 0 1 1 0 ...
##  $ morph.fight   : chr  "FF" "FF" "FF" "FF" ...
##  $ fight.fight   : chr  "F" "F" "F" "F" ...
##  $ comp.fight    : chr  "F" "F" "F" "F" ...
##  $ time.fight    : int  4530 2033 2033 2044 2044 4530 NA 909 909 NA ...
##  $ mating.fight  : int  1 1 1 0 0 1 NA 1 1 NA ...
##  $ mate.rhodamine: int  0 1 0 NA NA NA 1 0 0 NA ...
##  $ week1         : int  0 59 59 NA NA NA 0 116 116 NA ...
##  $ week2         : int  0 106 106 NA NA NA 0 94 94 NA ...
##  $ week3         : int  25 7 7 NA NA NA NA 38 38 NA ...
##  $ week4         : int  55 NA NA NA NA NA NA NA NA NA ...
##  $ week5         : int  20 NA NA NA NA NA NA NA NA NA ...
##  $ week6         : int  0 NA NA NA NA NA NA NA NA NA ...
##  $ week7         : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ week8         : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ week9         : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ week10        : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ week.11       : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ week.12       : int  NA NA NA NA NA NA NA NA NA NA ...
##  $ long          : int  42 21 21 14 14 42 14 21 21 14 ...
##  $ total         : int  100 172 172 NA NA NA 0 248 248 NA ...
##  $ total.NA      : int  100 172 172 0 0 0 0 248 248 0 ...

Fighting

1. Does fighting precede mating?

If +ve then fighting first, if -ve then mating first

fight_over_mating <- mate_fight %>%
  replace(is.na(.), 0) %>%
  mutate(preceed = time.fight-time.mate) %>%
  mutate(preced2 = case_when(preceed<=0 ~ "1", preceed>=0 ~"0")) %>%
  mutate(preced3=as.numeric(preced2))

str(fight_over_mating)
## 'data.frame':    324 obs. of  35 variables:
##  $ grp           : int  2 2 2 2 2 2 3 3 3 3 ...
##  $ Experiment    : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ morph         : chr  "F" "F" "F" "F" ...
##  $ trmnt_type    : chr  "FF" "FF" "FF" "FF" ...
##  $ competitor    : chr  "F" "F" "F" "F" ...
##  $ trmt          : int  75 73 73 74 74 75 2 3 3 1 ...
##  $ mate          : int  1 1 1 0 0 0 1 1 1 0 ...
##  $ mate.order    : num  1 1 2 0 0 0 1 1 2 0 ...
##  $ times.mated   : num  1 2 2 0 0 0 1 2 2 0 ...
##  $ time.mate     : num  2426 646 1313 0 0 ...
##  $ fight         : int  1 1 1 1 1 1 0 1 1 0 ...
##  $ morph.fight   : chr  "FF" "FF" "FF" "FF" ...
##  $ fight.fight   : chr  "F" "F" "F" "F" ...
##  $ comp.fight    : chr  "F" "F" "F" "F" ...
##  $ time.fight    : num  4530 2033 2033 2044 2044 ...
##  $ mating.fight  : num  1 1 1 0 0 1 0 1 1 0 ...
##  $ mate.rhodamine: num  0 1 0 0 0 0 1 0 0 0 ...
##  $ week1         : num  0 59 59 0 0 0 0 116 116 0 ...
##  $ week2         : num  0 106 106 0 0 0 0 94 94 0 ...
##  $ week3         : num  25 7 7 0 0 0 0 38 38 0 ...
##  $ week4         : num  55 0 0 0 0 0 0 0 0 0 ...
##  $ week5         : num  20 0 0 0 0 0 0 0 0 0 ...
##  $ week6         : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ week7         : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ week8         : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ week9         : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ week10        : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ week.11       : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ week.12       : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ long          : num  42 21 21 14 14 42 14 21 21 14 ...
##  $ total         : num  100 172 172 0 0 0 0 248 248 0 ...
##  $ total.NA      : int  100 172 172 0 0 0 0 248 248 0 ...
##  $ preceed       : num  2104 1387 720 2044 2044 ...
##  $ preced2       : chr  "0" "0" "0" "0" ...
##  $ preced3       : num  0 0 0 0 0 0 1 1 1 1 ...

Graph

ggplot(fight_over_mating, aes(trmnt_type,preceed, fill=trmnt_type)) + geom_boxplot() + theme_classic() + theme(legend.position="none")+ scale_fill_nejm() + ylab("Fighting-Mating") + scale_x_discrete(limits=c("FFF", "FFS", "FSS", "SSS", "SS", "FF", "FS")) + theme(legend.title=element_blank()) + xlab("Treatment Type")

Model

preceed_mod2 <- glmer(preced3~morph*competitor + (1|trmt), family="binomial", data=fight_over_mating)
Anova(preceed_mod2)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: preced3
##                   Chisq Df Pr(>Chisq)  
## morph            6.1306  1    0.01329 *
## competitor       0.9287  4    0.92041  
## morph:competitor 8.3473  4    0.07965 .
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
preceed.grid <- ref_grid(preceed_mod2)

emmeans(regrid(preceed.grid), pairwise~morph|competitor)
## $emmeans
## competitor = F:
##  morph  prob     SE  df asymp.LCL asymp.UCL
##  F     0.441 0.0891 Inf    0.2668     0.616
##  S     0.843 0.0871 Inf    0.6722     1.014
## 
## competitor = FF:
##  morph  prob     SE  df asymp.LCL asymp.UCL
##  F     0.520 0.0747 Inf    0.3731     0.666
##  S     0.674 0.1152 Inf    0.4486     0.900
## 
## competitor = FS:
##  morph  prob     SE  df asymp.LCL asymp.UCL
##  F     0.588 0.0881 Inf    0.4149     0.760
##  S     0.587 0.0881 Inf    0.4149     0.760
## 
## competitor = S:
##  morph  prob     SE  df asymp.LCL asymp.UCL
##  F     0.675 0.1153 Inf    0.4487     0.901
##  S     0.646 0.0855 Inf    0.4781     0.813
## 
## competitor = SS:
##  morph  prob     SE  df asymp.LCL asymp.UCL
##  F     0.269 0.1082 Inf    0.0567     0.481
##  S     0.674 0.0698 Inf    0.5375     0.811
## 
## Confidence level used: 0.95 
## 
## $contrasts
## competitor = F:
##  contrast  estimate    SE  df z.ratio p.value
##  F - S    -0.401460 0.125 Inf  -3.210  0.0013
## 
## competitor = FF:
##  contrast  estimate    SE  df z.ratio p.value
##  F - S    -0.154783 0.137 Inf  -1.128  0.2592
## 
## competitor = FS:
##  contrast  estimate    SE  df z.ratio p.value
##  F - S     0.000115 0.124 Inf   0.001  0.9993
## 
## competitor = S:
##  contrast  estimate    SE  df z.ratio p.value
##  F - S     0.028853 0.143 Inf   0.202  0.8399
## 
## competitor = SS:
##  contrast  estimate    SE  df z.ratio p.value
##  F - S    -0.405474 0.130 Inf  -3.125  0.0018
preced.graph <- emmip(preceed.grid, morph~competitor, CIs=TRUE, type = "response", style = "factor", plotit = FALSE)

fight_likely <- ggplot(preced.graph, aes(x=competitor, y=yvar, col=morph)) + theme_classic() + geom_pointrange(aes(ymin=yvar-SE, ymax=yvar+SE), position="jitter") + scale_color_viridis(discrete=TRUE) + ylab("Likelihood to Fight First then Mate") + xlab("Rivals") + theme(legend.position = "none", text = element_text(size = 15)) + scale_x_discrete(limits=c("FF", "FS", "SS", "S", "F"))

2. Does timing of fight differ between morph and competitor?

fight_time <- lm(time.fight~morph*competitor + trmt, contrast=list(morph=contr.sum, competitor=contr.sum), data=mate_fight) #need to have trmt in as covariate
Anova(fight_time, type=2)
## Anova Table (Type II tests)
## 
## Response: time.fight
##                     Sum Sq  Df F value   Pr(>F)   
## morph                 5815   1  0.0030 0.956543   
## competitor        17957567   4  2.2991 0.060804 . 
## trmt              18374413   1  9.4100 0.002505 **
## morph:competitor  24578151   4  3.1468 0.015789 * 
## Residuals        337808221 173                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
emmeans(fight_time, pairwise~competitor|morph)
## $emmeans
## morph = F:
##  competitor emmean  SE  df lower.CL upper.CL
##  F            2235 361 173     1523     2947
##  FF           2513 281 173     1959     3067
##  FS           3014 356 173     2312     3717
##  S            1241 533 173      190     2292
##  SS           2150 378 173     1404     2896
## 
## morph = S:
##  competitor emmean  SE  df lower.CL upper.CL
##  F            1241 533 173      190     2292
##  FF           3329 477 173     2388     4271
##  FS           2054 334 173     1396     2713
##  S            1365 382 173      610     2119
##  SS           2917 264 173     2396     3438
## 
## Confidence level used: 0.95 
## 
## $contrasts
## morph = F:
##  contrast estimate  SE  df t.ratio p.value
##  F - FF     -277.8 516 173  -0.539  0.9831
##  F - FS     -778.8 549 173  -1.420  0.6159
##  F - S       994.6 577 173   1.724  0.4221
##  F - SS       85.3 545 173   0.157  0.9999
##  FF - FS    -501.0 418 173  -1.198  0.7528
##  FF - S     1272.4 647 173   1.968  0.2861
##  FF - SS     363.1 453 173   0.802  0.9298
##  FS - S     1773.4 673 173   2.633  0.0688
##  FS - SS     864.1 507 173   1.705  0.4335
##  S - SS     -909.3 671 173  -1.356  0.6568
## 
## morph = S:
##  contrast estimate  SE  df t.ratio p.value
##  F - FF    -2088.3 743 173  -2.811  0.0433
##  F - FS     -813.5 657 173  -1.238  0.7289
##  F - S      -123.6 578 173  -0.214  0.9995
##  F - SS    -1676.0 625 173  -2.684  0.0605
##  FF - FS    1274.7 566 173   2.254  0.1652
##  FF - S     1964.6 650 173   3.021  0.0239
##  FF - SS     412.3 527 173   0.782  0.9356
##  FS - S      689.9 549 173   1.256  0.7181
##  FS - SS    -862.5 405 173  -2.131  0.2117
##  S - SS    -1552.4 510 173  -3.044  0.0224
## 
## P value adjustment: tukey method for comparing a family of 5 estimates
timefight.graph <- emmip(fight_time, morph~competitor, CIs=TRUE, type = "response", style = "factor", plotit = FALSE)

timetofight <- ggplot(timefight.graph, aes(x=competitor, y=yvar, col=morph)) + theme_classic() + geom_pointrange(aes(ymin=yvar-SE, ymax=yvar+SE), position="jitter") + scale_color_viridis(discrete=TRUE, labels=c("Focal Fighter Male", "Focal Scrambler Male")) + ylab("Time to Initiate Fight (sec)") + xlab("Rivals") + theme(legend.position = "bottom",legend.title=element_blank(), text = element_text(size = 15))+ scale_x_discrete(limits=c("FF", "FS", "SS", "S", "F"))

ggarrange(fight_likely, timetofight, ncol=1, labels=c("A", "B"))

emmeans(fight_time, pairwise~competitor)
## NOTE: Results may be misleading due to involvement in interactions
## $emmeans
##  competitor emmean  SE  df lower.CL upper.CL
##  F            1738 352 173     1044     2432
##  FF           2921 289 173     2350     3492
##  FS           2534 254 173     2033     3036
##  S            1303 362 173      588     2018
##  SS           2534 236 173     2067     3000
## 
## Results are averaged over the levels of: morph 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast estimate  SE  df t.ratio p.value
##  F - FF   -1183.05 506 173  -2.337  0.1382
##  F - FS    -796.18 478 173  -1.666  0.4580
##  F - S      435.46 408 173   1.066  0.8235
##  F - SS    -795.35 458 173  -1.736  0.4149
##  FF - FS    386.87 352 173   1.099  0.8068
##  FF - S    1618.51 518 173   3.125  0.0175
##  FF - SS    387.70 348 173   1.113  0.7993
##  FS - S    1231.65 490 173   2.516  0.0919
##  FS - SS      0.83 324 173   0.003  1.0000
##  S - SS   -1230.82 469 173  -2.622  0.0707
## 
## Results are averaged over the levels of: morph 
## P value adjustment: tukey method for comparing a family of 5 estimates

Graph

ggplot(mate_fight, aes(competitor,time.fight, fill=morph)) + geom_boxplot() + theme_classic() + scale_fill_nejm() + xlab("Competitor Morph")+ scale_x_discrete(limits=c("FF", "FS", "SS", "S", "F")) + ylab("Time of Fight") + theme(legend.position="bottom")
## Warning: Removed 140 rows containing non-finite values (`stat_boxplot()`).

3. Who fights more depending on competitors?

who_fight <- glmer(fight~morph*competitor + (1|trmt), family="binomial", contrast=list(morph=contr.sum, competitor=contr.sum), data=mate_fight)
Anova(who_fight, type=2)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: fight
##                   Chisq Df Pr(>Chisq)
## morph            0.5207  1     0.4706
## competitor       3.0125  4     0.5557
## morph:competitor 4.3307  4     0.3631
fight.grid <- ref_grid(who_fight)

emmeans(regrid(fight.grid), pairwise~morph|competitor)
## $emmeans
## competitor = F:
##  morph  prob     SE  df asymp.LCL asymp.UCL
##  F     0.633 0.1001 Inf     0.437     0.829
##  S     0.433 0.1377 Inf     0.163     0.703
## 
## competitor = FF:
##  morph  prob     SE  df asymp.LCL asymp.UCL
##  F     0.627 0.0851 Inf     0.460     0.793
##  S     0.499 0.1375 Inf     0.229     0.768
## 
## competitor = FS:
##  morph  prob     SE  df asymp.LCL asymp.UCL
##  F     0.466 0.1034 Inf     0.263     0.669
##  S     0.531 0.1031 Inf     0.329     0.733
## 
## competitor = S:
##  morph  prob     SE  df asymp.LCL asymp.UCL
##  F     0.433 0.1377 Inf     0.163     0.703
##  S     0.633 0.1001 Inf     0.437     0.829
## 
## competitor = SS:
##  morph  prob     SE  df asymp.LCL asymp.UCL
##  F     0.806 0.0993 Inf     0.612     1.001
##  S     0.607 0.0867 Inf     0.437     0.776
## 
## Confidence level used: 0.95 
## 
## $contrasts
## competitor = F:
##  contrast estimate    SE  df z.ratio p.value
##  F - S      0.1998 0.171 Inf   1.170  0.2420
## 
## competitor = FF:
##  contrast estimate    SE  df z.ratio p.value
##  F - S      0.1281 0.162 Inf   0.792  0.4285
## 
## competitor = FS:
##  contrast estimate    SE  df z.ratio p.value
##  F - S     -0.0651 0.146 Inf  -0.445  0.6560
## 
## competitor = S:
##  contrast estimate    SE  df z.ratio p.value
##  F - S     -0.1997 0.171 Inf  -1.170  0.2420
## 
## competitor = SS:
##  contrast estimate    SE  df z.ratio p.value
##  F - S      0.1997 0.131 Inf   1.522  0.1279
emmeans(regrid(fight.grid), pairwise~competitor|morph)
## $emmeans
## morph = F:
##  competitor  prob     SE  df asymp.LCL asymp.UCL
##  F          0.633 0.1001 Inf     0.437     0.829
##  FF         0.627 0.0851 Inf     0.460     0.793
##  FS         0.466 0.1034 Inf     0.263     0.669
##  S          0.433 0.1377 Inf     0.163     0.703
##  SS         0.806 0.0993 Inf     0.612     1.001
## 
## morph = S:
##  competitor  prob     SE  df asymp.LCL asymp.UCL
##  F          0.433 0.1377 Inf     0.163     0.703
##  FF         0.499 0.1375 Inf     0.229     0.768
##  FS         0.531 0.1031 Inf     0.329     0.733
##  S          0.633 0.1001 Inf     0.437     0.829
##  SS         0.607 0.0867 Inf     0.437     0.776
## 
## Confidence level used: 0.95 
## 
## $contrasts
## morph = F:
##  contrast estimate    SE  df z.ratio p.value
##  F - FF    0.00618 0.131 Inf   0.047  1.0000
##  F - FS    0.16696 0.144 Inf   1.157  0.7758
##  F - S     0.19975 0.171 Inf   1.170  0.7686
##  F - SS   -0.17339 0.140 Inf  -1.240  0.7277
##  FF - FS   0.16078 0.134 Inf   1.198  0.7524
##  FF - S    0.19357 0.162 Inf   1.194  0.7551
##  FF - SS  -0.17957 0.130 Inf  -1.380  0.6403
##  FS - S    0.03279 0.172 Inf   0.191  0.9997
##  FS - SS  -0.34035 0.144 Inf  -2.367  0.1243
##  S - SS   -0.37314 0.170 Inf  -2.191  0.1829
## 
## morph = S:
##  contrast estimate    SE  df z.ratio p.value
##  F - FF   -0.06547 0.195 Inf  -0.337  0.9972
##  F - FS   -0.09785 0.172 Inf  -0.569  0.9796
##  F - S    -0.19975 0.171 Inf  -1.170  0.7686
##  F - SS   -0.17346 0.163 Inf  -1.064  0.8249
##  FF - FS  -0.03238 0.172 Inf  -0.188  0.9997
##  FF - S   -0.13428 0.170 Inf  -0.789  0.9339
##  FF - SS  -0.10799 0.163 Inf  -0.664  0.9640
##  FS - S   -0.10190 0.144 Inf  -0.709  0.9544
##  FS - SS  -0.07561 0.135 Inf  -0.561  0.9805
##  S - SS    0.02629 0.132 Inf   0.199  0.9996
## 
## P value adjustment: tukey method for comparing a family of 5 estimates
num_fights <- mate_fight %>%
  count(fight)

num_fight_trmnt <- mate_fight %>%
  group_by(trmnt_type, morph.fight) %>%
  count(fight)

Mating

1. Likelihood of mating

mate_likely <- glm(mate~morph*competitor + trmt, family="binomial",contrast=list(morph=contr.sum, competitor=contr.sum), data=mate_fight)
Anova(mate_likely)
## Analysis of Deviance Table (Type II tests)
## 
## Response: mate
##                  LR Chisq Df Pr(>Chisq)  
## morph              4.2987  1    0.03814 *
## competitor         1.8284  4    0.76728  
## trmt               0.2885  1    0.59116  
## morph:competitor   1.8498  4    0.76335  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
likely.grid <- ref_grid(mate_likely)

emmeans(regrid(likely.grid), pairwise~morph)
## NOTE: Results may be misleading due to involvement in interactions
## $emmeans
##  morph  prob     SE  df asymp.LCL asymp.UCL
##  F     0.394 0.0419 Inf     0.312     0.476
##  S     0.519 0.0437 Inf     0.434     0.605
## 
## Results are averaged over the levels of: competitor 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast estimate     SE  df z.ratio p.value
##  F - S      -0.125 0.0596 Inf  -2.102  0.0356
## 
## Results are averaged over the levels of: competitor
many_mates <- mate_fight %>%
  count(mate)

many_mates_trmnt <- mate_fight %>%
  group_by(trmnt_type, morph) %>%
  count(mate)

2. Time to mate

timing_mating <- lm(time.mate~morph*competitor + trmt, data=mate_fight)
Anova(timing_mating, type=2)
## Anova Table (Type II tests)
## 
## Response: time.mate
##                     Sum Sq  Df F value Pr(>F)
## morph               980279   1  0.2988 0.5855
## competitor        11639527   4  0.8871 0.4736
## trmt               3079223   1  0.9387 0.3343
## morph:competitor   7650745   4  0.5831 0.6754
## Residuals        442832358 135
timemate.graph <- emmip(timing_mating, morph~competitor, CIs=TRUE, type = "response", style = "factor", plotit = FALSE)

ggplot(timemate.graph, aes(x=competitor, y=yvar, col=morph)) + theme_classic() + geom_pointrange(aes(ymin=yvar-SE, ymax=yvar+SE), position="jitter") + scale_color_viridis(discrete=TRUE, labels=c("Focal Fighter Male", "Focal Scrambler Male")) + ylab("Time to Initiate Mating (sec)") + xlab("Rivals") + theme(legend.position = "bottom",legend.title=element_blank(),text = element_text(size = 15)) + scale_x_discrete(limits=c("FF", "FS", "SS", "S", "F"))

Graph

ggplot(mate_fight, aes(competitor, time.mate, fill=morph)) + geom_boxplot() + theme_classic()+ scale_fill_nejm() + xlab("Competitor Morph")+ scale_x_discrete(limits=c("FF", "FS", "SS", "S", "F")) + ylab("Time of Mating") + theme(legend.position="bottom")
## Warning: Removed 178 rows containing non-finite values (`stat_boxplot()`).

Male Fitness: total egg count and longevity

Total egg count/number of matings

  • majority of fitness is 0
fit_mod <- lmer(fitness.NA~competitor*morph + (1|trmt) + mate.rhodamine, contrast=list(morph=contr.sum, competitor=contr.sum), data=fit)
Anova(fit_mod)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: fitness.NA
##                   Chisq Df Pr(>Chisq)  
## competitor       3.3387  4    0.50282  
## morph            2.7240  1    0.09885 .
## mate.rhodamine   0.0000  1    0.99778  
## competitor:morph 3.3353  4    0.50336  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
emmeans(fit_mod, pairwise~competitor|morph)
## $emmeans
## morph = F:
##  competitor emmean   SE   df lower.CL upper.CL
##  F            58.7 16.2 96.1   26.419     90.9
##  FF           38.3 15.6 96.0    7.378     69.3
##  FS           26.2 13.7 96.5   -0.884     53.3
##  S            45.0 15.6 96.8   13.981     76.0
##  SS           41.8 14.2 99.1   13.679     69.9
## 
## morph = S:
##  competitor emmean   SE   df lower.CL upper.CL
##  F            45.0 15.6 96.8   13.946     76.0
##  FF           26.3 13.7 97.2   -0.900     53.4
##  FS           42.0 14.1 96.5   14.019     69.9
##  S            15.4 15.0 96.0  -14.442     45.2
##  SS           17.0 13.3 95.9   -9.333     43.3
## 
## Results are averaged over the levels of: mate.rhodamine 
## Degrees-of-freedom method: kenward-roger 
## Confidence level used: 0.95 
## 
## $contrasts
## morph = F:
##  contrast estimate   SE   df t.ratio p.value
##  F - FF      20.31 22.5 96.0   0.902  0.8954
##  F - FS      32.43 21.2 96.2   1.528  0.5468
##  F - S       13.65 22.5 96.4   0.606  0.9739
##  F - SS      16.85 21.6 97.3   0.782  0.9353
##  FF - FS     12.12 20.7 96.2   0.584  0.9771
##  FF - S      -6.67 22.1 96.4  -0.302  0.9982
##  FF - SS     -3.46 21.1 97.4  -0.164  0.9998
##  FS - S     -18.78 20.8 96.6  -0.905  0.8944
##  FS - SS    -15.58 19.7 97.8  -0.791  0.9326
##  S - SS       3.21 21.1 97.8   0.152  0.9999
## 
## morph = S:
##  contrast estimate   SE   df t.ratio p.value
##  F - FF      18.72 20.8 96.9   0.901  0.8958
##  F - FS       3.01 21.0 96.6   0.143  0.9999
##  F - S       29.58 21.7 96.4   1.364  0.6519
##  F - SS      28.00 20.5 96.4   1.366  0.6506
##  FF - FS    -15.70 19.6 96.8  -0.800  0.9300
##  FF - S      10.86 20.3 96.5   0.535  0.9835
##  FF - SS      9.28 19.0 96.5   0.487  0.9884
##  FS - S      26.57 20.6 96.2   1.290  0.6979
##  FS - SS     24.99 19.3 96.2   1.292  0.6966
##  S - SS      -1.58 20.0 96.0  -0.079  1.0000
## 
## Results are averaged over the levels of: mate.rhodamine 
## Degrees-of-freedom method: kenward-roger 
## P value adjustment: tukey method for comparing a family of 5 estimates
emmeans(fit_mod, pairwise~morph)
## NOTE: Results may be misleading due to involvement in interactions
## $emmeans
##  morph emmean   SE   df lower.CL upper.CL
##  F       42.0 6.75 97.0     28.6     55.4
##  S       29.1 6.43 96.7     16.4     41.9
## 
## Results are averaged over the levels of: competitor, mate.rhodamine 
## Degrees-of-freedom method: kenward-roger 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast estimate   SE   df t.ratio p.value
##  F - S        12.9 6.07 98.7   2.124  0.0362
## 
## Results are averaged over the levels of: competitor, mate.rhodamine 
## Degrees-of-freedom method: kenward-roger
male_fit_graph <- emmip(fit_mod, morph~competitor, CIs=TRUE, type = "response", style = "factor", plotit = FALSE)

malefitnessgraph <- ggplot(male_fit_graph, aes(x=competitor, y=yvar, col=morph)) + theme_classic()+ geom_pointrange(aes(ymin=yvar-SE, ymax=yvar+SE), position="jitter") + scale_color_viridis(discrete=TRUE, labels=c("Focal Fighter Male", "Focal Scrambler Male")) + ylab("Male Fitness") + xlab("Rivals") + theme(legend.position = "bottom", legend.title=element_blank(),text = element_text(size = 15)) + scale_x_discrete(limits=c("FF", "FS", "SS", "S", "F"))

Probability of 0

fit_prob <- glm(as.numeric(fitness_prob)~competitor*morph + mate.rhodamine, family="binomial", data=fit_zero)
Anova(fit_prob)
## Analysis of Deviance Table (Type II tests)
## 
## Response: as.numeric(fitness_prob)
##                  LR Chisq Df Pr(>Chisq)
## competitor         4.2764  4     0.3699
## morph              0.7598  1     0.3834
## mate.rhodamine     1.3856  1     0.2391
## competitor:morph   0.7761  4     0.9416
fitprob.grid <- ref_grid(fit_prob)

emmeans(regrid(fitprob.grid), pairwise~competitor | morph)
## $emmeans
## morph = F:
##  competitor response     SE  df asymp.LCL asymp.UCL
##  F             0.529 0.1380 Inf    0.2587     0.800
##  FF            0.460 0.1201 Inf    0.2247     0.696
##  FS            0.475 0.1339 Inf    0.2122     0.737
##  S             0.400 0.1633 Inf    0.0800     0.720
##  SS            0.630 0.2027 Inf    0.2325     1.027
## 
## morph = S:
##  competitor response     SE  df asymp.LCL asymp.UCL
##  F             0.388 0.1636 Inf    0.0675     0.709
##  FF            0.496 0.1728 Inf    0.1574     0.835
##  FS            0.453 0.1204 Inf    0.2173     0.689
##  S             0.243 0.0965 Inf    0.0534     0.432
##  SS            0.510 0.0893 Inf    0.3354     0.685
## 
## Results are averaged over the levels of: mate.rhodamine 
## Confidence level used: 0.95 
## 
## $contrasts
## morph = F:
##  contrast estimate    SE  df z.ratio p.value
##  F - FF     0.0689 0.181 Inf   0.380  0.9956
##  F - FS     0.0545 0.188 Inf   0.290  0.9985
##  F - S      0.1290 0.208 Inf   0.622  0.9717
##  F - SS    -0.1006 0.240 Inf  -0.419  0.9936
##  FF - FS   -0.0144 0.179 Inf  -0.081  1.0000
##  FF - S     0.0601 0.201 Inf   0.299  0.9983
##  FF - SS   -0.1696 0.234 Inf  -0.723  0.9512
##  FS - S     0.0745 0.207 Inf   0.359  0.9964
##  FS - SS   -0.1551 0.240 Inf  -0.646  0.9674
##  S - SS    -0.2297 0.256 Inf  -0.898  0.8977
## 
## morph = S:
##  contrast estimate    SE  df z.ratio p.value
##  F - FF    -0.1081 0.228 Inf  -0.474  0.9897
##  F - FS    -0.0652 0.200 Inf  -0.327  0.9975
##  F - S      0.1455 0.186 Inf   0.782  0.9358
##  F - SS    -0.1224 0.185 Inf  -0.661  0.9646
##  FF - FS    0.0428 0.207 Inf   0.207  0.9996
##  FF - S     0.2536 0.194 Inf   1.309  0.6856
##  FF - SS   -0.0143 0.193 Inf  -0.074  1.0000
##  FS - S     0.2107 0.153 Inf   1.380  0.6407
##  FS - SS   -0.0571 0.149 Inf  -0.382  0.9955
##  S - SS    -0.2678 0.131 Inf  -2.047  0.2437
## 
## Results are averaged over the levels of: mate.rhodamine 
## P value adjustment: tukey method for comparing a family of 5 estimates

Female Fitness

Survival

Model

long_num <- mate_fight %>%
  filter(long != "CHECK") %>%
  mutate(num.long=as.numeric(long)) %>%
  mutate(times.mated.NA= ifelse(is.na(times.mated), 0, times.mated))


surv_long <- coxme(Surv(num.long)~trmnt_type*times.mated.NA + total.NA +(1|trmt) + mate.rhodamine, data=long_num)
Anova(surv_long)
## Analysis of Deviance Table (Type II tests)
## 
## Response: Surv(num.long)
##                           Df   Chisq Pr(>Chisq)  
## trmnt_type                 6 10.2396     0.1149  
## times.mated.NA             1  0.0003     0.9853  
## total.NA                   1  6.4332     0.0112 *
## mate.rhodamine             1  0.0764     0.7822  
## trmnt_type:times.mated.NA  6  2.5917     0.8581  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
surv.grid <- ref_grid(surv_long)

emmeans(regrid(surv.grid), pairwise~trmnt_type)
## NOTE: Results may be misleading due to involvement in interactions
## $emmeans
##  trmnt_type response    SE  df asymp.LCL asymp.UCL
##  FF            3.429 2.493 Inf   -1.4572      8.31
##  FFF           0.745 0.428 Inf   -0.0945      1.58
##  FFS           0.562 0.276 Inf    0.0220      1.10
##  FS            0.609 0.330 Inf   -0.0368      1.26
##  FSS           1.196 0.572 Inf    0.0743      2.32
##  SS            2.029 1.043 Inf   -0.0151      4.07
##  SSS           0.946 0.416 Inf    0.1312      1.76
## 
## Results are averaged over the levels of: mate.rhodamine 
## Confidence level used: 0.95 
## 
## $contrasts
##  contrast  estimate    SE  df z.ratio p.value
##  FF - FFF    2.6837 2.560 Inf   1.048  0.9427
##  FF - FFS    2.8667 2.528 Inf   1.134  0.9178
##  FF - FS     2.8193 2.527 Inf   1.116  0.9236
##  FF - FSS    2.2323 2.616 Inf   0.854  0.9791
##  FF - SS     1.3998 2.789 Inf   0.502  0.9988
##  FF - SSS    2.4827 2.569 Inf   0.966  0.9611
##  FFF - FFS   0.1830 0.533 Inf   0.343  0.9999
##  FFF - FS    0.1356 0.556 Inf   0.244  1.0000
##  FFF - FSS  -0.4514 0.763 Inf  -0.591  0.9971
##  FFF - SS   -1.2839 1.185 Inf  -1.084  0.9331
##  FFF - SSS  -0.2010 0.642 Inf  -0.313  0.9999
##  FFS - FS   -0.0474 0.442 Inf  -0.107  1.0000
##  FFS - FSS  -0.6344 0.690 Inf  -0.919  0.9697
##  FFS - SS   -1.4669 1.108 Inf  -1.324  0.8408
##  FFS - SSS  -0.3840 0.527 Inf  -0.728  0.9909
##  FS - FSS   -0.5870 0.704 Inf  -0.834  0.9815
##  FS - SS    -1.4195 1.117 Inf  -1.271  0.8652
##  FS - SSS   -0.3366 0.576 Inf  -0.584  0.9973
##  FSS - SS   -0.8325 1.270 Inf  -0.655  0.9949
##  FSS - SSS   0.2504 0.762 Inf   0.329  0.9999
##  SS - SSS    1.0829 1.169 Inf   0.926  0.9685
## 
## Results are averaged over the levels of: mate.rhodamine 
## P value adjustment: tukey method for comparing a family of 7 estimates

Plot - PICK COLOURS

survfit <- survfit(Surv(num.long)~trmnt_type + (1|trmt), data=long_num)

ggsurvplot(survfit, data=long_num)

ggsurvplot(survfit, data=long_num,
           legend.title="",
           legend.labs=c("FF", "FFF", "FFS", "FS", "FSS", "SS", "SSS"),
           xlab="Time in weeks",
           conf.int=TRUE,
           conf.int.style="step",
           xlim =c(0,100),
           legend = "bottom", 
           ggtheme = theme_pubr(),
           palette=c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7"),
           )

Fecundity

fem_fit <- mate_fight %>%
  filter(total !="CHECK") %>%
  mutate(total_num=as.numeric(total)) %>%
  filter(mate == 1)

fem_fit_two <- mate_fight %>%
  filter(total !="CHECK") %>%
  mutate(total_num=as.numeric(total)) %>%
  filter(mate == 1) %>%
  filter(times.mated != "3")

mated_fem <- mate_fight %>%
  group_by(trmt) %>%
  filter(mate == "1") %>%
  count(mate)

mated_fem_zero <- mate_fight %>%
  filter(mate=="1") %>%
  group_by(trmt) %>%
  filter(total == 0) %>%
  distinct(trmt, .keep_all=TRUE)

Total Female Fecundity

fem_fecund <- glmer(total_num~trmnt_type*as.factor(times.mated) + (1|trmt) + mate.rhodamine, family="poisson",control = glmerControl(optimizer ='optimx', optCtrl=list(method='nlminb')), data=fem_fit)
## fixed-effect model matrix is rank deficient so dropping 5 columns / coefficients
## Warning in optimx.check(par, optcfg$ufn, optcfg$ugr, optcfg$uhess, lower, : Parameters or bounds appear to have different scalings.
##   This can cause poor performance in optimization. 
##   It is important for derivative free methods like BOBYQA, UOBYQA, NEWUOA.
Anova(fem_fecund)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: total_num
##                                    Chisq Df Pr(>Chisq)
## trmnt_type                        7.7107  6     0.2601
## as.factor(times.mated)            2.3569  2     0.3077
## mate.rhodamine                    0.0015  1     0.9692
## trmnt_type:as.factor(times.mated) 4.5688  7     0.7124
fem_fecund_twice <- glmer(total_num~trmnt_type*as.factor(times.mated) + (1|trmt), family="poisson",control = glmerControl(optimizer ='optimx', optCtrl=list(method='nlminb')), data=fem_fit_two)
Anova(fem_fecund_twice)
## Analysis of Deviance Table (Type II Wald chisquare tests)
## 
## Response: total_num
##                                    Chisq Df Pr(>Chisq)
## trmnt_type                        7.2790  6     0.2958
## as.factor(times.mated)            1.1043  1     0.2933
## trmnt_type:as.factor(times.mated) 4.1984  6     0.6498
fecund.grid <- ref_grid(fem_fecund_twice)

emmeans(regrid(fecund.grid), pairwise~trmnt_type | times.mated)
## $emmeans
## times.mated = 1:
##  trmnt_type   rate     SE  df asymp.LCL asymp.UCL
##  FF         2.7985 4.7154 Inf   -6.4436   12.0405
##  FFF        0.3057 0.6223 Inf   -0.9140    1.5255
##  FFS        2.5200 4.0905 Inf   -5.4973   10.5373
##  FS         0.5129 1.0586 Inf   -1.5619    2.5878
##  FSS        4.9876 8.5097 Inf  -11.6911   21.6664
##  SS         0.0277 0.0471 Inf   -0.0646    0.1200
##  SSS        0.0357 0.0703 Inf   -0.1021    0.1735
## 
## times.mated = 2:
##  trmnt_type   rate     SE  df asymp.LCL asymp.UCL
##  FF         1.2105 4.6543 Inf   -7.9118   10.3327
##  FFF        0.2051 0.5885 Inf   -0.9482    1.3585
##  FFS        0.0173 0.0437 Inf   -0.0685    0.1030
##  FS         0.2236 0.6100 Inf   -0.9720    1.4193
##  FSS        0.1538 0.3536 Inf   -0.5393    0.8469
##  SS         0.0123 0.0272 Inf   -0.0411    0.0657
##  SSS        0.4868 1.0137 Inf   -1.5001    2.4737
## 
## Confidence level used: 0.95 
## 
## $contrasts
## times.mated = 1:
##  contrast  estimate     SE  df z.ratio p.value
##  FF - FFF   2.49275 4.7084 Inf   0.529  0.9984
##  FF - FFS   0.27846 6.1326 Inf   0.045  1.0000
##  FF - FS    2.28557 4.7672 Inf   0.479  0.9991
##  FF - FSS  -2.18914 9.5822 Inf  -0.228  1.0000
##  FF - SS    2.77076 4.7119 Inf   0.588  0.9972
##  FF - SSS   2.76281 4.7103 Inf   0.587  0.9972
##  FFF - FFS -2.21429 4.1020 Inf  -0.540  0.9982
##  FFF - FS  -0.20718 1.1713 Inf  -0.177  1.0000
##  FFF - FSS -4.68190 8.4965 Inf  -0.551  0.9980
##  FFF - SS   0.27801 0.6179 Inf   0.450  0.9994
##  FFF - SSS  0.27005 0.6170 Inf   0.438  0.9995
##  FFS - FS   2.00711 4.1768 Inf   0.481  0.9991
##  FFS - FSS -2.46761 9.3444 Inf  -0.264  1.0000
##  FFS - SS   2.49230 4.0880 Inf   0.610  0.9965
##  FFS - SSS  2.48434 4.0869 Inf   0.608  0.9966
##  FS - FSS  -4.47472 8.5257 Inf  -0.525  0.9985
##  FS - SS    0.48519 1.0546 Inf   0.460  0.9993
##  FS - SSS   0.47724 1.0534 Inf   0.453  0.9994
##  FSS - SS   4.95991 8.5070 Inf   0.583  0.9973
##  FSS - SSS  4.95195 8.5058 Inf   0.582  0.9973
##  SS - SSS  -0.00795 0.0791 Inf  -0.101  1.0000
## 
## times.mated = 2:
##  contrast  estimate     SE  df z.ratio p.value
##  FF - FFF   1.00534 4.6752 Inf   0.215  1.0000
##  FF - FFS   1.19320 4.6528 Inf   0.256  1.0000
##  FF - FS    0.98683 4.6712 Inf   0.211  1.0000
##  FF - FSS   1.05666 4.6527 Inf   0.227  1.0000
##  FF - SS    1.19816 4.6532 Inf   0.257  1.0000
##  FF - SSS   0.72362 4.7355 Inf   0.153  1.0000
##  FFF - FFS  0.18787 0.5873 Inf   0.320  0.9999
##  FFF - FS  -0.01850 0.8209 Inf  -0.023  1.0000
##  FFF - FSS  0.05133 0.6650 Inf   0.077  1.0000
##  FFF - SS   0.19282 0.5872 Inf   0.328  0.9999
##  FFF - SSS -0.28172 1.1483 Inf  -0.245  1.0000
##  FFS - FS  -0.20637 0.6078 Inf  -0.340  0.9999
##  FFS - FSS -0.13654 0.3520 Inf  -0.388  0.9997
##  FFS - SS   0.00496 0.0492 Inf   0.101  1.0000
##  FFS - SSS -0.46959 1.0118 Inf  -0.464  0.9993
##  FS - FSS   0.06983 0.6752 Inf   0.103  1.0000
##  FS - SS    0.21133 0.6080 Inf   0.348  0.9999
##  FS - SSS  -0.26322 1.1496 Inf  -0.229  1.0000
##  FSS - SS   0.14150 0.3517 Inf   0.402  0.9997
##  FSS - SSS -0.33304 1.0495 Inf  -0.317  0.9999
##  SS - SSS  -0.47454 1.0122 Inf  -0.469  0.9992
## 
## P value adjustment: tukey method for comparing a family of 7 estimates
fem_fecund_graph <- emmip(fem_fecund_twice, ~trmnt_type | times.mated, CIs=TRUE, style = "factor", type="response", plotit = FALSE)

femalefitnessgraph <- ggplot(fem_fecund_graph, aes(x=trmnt_type, y=yvar, col=as.factor(times.mated))) + theme_classic() + geom_pointrange(aes(ymin=yvar-SE, ymax=yvar+SE), position="jitter") + ylab("Female Fitness") + xlab("Treatment Type") + theme(legend.position = "bottom",legend.title=element_blank(), text = element_text(size = 15)) + scale_x_discrete(limits=c("FFF", "FFS", "FSS", "SSS", "SS", "FF")) + scale_color_d3(labels=c("Mated Once", "Mated Twice"))

ggarrange(malefitnessgraph, femalefitnessgraph, ncol=1, labels=c("A", "B"))
## Warning: Removed 2 rows containing missing values (`geom_pointrange()`).

Graph

ggplot(fem_fit, aes(trmnt_type,total_num, fill=as.factor(times.mated))) + geom_boxplot() + theme_classic() + theme(legend.position="bottom") + scale_fill_nejm()

How many females mated but did not produce eggs?

fem_noegg <- mate_fight %>%
  filter(total !="CHECK") %>%
  mutate(total_num=as.numeric(total)) %>%
  filter(mate == 1) %>%
  filter(total == 0) %>%
  group_by(trmnt_type, times.mated) %>%
  count(times.mated)

fem_noegg
## # A tibble: 15 × 3
## # Groups:   trmnt_type, times.mated [15]
##    trmnt_type times.mated     n
##    <chr>            <int> <int>
##  1 FF                   1     4
##  2 FF                   2     2
##  3 FFF                  1     5
##  4 FFF                  2     4
##  5 FFS                  1     3
##  6 FFS                  2     6
##  7 FS                   1     4
##  8 FS                   2     6
##  9 FSS                  1     3
## 10 FSS                  2     8
## 11 SS                   1     6
## 12 SS                   2     8
## 13 SSS                  1     5
## 14 SSS                  2     6
## 15 SSS                  3     3

How many times females mated vs produced eggs?

fem_egg <- mate_fight %>%
  filter(total !="CHECK") %>%
  mutate(total_num=as.numeric(total)) %>%
  filter(mate == 1) %>%
  filter(total != 0) %>%
  group_by(trmnt_type, times.mated) %>%
  count(times.mated)

fem_egg
## # A tibble: 16 × 3
## # Groups:   trmnt_type, times.mated [16]
##    trmnt_type times.mated     n
##    <chr>            <int> <int>
##  1 FF                   1     6
##  2 FF                   2     2
##  3 FFF                  1     4
##  4 FFF                  2     4
##  5 FFS                  1     7
##  6 FFS                  2     2
##  7 FFS                  3     3
##  8 FS                   1     4
##  9 FS                   2     4
## 10 FSS                  1     6
## 11 FSS                  2     6
## 12 SS                   1     3
## 13 SS                   2     2
## 14 SSS                  1     2
## 15 SSS                  2     8
## 16 SSS                  3     6