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.
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 and observational units.
The weight gain is the response variable.
The experiment is a randomized complete block (RCB) design
Load libraries
Data import
diet <- read.table("https://raw.githubusercontent.com/statOmics/PSLSData/main/dietRats.txt",
header = TRUE
)
head(diet)
Tidy data
diet <- diet %>%
mutate(
block = as.factor(block),
protSource = as.factor(protSource),
protLevel = as.factor(protLevel)
) %>%
mutate(protLevel = fct_relevel(protLevel, "l"))
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
Multivariate linear regression analysis
Model specification
Based on the data exploration, propose a sensible regression model to analyse the data.
Assumptions
Check the assumptions of the linear regression model
Hypothesis testing
Use the summary
function to get an initial test for the parameters in the model.
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.
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.
Assessing the interaction effect between protein source and protein level
Assessing specific contrasts
Imagine that we are interested in assessing if there is an effect of
- protein source in the low protein diets
- cereal versus beef
- pork verus beef
- pork versus cereal
- protein source in high protein diets
- cereal versus beef
- pork verus beef
- pork versus cereal
- protein level (high versus low) for
- beef diets
- cereal diets
- pork diets
- 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.
Conclusion
Formulate a conclusion for the different research hypotheses.
LS0tCnRpdGxlOiAiRXhlcmNpc2UgOC42OiBCbG9ja2luZyBvbiB0aGUgcmF0IGRpZXQgZGF0YXNldCAoMikiCmF1dGhvcjogIkxpZXZlbiBDbGVtZW50IGFuZCBKZXJvZW4gR2lsaXMiCmRhdGU6ICJzdGF0T21pY3MsIEdoZW50IFVuaXZlcnNpdHkgKGh0dHBzOi8vc3RhdG9taWNzLmdpdGh1Yi5pbykiCi0tLQoKIyBCYWNrZ3JvdW5kCgpSZXNlYXJjaGVycyBhcmUgc3R1ZHlpbmcgdGhlIGltcGFjdCBvZiBwcm90ZWluIHNvdXJjZXMgYW5kIHByb3RlaW4gbGV2ZWxzIGluCnRoZSBkaWV0IG9uIHRoZSB3ZWlnaHQgb2YgcmF0cy4gVGhleSBmZWVkIHRoZSByYXRzIHdpdGggZGlldHMgb2YgYmVlZiwgY2VyZWFsCmFuZCBwb3JrIGFuZCB1c2UgYSBsb3cgYW5kIGhpZ2ggcHJvdGVpbiBsZXZlbCBmb3IgZWFjaCBkaWV0IHR5cGUuClRoZSByZXNlYXJjaGVycyBjYW4gaW5jbHVkZSA2MCByYXRzIGluIHRoZSBleHBlcmltZW50LiBQcmlvciB0byB0aGUgZXhwZXJpbWVudCwKdGhlIHJhdHMgd2VyZSBkaXZpZGVkIGluIDEwIGhvbW9nZW5lb3VzIGdyb3VwcyBvZiA2IHJhdHMgYmFzZWQgb24KY2hhcmFjd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