Lab 2: Help, these kids are killing me! (Part II)

Multilevel and hierarchical models

Due: 11:59pm, Tuesday, February 2

Housekeeping

R/RStudio

You all should have R and RStudio installed on your computers by now. If you do not, first install the latest version of R here: https://cran.rstudio.com (remember to select the right installer for your operating system). Next, install the latest version of RStudio here: https://www.rstudio.com/products/rstudio/download/. Scroll down to the “Installers for Supported Platforms” section and find the right installer for your operating system.

Gradescope

You MUST submit both your .Rmd and .pdf files to the course site on Gradescope here: https://www.gradescope.com/courses/224715/assignments. Do NOT create a zipped folder with the two documents but instead, upload them as two separate documents. Also, be sure to knit to pdf and NOT html; ask the TA about knitting to pdf if you cannot figure it out. Be sure to submit under the right assignment entry. Finally, when submitting your files, please select the corresponding pages for each exercise.

Introduction

This individual lab is a continuation of the previous lab.

In a classic Nature communication, Partridge and Farquhar argued that there is a physiological cost of reproduction, which is in line with many evolutionary theories. At that time, this cost had been shown experimentally for females, but no cost for sexual activity had been shown for males in which the only paternal contribution to offspring is provision of gametes.

To explore whether there is any effect of sexual activity on lifespan, researchers randomized male fruit flies to one of two groups: an isolated population of males (no sexual activity), or a mixed-gender population in which the male fruit flies were sexually active. Because body size has also been linked to longevity, we consider it here (measured by thorax length) as well.

The Data

The data are in the file fruitfly_thorax_len.csv, which contains lifespan, thorax length, and sexual activity for male fruit flies in the experiment.

For reference and as a quick recap of the EDA you did in the previous lab, here is a visualization of the lifespan of the male fruit flies as a function of body size and sexual activity.

library(ggplot2)
buzzkiller=read_csv("data/fruitfly_thorax_len.csv")
## Parsed with column specification:
## cols(
##   thorax = col_character(),
##   longevity = col_double(),
##   sexually_active = col_character()
## )
#reorder factors
buzzkiller$thorax <- factor(buzzkiller$thorax,
                                     levels = c("short",
                                                "long"))
ggplot(buzzkiller,
       aes(x = sexually_active, y = longevity, color = thorax)) +
  stat_summary(fun = mean,
               geom = "point",
               shape = 5,
               size = 4,
               position = position_dodge(0.5)) +
  geom_jitter(position = position_dodge(0.5), alpha = 0.3) +
  scale_color_manual(values=c("black", "dodgerblue3")) +
  xlab("Sexual Activity") +
  ylab("Longevity (days)")  

Exercises

The main purpose of this lab is to help you practice or start to develop your report writing skills. Prepare a short (maximum of 2 pages) but well organized written report describing the association between sexual activity, body size, and longevity in male fruit flies. You should be able to rely heavily on the work you did in the last lab. Your report should include the following.

DO NOT INCLUDE R CODE OR OUTPUT IN YOUR REPORTS. All R outputs should be converted to nicely formatted tables. Feel free to use R packages such as kable, xtable, stargazer, etc.