Chick weights
The ChickWeight
data set is part of the base package
datasets
. See ?ChickWeight
for details on the
data. For all of the questions use dplyr
functions whenever
possible.
- Download the RMarkdown file with these homework instructions to use
as a template for your work. Make sure to replace “Your Name” in the
YAML with your name. To get full points, show your R code (in a code
chunk) and write answers to the questions.
- (1 pt) What variables are part of the dataset?
- (2 pts) Get a frequency breakdown of the number of chicks, their
average weight and the standard deviation of the weights in each of the
diets at the start of the study.
0.5 pts of extra credit: construct
a ggplot that shows average weights by diet with an interval (shown as a
line) of +- the standard deviation around the averages. (Hint: read this
article regarding ggplot
error bars)
- (2.5 pts) Each chick should have twelve weight measurements. Use the
dplyr package to identify how many chicks have a complete set of weight
measurements and how many measurements there are on average in the
incomplete cases. Extract a subset of the data for all chicks with
complete information and name the data set
complete
. (Hint:
you might want to use mutate to introduce a helper variable consisting
of the number of observations)
- (.5 pt) In the complete data set introduce a new variable that
measures the current weight difference compared to day 0. Name this
variable
weightgain
. (Hint: use mutate and
?mutate
to check the parameter .by
. This
parameter can create a temporary group_by
so that we can do
calculation in each subgroup, i.e. for each combination of chick and
diet, weight - min(weight)
)
- (2.5 pts) Use ggplot2 to create side-by-side boxplots of
weightgain
by Diet
for day 21. Describe the
relationship in 2-3 sentences. Change the order of the categories in the
Diet variable such that the boxplots are ordered by median
weightgain
.
Note: 1.5 pts your submission is supposed to be fully reproducible,
i.e. the TA and I will ‘knit’ your submission in RStudio.
For the submission: submit your solution in an R Markdown file and
(just for insurance) submit the corresponding html (or Word) file with
it.