Modeling an interaction
In this exercise, you will use interactions to model the effect of gender and gastric activity on alcohol metabolism.
The alcohol data frame has been pre-loaded, and has the columns:
- Metabol: the alcohol metabolism rate
- Gastric: the rate of gastric alcohol dehydrogenase activity
- Sex: the sex of the drinker (- Maleor- Female)
In the video, we fit three models to the alcohol data: 
- one with only additive (main effect) terms : Metabol ~ Gastric + Sex
- two models, each with interactions between gastric activity and sex
You saw that one of the models with interaction terms had a better R-squared than the additive model, suggesting that using interaction terms gives a better fit. In this exercise, you will compare the R-squared of one of the interaction models to the main-effects-only model.
Recall that the operator : designates the interaction between two variables. The operator * designates the interaction between the two variables, plus the main effects.
x*y = x + y + x:y
Este exercício faz parte do curso
Supervised Learning in R: Regression
Instruções do exercício
- Write a formula that expresses Metabolas a function ofGastricandSexwith no interactions.- Assign the formula to the variable fmla_addand print it.
 
- Assign the formula to the variable 
- Write a formula that expresses Metabolas a function of the interaction betweenGastricandSex.- Add Gastricas a main effect, but notSex.
- Assign the formula to the variable fmla_interactionand print it.
 
- Add 
- Fit a linear model with only main effects: model_addto the data.
- Fit a linear model with the interaction: model_interactionto the data.
- Call summary()on both models. Which has a better R-squared?
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# alcohol is available
summary(alcohol)
# Create the formula with main effects only
(fmla_add <- ___ )
# Create the formula with interactions
(fmla_interaction <- ___ )
# Fit the main effects only model
model_add <- ___
# Fit the interaction model
model_interaction <- ___
# Call summary on both models and compare
___
___