More statistics exercises (extra)
Get RStudio setup
- Make a new folder in your course folder for the exercise (e.g. bioc13/day_2_extra)
- Open RStudio
- If you haven’t closed RStudio since the last exercise, I recommend you close it and then re-open it. If it asks if you want to save your R Session data, choose no.
 
- Set your working directory by going to Session -> Set working directory -> Choose directory, then navigate to the folder you just made for this exercise.
- Create a new Rmarkdown document (File -> New file -> R markdown..). Give it a clear title.
- Create a new code cell, and load the tidyverseandinferpackages usinglibrary().
How does diet and temperature influence tobacco hornworms

Background
Insect colouration mediated by melanization can assist in dealing with environmental temperatures. However, melanin synthesis can be costly and depends on the ability of insects to acquire enough energy and nutrients from their diets. Due to the increased plant C:N ratio associated with elevated CO2 concentrations, insect herbivores’ melanization could be limited by the amount of nitrogen they acquire from their host plants.
To investigate how diet C:N impacts the potential colour response to temperature, the authors used Manduca sexta caterpillars reared at different combinations of temperatures and diet C:N ratios, and measured pupal mass and development time (performance metrics) and colour morphology.
Soon after eclosion, Manduca sexta larvae were reared under two temperature conditions ("18C", "27C") and two diet_quality treatments ("low" or "high" nitrogen content). The authors measured pupal_mass_g and development_time as performance metrics. They also photographed the 5th instar larvae before the wandering stage and measured color as mean colour (red_mean, blue_mean, green_mean) and luminance (luminance_mean) values across the larvae. The experiment was repeated over two different years.
The dataset
The results of the experiment are stored in a csv file here: Link to data.
Once downloaded, you should move it to your working directory folder for this exercise before continuing.
Loading the data into R
In a new code cell, use read_csv() to load the data into R. Assign it to an object.
Explore the dataset
To get a better understanding of the dataset before you continue, use functions from previous exercises to explore the dataset, calculate summary statistics and make quick and basic plots.
The research question
In this exercise, you need to address the research question:
- How do diet_qualityandtemperatureinfluence performance and colouration in Manduca sexta.
By the end, you need to be able to answer the following questions:
- What effect did temperaturehave on performance and colouration in Manduca sexta?
- What effect did diet_qualityhave on performance and colouration in Manduca sexta?
- Was the effect of temperatureanddiet_qualityadditive, or do they interact?
For each question, refer to the at least one statistical method, and a plot that shows the variables of interest.
You must use statistical methods in the infer package to answer these questions. Both null hypothesis testing and confidence intervals are applicable methods.
To analyze the data, consider using the fit() function from the infer package. Use the examples from the infer website and find ones that fits what you want to do.