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 contrast to the previous exercise, we perform the analysis for all three diets in the dataset.

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 Multivariate linear regression analysis

6.1 Model specification

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

6.2 Assumptions

Check the assumptions of the linear regression model

6.3 Hypothesis testing

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

6.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.

6.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.

6.6 Assessing the interaction effect between protein source and protein level

6.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
    • cereal versus beef
    • pork verus beef
    • pork versus cereal
  2. protein source in high protein diets
    • cereal versus beef
    • pork verus beef
    • pork versus cereal
  3. protein level (high versus low) for
    • beef diets
    • cereal diets
    • pork diets
  4. If the effect of the protein level differs between
    • beef and cereal
    • beef and pork
    • cereal and pork diets

These effects of interest are so-called contrasts, i.e. linear combinations of the parameters.

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.

7 Conclusion

Formulate a conclusion for the different research hypotheses.

LS0tCnRpdGxlOiAiRXhlcmNpc2UgOC42OiBCbG9ja2luZyBvbiB0aGUgcmF0IGRpZXQgZGF0YXNldCAoMikiICAgCmF1dGhvcjogIkxpZXZlbiBDbGVtZW50IGFuZCBKZXJvZW4gR2lsaXMiCmRhdGU6ICJzdGF0T21pY3MsIEdoZW50IFVuaXZlcnNpdHkgKGh0dHBzOi8vc3RhdG9taWNzLmdpdGh1Yi5pbykiICAKb3V0cHV0OgogICAgaHRtbF9kb2N1bWVudDoKICAgICAgY29kZV9kb3dubG9hZDogdHJ1ZSAgICAKICAgICAgdGhlbWU6IGNvc21vCiAgICAgIHRvYzogdHJ1ZQogICAgICB0b2NfZmxvYXQ6IHRydWUKICAgICAgaGlnaGxpZ2h0OiB0YW5nbwogICAgICBudW1iZXJfc2VjdGlvbnM6IHRydWUKLS0tCgojIEJhY2tncm91bmQgCgpSZXNlYXJjaGVycyBhcmUgc3R1ZHlpbmcgdGhlIGltcGFjdCBvZiBwcm90ZWluIHNvdXJjZXMgYW5kIHByb3RlaW4gbGV2ZWxzIGluIAp0aGUgZGlldC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