Deadline: Friday, October 9
Resubmission deadline: Friday, October 30
The goal of today’s lab is to use linear regression and related statistical methods to investigate the relationship between paternal age, maternal age, and the number of de novo mutations (DNMs) in a proband (offspring). Today’s assignment will build familiarity with manipulating tabular datasets containing mixed data types using the tidyverse in R. Specifically, you will import a table of de novo mutations and manipulate it to calculate the number of maternal and paternal DNMs per individual. You will then fit and interpret simple and multiple linear regression models with stats::lm, compare nested models with stats::anova, and tidy results with broom.
This assignment is an R Markdown notebook. Write your code in the empty code chunks and your answers where you see Your answer:.
Data are taken from Halldorsson, B. V. et al. (2019). Characterizing mutagenic effects of recombination through a sequence-level genetic map. Science, 363(6425).
Read the abstract from the above paper to understand the context of the datasets you will be using. The data you need for this assignment are available from Dropbox at:
You may copy these into your submission directory (and add to your .gitignore).
Before beginning the assignment, take a quick look at both files (e.g., with less -S in Unix) to confirm their structure.
Load the tidyverse and broom packages.
Load aau1043_dnm.csv into a tibble.
Create a per-proband summary with counts of maternally and paternally inherited DNMs. Ignore DNMs without a specified parent of origin. Name the count columns maternal_dnm and paternal_dnm, as later steps use these names.
Load aau1043_parental_age.csv.
Join the two tibbles by proband ID. Name the result merged, as later steps use this name.
Use your merged data frame for the following. All plots should be clearly labeled and easily interpretable.
2.1.1 Create a scatter plot of the count of maternal DNMs vs. maternal age → save as ex2_a.png
2.1.2 Create a scatter plot of the count of paternal DNMs vs. paternal age → save as ex2_b.png
2.1.3 Create a scatter plot of paternal age vs. maternal age → save as ex2_c.png
Fit a simple linear regression model relating maternal age to the number of maternal de novo mutations.
Answer the following questions:
What is the “size” (i.e., slope) of this relationship? Interpret the slope in plain language. Does it match your plot?
Your answer:
Is the relationship significant? How do you know? Explain the p-value in plain but precise language.
Your answer:
Repeat the step above but for paternal age vs. paternal DNMs.
Answer the following questions:
What is the “size” (i.e., slope) of this relationship? Interpret the slope in plain language. Does it match your plot?
Your answer:
Is the relationship significant? How do you know? Explain the p-value in plain but precise language.
Your answer:
Use the paternal regression model to predict the expected number of paternal DNMs for a father of age 50.5. You are welcome to do this manually or using a built-in function, but show your work in the code chunk.
Your answer:
Maternal DNMs arose in the mother’s germline, so there is no obvious reason that the father’s age should affect them.
2.5.1 Fit a simple linear regression model relating paternal age to the number of maternal DNMs.
Is paternal age a significant predictor of maternal DNMs on its own? Using your plot from 2.1.3, explain why this might happen.
Your answer:
2.5.2 Fit a multiple linear regression model with both maternal age and paternal age as predictors of maternal DNMs, just as we added year as a covariate in the penguin example.
What happened to the paternal age coefficient and its p-value?
Your answer:
Interpret the maternal age coefficient in plain language. How does its meaning differ from the slope you estimated in Step 2.2? (Hint: what is being held constant?)
Your answer:
2.5.3 Use anova() to compare your two-predictor model from 2.5.2 to your model from Step 2.2 (maternal age only).
Hint: In the live coding, we used
anova()to test whether island improved a model that already contained sex and year. The same approach works for any pair of models where the smaller model is the larger model with some terms removed (these are called “nested” models). Here, the smaller model is the one that leaves out paternal age.
Does adding paternal age improve the model? Compare the p-value from anova() to the p-value for paternal age in the summary() of the two-predictor model. Why are they the same here, when for island we needed anova() to get a single answer? (Hint: how many coefficients did island add to the model, and how many does paternal age add?)
Your answer:
Plot both distributions on the same axes as semi-transparent histograms; save as ex2_d.png.
We have paired observations per proband (maternal vs. paternal). The paired t-test assumes that the within-pair differences are approximately normally distributed.
2.7.1 Apply a paired t-test in R using t.test(merged$maternal_dnm, merged$paternal_dnm, paired = TRUE).
What is the “size” of this relationship (i.e., the average difference in counts of maternal and paternal DNMs)? Interpret the difference in plain language. Does it match your plot?
Your answer:
Is the relationship significant? How do you know? Explain the p-value in plain but precise language.
Your answer:
2.7.2 The paired t-test is equivalent to using the difference between the maternal and paternal DNM counts per proband as the response variable and fitting a model with only an intercept term (indicated with 1 on the right side of the model formula). Fit this model using lm().
How do the results compare to the paired t-test? How would you interpret the coefficient estimate for the intercept term?
Your answer:
Choose a dataset from the bottom of the TidyTuesday README and load it.
Which dataset did you choose?
Your answer:
Generate figures; save them as ex3_<something>.png.
What interesting patterns do you notice?
Your answer:
State a hypothesis that you can test with a linear model.
Your answer:
Fit a linear model with at least two predictors to test your hypothesis, and evaluate its fit.
Why did you include each predictor?
Your answer:
Report and interpret your results. How well does the model fit?
Your answer:
.Rmd), with code in each chunk and your answers to all questions.ex2_a.png through ex2_d.png, and your ex3_ figures).anova() (1.5 pts)t.test and lm(diff ~ 1)) and interpret results (1 pt)Total Points: 10