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.
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}\]
# Models Tag {2}, {3}, and {4} are linear regressions. The reason that disqualifies model tag{1} from being a multiple regression is that it only has one predictor variable.
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.
# a: Animal Diversity predictor variable
# p: Plant Diversity controlling variable
# The model would be:
# μi=α+β_aai+β_pp_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.
# f: Funding amount
# s: Size of laboratory
# The beta (β) slope parameters for f and s should be both positive.
# The model would be:
# μi=α+β_ffi+β_ss_i
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}\]
# All models but Tag {2} are inferentially equivalent to include the categorical variable in a regression. Tag {2} includes a slope for every category of the predictor, thus not inferencially equivalent.
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).
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.
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?
# The prediction of having more divorces in a larger amount of marriages makes sense. Naturally, more single individuals getting married within a given population feeds the group of married couples that could get divorced due to having a higher number of couples who likely won't have a successful relationship. Then, the hypothesis could be a revert of the previous statement, where higher divorce rate could predict higher marriage rate. The growth of the divorce rate will provide more single people to the population who might consider getting re-married. Adding up the re-married and freshly married couples would grow the divorce rate as more couples get formed, which validates our initial hypothesis.
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.
# WaffleDivorce: Data for the individual States of the United States, describing number of Waffle House diners and various marriage and demographic facts. This data will be used to answer the above question.
# LDS Population by state sourced from https://en.wikipedia.org/wiki/The_Church_of_Jesus_Christ_of_Latter-day_Saints_membership_statistics_(United_States)
data("WaffleDivorce")
DivData <- WaffleDivorce
DivData$LDS <- c(0.0077,0.0458,0.0600,0.0107,0.0191,0.0261,0.0045,0.0058,0.0045,0.0075,0.0082,0.0530,0.2586,0.0045,0.0068,0.0090,0.0132,0.0080,0.0064,0.0082,0.0072,0.0041,0.0045,0.0059,0.0073,0.0118,0.0473,0.0130,0.0065,0.0038,0.0331,0.0043,0.0085,0.0152,0.0054,0.0124,0.0364,0.0041,0.0040,0.0080,0.0120,0.0077,0.0125,0.6632,0.0074,0.0113,0.0380,0.0096,0.0047,0.1170)
# Transforming predictors:
DivData$LDS_stdr <- (DivData$LDS - mean(DivData$LDS)) / sd(DivData$LDS)
DivData$MedianAgeMarriage_stdr <- (DivData$MedianAgeMarriage - mean(DivData$MedianAgeMarriage)) / sd(DivData$MedianAgeMarriage)
DivData$Marriage_stdr <- (DivData$Marriage - mean(DivData$Marriage)) / sd(DivData$Marriage)
Model5M4 <- map(
alist( Divorce ~ dnorm(mean = md, sd = sigma),
md <- a + mar * Marriage_stdr + mm * MedianAgeMarriage_stdr + clds * LDS_stdr,
a ~ dnorm(mean = 0, sd = 100),
c(mar, mm, clds) ~ dnorm(mean = 0, sd = 5),
sigma ~ dunif(min = 0, 5)
),
data = DivData
)
precis(Model5M4)
## mean sd 5.5% 94.5%
## a 9.6879682 0.1893676 9.3853223 9.9906142
## mar 0.0138378 0.2873700 -0.4454349 0.4731105
## mm -1.3710455 0.2795719 -1.8178554 -0.9242355
## clds -0.6254973 0.2261705 -0.9869615 -0.2640331
## sigma 1.3390335 0.1339088 1.1250214 1.5530455
# The results reveal that the states with lower percentage of LDS members have higher divorce rate, similarly to the states with lower median age at marriage.
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.
# We can try to set up a multiple regression that take into account these 2 mechanisms. With the variable gas price "P" in hand, the 2 mechanisms can be represented through the following 2 variables:
# "M": representing the amount of movement/exercise done by the studied population over a period of time.
# "C": representing the calories intake from restaurant eating over the same period of time.
# This leaves us with the following regression model:
# μi=α+βPPi+βMMi+βCCi