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 = β_xx_i + β_zz_i \tag{3} \\ μ_i = α + β(x_i − z_i) \tag{4} \\ μ_i = α + β_xx_i + β_zz_i \tag{5} \\ \end{align}\]
#2,3,4,5
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.
# μ_i = α + βlLi + βpPi
#Where L is latitude and P is plant diversity
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.
# μ_i = α + βfFi + βlLi
#Where F is amount of funding and L is size of laboratory
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).
N<- 100
MR<-rnorm(n=N,mean=0,sd=0.5)
A<- rnorm(n=N, mean=0, sd=0.5)
DR <- rnorm(n=N,mean=0,sd=0.2)
d<- data.frame (DR,A,MR)
pairs(d)
m<- quap(
alist(
DR ~dnorm (mu,sigma),
mu<- a + bMR*MR ,
a ~ dnorm (0,0.2),
bMR ~ dnorm (0,0.5),
sigma ~dexp (1)
), data=d
)
precis (m)
## mean sd 5.5% 94.5%
## a 0.02850103 0.01934976 -0.002423618 0.05942568
## bMR -0.03534729 0.03598118 -0.092852171 0.02215759
## sigma 0.19405733 0.01370048 0.172161309 0.21595335
m1<- quap(
alist(
DR ~dnorm (mu,sigma),
mu<- a + bMR*MR + bA*A,
a ~ dnorm (0,0.2),
bMR ~ dnorm (0,0.5),
bA ~dnorm (0,0.5),
sigma ~dexp (1)
), data=d
)
precis (m1)
## mean sd 5.5% 94.5%
## a 0.0284972925 0.01935843 -0.002441214 0.05943580
## bMR -0.0353516434 0.03599510 -0.092878769 0.02217548
## bA 0.0001247785 0.03944232 -0.062911665 0.06316122
## sigma 0.1940585337 0.01370070 0.172162173 0.21595489
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.
# My example is the prediction of happiness ratings of life from the the amount of time one works/studies hard and the amount of the time one feels tired
N<-100
rho<-0.6
study<- rnorm (n=N, mean =0, sd=1)
tired<- rnorm (n=N,mean=rho*study, sd=sqrt(1-rho^2))
happiness<-rnorm (n=N, mean=study-tired,sd=1)
d<-data.frame (happiness, study, tired)
pairs(d)
m1<-quap (
alist (
happiness ~ dnorm (mu,sigma),
mu<- a + bs*study,
a ~ dnorm (0,5),
bs ~ dnorm (0,5),
sigma ~ dunif(0,5)
), data=d
)
precis (m1)
## mean sd 5.5% 94.5%
## a -0.06678761 0.12715883 -0.27001199 0.1364368
## bs 0.25333774 0.11107031 0.07582593 0.4308495
## sigma 1.26357143 0.08934783 1.12077634 1.4063665
m2<-quap (
alist (
happiness ~ dnorm (mu,sigma),
mu<- a + bt*tired,
a ~ dnorm (0,5),
bt ~ dnorm (0,5),
sigma ~ dunif(0,5)
), data=d
)
precis (m2)
## mean sd 5.5% 94.5%
## a 0.005014908 0.12368790 -0.1926622 0.2026921
## bt -0.383756300 0.11718900 -0.5710470 -0.1964656
## sigma 1.231660287 0.08709137 1.0924715 1.3708491
m3<-quap (
alist (
happiness ~ dnorm (mu,sigma),
mu<- a + bs*study+bt*tired,
a ~ dnorm (0,5),
bs ~ dnorm (0,5),
bt ~ dnorm (0,5),
sigma ~ dunif(0,5)
), data=d
)
precis (m3)
## mean sd 5.5% 94.5%
## a -0.04720789 0.09848688 -0.2046090 0.1101932
## bs 0.88246603 0.11541651 0.6980082 1.0669239
## bt -1.02083930 0.12492994 -1.2205015 -0.8211771
## sigma 0.97824098 0.06917475 0.8676864 1.0887956
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?
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.
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 = α + βGGi + βEEi+βRRi
#Where G is the price of gasolie, E is an exercise variable, and R is a restaurant variable