Multiple Predictor Models with Rethinking
Models from McElreath
5E2. Write down a multiple regression to evaluate the claim: Animal diversity is linearly related to plant productivity (more food, more animal species), but only after controlling for latitude. Assume these are z-standardized variables. You just need to write down the model definition. Stretch your wings by doing this in markdown with LaTeX. See here, here, and this little cheat.
Draw the DAG with dagitty and the rethinking::drawdag()
function.
Some Conceptual Thoughts from McElreath
5M2. Invent your own example of a masked relationship. An outcome variable should be correlated with both predictor variables, but in opposite directions. And the two predictor variables should be correlated with one another. Draw the DAG with dagitty and the rethinking::drawdag()
function.
McElreath gets Foxy!
For the following, we will use the data(foxes)
(part of rethinking). The urban fox (Vulpes vulpes) is a successful exploiter of human habitat. Since urban foxes move in packs and defend territories, data on habitat quality and population density is also included. The data frame has five columns:
- group: Number of the social group the individual fox belongs to
- avgfood: The average amount of food available in the territory
- groupsize: The number of foxes in the social group
- area: Size of the territory
- weight: Body weight of the individual fox
5H2. Fit a multiple linear regression with weight as the outcome and both area and group size as predictor variables. You can standardize the variables if you wish. Plot the predictions of the model for each predictor, holding the other predictor constant at its mean. Use tidybayes
and tidybayes.rethinking
for this with linpred_draws()
. What does this model say about the importance of each variable?
Categoricals
With data(milk)
, build a model explaing the kcal.per.g of milk with 2 continuous predictors of your choice and clade. Plot the effect of clade controlling for continuous predictors (which you can standardize). If you want to go wild, try and make some of the SLOPES clade specific. Hey, you’ve got an interaction. Use tidybayes
and tidybayes.rethinking
with linpred_draws()
for this. Can you plot clade-specific effects? (Note, you do not need to do this part - just leaving it there as a challenge and an opportunity.)
Go Causal from McElreath
6H1. Use the Waffle House data, data(WaffleDivorce), to find the total causal influence of number of Waffle Houses on divorce rate. Justify your model or models with a causal graph. You can fit an SEM here and calculate direct and indirect effects. If you want to show the causal graph in R, use dagitty and be sure to check out the drawdag()
function in rethinking