1 Background

Researchers are studying the impact of protein sources and protein levels in the diet on the weight of rats. They feed the rats with diets of beef, cereal and pork and use a low and high protein level for each diet type. The researchers can include 60 rats in the experiment. Prior to the experiment, the rats were divided in 10 homogeneous groups of 6 rats based on characteristics such as initial weight, appetite, etc.

Within each group a rat is randomly assigned to a diet. The rats are fed during a month and the weight gain in grams is recorded for each rat.

The researchers want to assess the effect of the type of diet and the protein level on the weight of the rats.

In this exercise we will perform the data exploration using all diets, but, to keep the data analysis simple we will only assess the beef and cereal diets.

2 Experimental design

  • There are three explanatory variables in the experiment: the factor diet type with two levels (beef and cereal), factor protein level with levels (low and high) and a group blocking factor with 10 levels.

  • There are 6 treatments: beef-high, cereal-high, pork-high, beef-low, cereal-low, pork-low protein.

  • The rats are the experimental units (the unit to which a treatment is applied): in this design, there is a randomisation restriction: Within a block, a rat is randomly assigned to a diet.

  • The rats are the observational units (the unit on which the response is measured): The weight is weighted for each rat.

  • The weight gain is the response variable.

  • The experiment is a randomized complete block (RCB) design

Load libraries

library(tidyverse)

3 Data import

diet <- read.table("https://raw.githubusercontent.com/statOmics/PSLS21/data/dietRats.txt",
                   header=TRUE)
head(diet)

4 Tidy data

diet <- diet %>%
  mutate(block = as.factor(block),
         protSource = as.factor(protSource),
         protLevel = as.factor(protLevel)) %>%
  mutate(protLevel = fct_relevel(protLevel, "l"))

5 Data exploration

  • Boxplot of the weight gain against protein source, protein level with coloring according to block

  • Lineplot of the weight gain against protein source, protein level with coloring and grouping according to block

  • Interpret the plots

6 Data filtering

Filter the data to only use the beef and cereal diet.

7 Multivariate linear regression analysis

7.1 Model specification

Based on the data exploration, propose a sensible regression model to analyse the data.

7.2 Assumptions

Check the assumptions of the linear regression model

7.3 Hypothesis testing

Use the summary function to get an initial test for the parameters in the model.

7.4 Interpretation of the regression parameters

To facilitate the interpretation of the different parameters in our regression model, we can make use of the VisualizeDesign function of the ExploreModelMatrix R package. The first argument of this function is the name of our target dataset, the second argument is a model formula, which in this case is specified as a ~ followed by the explanatory variables in our model.

library(ExploreModelMatrix)
ExploreModelMatrix::VisualizeDesign(..., ~ ...)$plotlist

After seeing this, again think about the meaning of the parameters in our model.

7.5 Testing the overall (omnibus) effect of diet

By comparing a model containing diet effects to a model that does not have diet effects, using anova.

7.6 Assessing the interaction effect between protein source and protein level

7.7 Assessing specific contrasts

Imagine that we are interested in assessing if there is an effect of

  1. protein source in the low protein diets

  2. protein source in high protein diets

  3. protein level for beef diets,

  4. protein level for cereal diets,

  5. if the effect of the protein level differs between beef and cereal

Step 1: translate these research questions into parameters of the model (or combinations of multiple parameters).

Step 2: Assess the significance of the contrasts using the multcomp package. The contrasts are given as input in the form of symbolic descriptions to the linfct argument of the glht function.

8 Conclusion

Formulate a conclusion for the different research hypotheses.

LS0tCnRpdGxlOiAiRXhlcmNpc2UgOC41OiBCbG9ja2luZyBvbiB0aGUgcmF0IGRpZXQgZGF0YXNldCIgICAKYXV0aG9yOiAiTGlldmVuIENsZW1lbnQgYW5kIEplcm9lbiBHaWxpcyIKZGF0ZTogInN0YXRPbWljcywgR2hlbnQgVW5pdmVyc2l0eSAoaHR0cHM6Ly9zdGF0b21pY3MuZ2l0aHViLmlvKSIgIApvdXRwdXQ6CiAgICBodG1sX2RvY3VtZW50OgogICAgICBjb2RlX2Rvd25sb2FkOiB0cnVlICAgIAogICAgICB0aGVtZTogY29zbW8KICAgICAgdG9jOiB0cnVlCiAgICAgIHRvY19mbG9hdDogdHJ1ZQogICAgICBoaWdobGlnaHQ6IHRhbmdvCiAgICAgIG51bWJlcl9zZWN0aW9uczogdHJ1ZQotLS0KCiMgQmFja2dyb3VuZCAKClJlc2VhcmNoZXJzIGFyZSBzdHVkeWluZyB0aGUgaW1wYWN0IG9mIHByb3RlaW4gc291cmNlcyBhbmQgcHJvdGVpbiBsZXZlbHMgaW4gCnRoZSBkaWV0IG9uIHRoZSB3ZWlnaHQgb2YgcmF0cy4gVGhleSBmZWVkIHRoZSByYXRzIHdpdGggZGlldHMgb2YgYmVlZiwgY2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