Pint008

Author

Calvin Belton

library("tidyverse")
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library("survival")
library("ggfortify")
pint008 <- read.csv("/Users/chloebelton/Desktop/Pint008.csv")
pint008$AdultDays <- as.integer(pint008$AdultDays)
str(pint008)
'data.frame':   181 obs. of  11 variables:
 $ Experiment    : chr  "Pint008" "Pint008" "Pint008" "Pint008" ...
 $ PairID        : int  1 2 2 3 4 4 5 5 6 6 ...
 $ PairType      : chr  "Singleton" "MixedPair" "MixedPair" "Singleton" ...
 $ IndividualID  : chr  "A" "A" "B" "A" ...
 $ SampleID      : chr  "001A" "002A" "002B" "003A" ...
 $ Sex           : chr  "Female" "Female" "Male" "Female" ...
 $ EclosionDate  : chr  "2024-06-18" "2024-06-19" "2024-06-19" "2024-06-19" ...
 $ DeathDate     : chr  "2024-06-24" "2024-06-28" "2024-06-29" "2024-06-25" ...
 $ Larva.Observed: chr  NA "TRUE" NA NA ...
 $ AdultDays     : int  6 9 10 6 5 13 10 17 7 7 ...
 $ Comment       : chr  "" "Few larva" "" "" ...
boxplot(AdultDays ~ Sex, data = pint008, col = c("firebrick2", "dodgerblue"))

boxplot(AdultDays~PairType, data = pint008, col = c("firebrick2", "dodgerblue", "yellow", "green"))

boxplot(AdultDays ~ Larva.Observed, data = pint008, col = c("firebrick2", "dodgerblue"))

breaksBy1 <- 2:23
par(mfrow = c(1,2))
hist(pint008$AdultDays[pint008$Sex == "Female"], col = "firebrick2",  breaks = breaksBy1, xlab = "Adult Age", main = "Female")
hist(pint008$AdultDays[pint008$Sex == "Male"], col="dodgerblue", 
breaks = breaksBy1, xlab = "Adult Age", main = "Male")

par(mfrow = c(2,2))
hist(pint008$AdultDays[pint008$PairType == "FemalePair"], col = "firebrick2", breaks = breaksBy1, xlab = "Pair Type", main = "FemalePair")
hist(pint008$AdultDays[pint008$PairType == "MixedPair"], col = "dodgerblue", breaks = breaksBy1, xlab = "Pair Type", main = "MixedPair")
hist(pint008$AdultDays[pint008$PairType == "MalePair"], col = "yellow", breaks = breaksBy1, xlab = "Pair Type", main = "MalePair")
hist(pint008$AdultDays[pint008$PairType == "Singleton"], col = "green", breaks = breaksBy1, xlab = "Pair Type", main = "Singleton")

par(mfrow = c(1,2))
hist(pint008$AdultDays[pint008$Larva.Observed == "TRUE"], col = "firebrick2", breaks = breaksBy1, xlab = "Larva Observed", main = "TRUE")
hist(pint008$AdultDays[pint008$Larva.Observed == "FALSE"], col="dodgerblue", breaks = breaksBy1, xlab = "Larva Observed", main = "FALSE")

tapply(X=pint008$AdultDays, INDEX=pint008$Sex, FUN=summary)
[[1]]
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
     NA      NA      NA     NaN      NA      NA      10 

$Female
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  3.000   6.000   8.000   7.609   9.000  12.000 

$Male
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   7.00   14.00   15.00   15.27   17.00   21.00 
tapply(X=pint008$AdultDays, INDEX=pint008$PairType, FUN=summary)
[[1]]
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
     NA      NA      NA     NaN      NA      NA      10 

$FemalePair
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  3.000   5.000   6.000   6.045   7.000   9.000 

$MalePair
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  12.00   15.00   15.00   15.59   17.00   21.00 

$MixedPair
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
   5.00    9.00   12.00   12.22   15.00   21.00 

$Singleton
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  5.000   5.500   6.000   5.667   6.000   6.000 
survPint008 <- Surv(time = pint008$AdultDays, event = rep(1, nrow(pint008)))
survPint008.diff <- survdiff(survPint008 ~ pint008$Sex)
print(survPint008.diff)
Call:
survdiff(formula = survPint008 ~ pint008$Sex)

n=171, 10 observations deleted due to missingness.

                    N Observed Expected (O-E)^2/E (O-E)^2/V
pint008$Sex=Female 92       92       35      92.6       175
pint008$Sex=Male   79       79      136      23.9       175

 Chisq= 175  on 1 degrees of freedom, p= <2e-16 
survPint008.diff$pvalue
[1] 4.994678e-40
survPint008 <- Surv(time = pint008$AdultDays, event = rep(1, nrow(pint008)))
survPint008.diff <- survdiff(survPint008 ~ pint008$PairType)
print(survPint008.diff)
Call:
survdiff(formula = survPint008 ~ pint008$PairType)

n=171, 10 observations deleted due to missingness.

                             N Observed Expected (O-E)^2/E (O-E)^2/V
pint008$PairType=FemalePair 44       44    9.683    121.63    159.91
pint008$PairType=MalePair   32       32   58.260     11.84     24.42
pint008$PairType=MixedPair  92       92  102.543      1.08      3.49
pint008$PairType=Singleton   3        3    0.514     12.02     13.02

 Chisq= 189  on 3 degrees of freedom, p= <2e-16 
survPint008.diff$pvalue
[1] 1.250988e-40
survPint008.fit <- survfit(survPint008 ~ pint008$Sex)
print(survPint008.fit)
Call: survfit(formula = survPint008 ~ pint008$Sex)

   10 observations deleted due to missingness 
                    n events median 0.95LCL 0.95UCL
pint008$Sex=Female 92     92      8       7       8
pint008$Sex=Male   79     79     15      15      16
autoplot(survPint008.fit) + scale_fill_manual(values=c("firebrick2", "dodgerblue")) +
theme_classic() + 
labs(title = "Plodia PiW3 Survivorship", x="Days", y="Survival")

survPint008.fit <- survfit(survPint008 ~ pint008$PairType)
print(survPint008.fit)
Call: survfit(formula = survPint008 ~ pint008$PairType)

   10 observations deleted due to missingness 
                             n events median 0.95LCL 0.95UCL
pint008$PairType=FemalePair 44     44      6       5       7
pint008$PairType=MalePair   32     32     15      15      17
pint008$PairType=MixedPair  92     92     12      11      14
pint008$PairType=Singleton   3      3      6       5      NA
autoplot(survPint008.fit) + scale_fill_manual(values=c("firebrick2", 
"dodgerblue", "yellow", "green")) +
theme_classic() + 
labs(title = "Plodia PiW3 Survivorship", x="Days", y="Survival")