Chapter 5 - Many Variables and Spurious Waffles

This chapter introduced multiple regression, a way of constructing descriptive models for how the mean of a measurement is associated with more than one predictor variable. The defining question of multiple regression is: What is the value of knowing each predictor, once we already know the other predictors? The answer to this question does not by itself provide any causal information. Causal inference requires additional assumptions. Simple directed acyclic graph (DAG) models of causation are one way to represent those assumptions.

Place each answer inside the code chunk (grey box). The code chunks should contain a text response or a code that completes/answers the question or activity requested. Make sure to include plots if the question requests them. Problems are labeled Easy (E), Medium (M), and Hard(H).

Finally, upon completion, name your final output .html file as: YourName_ANLY505-Year-Semester.html and publish the assignment to your R Pubs account and submit the link to Canvas. Each question is worth 5 points.

Questions

5E1. Which of the linear models below are multiple linear regressions? \[\begin{align} {μ_i = α + βx_i} \tag{1}\\ μ_i = β_xx_i + β_zz_i \tag{2} \\ μ_i = α + β(x_i − z_i) \tag{3} \\ μ_i = α + β_xx_i + β_zz_i \tag{4} \\ \end{align}\]

# {2},{3},{4}

5E2. Write down a multiple regression to evaluate the claim: Animal diversity is linearly related to latitude, but only after controlling for plant diversity. You just need to write down the model definition.

# Considering AD as animal diversity and PD as plant diversity:
# μ_i = α + β_ADAD_i + β_PDPD_i

5E3. Write down a multiple regression to evaluate the claim: Neither amount of funding nor size of laboratory is by itself a good predictor of time to PhD degree; but together these variables are both positively associated with time to degree. Write down the model definition and indicate which side of zero each slope parameter should be on.

# Considering AF as amount funded and SL as size of the lab:

# μ_i = α + β_AFAF_i + β_SLSL_i

# slopes shoould be positive

5E4. Suppose you have a single categorical predictor with 4 levels (unique values), labeled A, B, C and D. Let Ai be an indicator variable that is 1 where case i is in category A. Also suppose Bi, Ci, and Di for the other categories. Now which of the following linear models are inferentially equivalent ways to include the categorical variable in a regression? Models are inferentially equivalent when it’s possible to compute one posterior distribution from the posterior distribution of another model. \[\begin{align} μ_i = α + β_AA_i + β_BB_i + β_DD_i \tag{1} \\ μ_i = α + β_AA_i + β_BB_i + β_CC_i + β_DD_i \tag{2} \\ μ_i = α + β_BB_i + β_CC_i + β_DD_i \tag{3} \\ μ_i = α_AA_i + α_BB_i + α_CC_i + α_DD_i \tag{4} \\ μ_i = α_A(1 − B_i − C_i − D_i) + α_BB_i + α_CC_i + α_DD_i \tag{5} \\ \end{align}\]

# {1},{3},{4},{5}

5M1. Invent your own example of a spurious correlation. An outcome variable should be correlated with both predictor variables. But when both predictors are entered in the same model, the correlation between the outcome and one of the predictors should mostly vanish (or at least be greatly reduced).

# Collisions on bicycles rise when ice cream sales rise.
# Hotter weather might be the reason that cause more people exercise outdoor and eat more ice cream.
# Collisions rises when more people go biking outside.

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.

# Hours of studying and sleep on GPA. Hours of studying is positively associated with GPA. 
# Research has shown that not enough sleep results in a lower gpa. Students who spend more time
# studying might sacrifice their sleep to study more.

5M3. It is sometimes observed that the best predictor of fire risk is the presence of firefighters— States and localities with many firefighters also have more fires. Presumably firefighters do not cause fires. Nevertheless, this is not a spurious correlation. Instead fires cause firefighters. Consider the same reversal of causal inference in the context of the divorce and marriage data. How might a high divorce rate cause a higher marriage rate? Can you think of a way to evaluate this relationship, using multiple regression?

# A similar reversal of causal inference is possible as divorced people can go back to dating and
# marry again. Number of previous marriage could be included as a predictor in multiple regression.

5M4. In the divorce data, States with high numbers of members of the Church of Jesus Christ of Latter-day Saints (LDS) have much lower divorce rates than the regression models expected. Find a list of LDS population by State and use those numbers as a predictor variable, predicting divorce rate using marriage rate, median age at marriage, and percent LDS population (possibly standardized). You may want to consider transformations of the raw percent LDS variable.

library(rethinking)
data(WaffleDivorce)
d <- WaffleDivorce

# Data retrieved from Wikipedia page "The Church of Jesus Christ of Latter-day Saints membership
# statistics (United States)" on 12/9/2020 (removed Nevada data to match WaffleDivorce)
d$pct_LDS <- c(0.77, 4.58, 6.00, 1.07, 1.91, 2.61, 0.45, 0.58, 0.45,
0.75, 0.82, 5.30, 25.86, 0.45, 0.68, 0.90, 1.32, 0.80, 0.64, 0.82, 0.72, 0.41, 0.45, 0.59, 0.73, 1.18, 4.73, 1.30, 0.65, 0.38, 3.31, 0.43, 0.85, 1.52, 0.54, 1.24, 3.64, 0.41, 0.40, 0.80, 1.20, 0.77, 1.25, 66.32, 0.74, 1.13, 3.80, 0.96, 0.47, 11.70 )

m <- quap( 
  alist(
    Divorce ~ dnorm(mu,sigma),
    mu <- a + br*Marriage + ba*MedianAgeMarriage + bp*pct_LDS, 
    a ~ dnorm(0,100),
    c(br,ba,bp) ~ dnorm(0,10),
    sigma ~ dunif(0,10)
  ),
  data=d ) 

precis( m )
##               mean         sd       5.5%       94.5%
## a     38.457058654 6.92724363 27.3859854 49.52813191
## br     0.004679828 0.07573113 -0.1163531  0.12571280
## ba    -1.099605124 0.22472378 -1.4587571 -0.74045313
## bp    -0.063234958 0.02284595 -0.0997472 -0.02672271
## sigma  1.339008432 0.13390287  1.1250058  1.55301108
# The median age at marriage or percent LDS population are negatively associated with divorce
# rates. However, the percent LDS population might at the same time have an impact on the other
# predictor variables. We might need to further investigate degree of covariance among them.

5M5. One way to reason through multiple causation hypotheses is to imagine detailed mechanisms through which predictor variables may influence outcomes. For example, it is sometimes argued that the price of gasoline (predictor variable) is positively associated with lower obesity rates (outcome variable). However, there are at least two important mechanisms by which the price of gas could reduce obesity. First, it could lead to less driving and therefore more exercise. Second, it could lead to less driving, which leads to less eating out, which leads to less consumption of huge restaurant meals. Can you outline one or more multiple regressions that address these two mechanisms? Assume you can have any predictor data you need.

# μ_i = α + β_GASGAS_i + β_EXEEXE_i + β_RESRES_i

# Where GAS represents the price of gasoline, EXE represents the exercise variable and RES represents the restaurant variable.