8E1. For each of the causal relationships below, name a hypothetical third variable that would lead to an interaction effect.

  1. Bread dough rises because of yeast - conditional on room temperature
  2. Education leads to higher income - conditional on type of education
  3. Gasoline makes a car go - conditional on type of car (whether it is electric or not)

8E2. Which of the following explanations invokes an interaction?

  1. Caramelizing onions requires cooking over low heat and making sure the onions do not dry out.

We think number one invokes an interaction as caramelizing onions is conditional on both low heat and not drying out the onions. The others are additive relationships, as the predictors are all equally related to the outcome.

8E3. For each of the explanations in 8E2, write a linear model that expresses the stated relationship.

  1. Caramelized = α + β1 * heat * β 2 * dryness + β 1 * heat + β2 * dryness

  2. Political_beliefs = alpha + β1 * parent_opinion_beliefs + β2 * friend_beliefs

  3. Carspeed = alpha + β1 * cylinders + β2 * fuels

  4. Animalintelligence = alpha + β1 * socialtendencies + β2 * manipulativeappendages

8M1. Recall the tulips example from the chapter. Suppose another set of treatments adjusted the temperature in the greenhouse over two levels: cold and hot. The data in the chapter were collected at the cold temperature. You find none of the plants grown under the hot temperature developed any blooms at all, regardless of the water and shade levels. Can you explain this result in terms of interactions between water, shade, and temperature?

In the example there was an interaction between shade and water levels, under cold climate conditions. However, in this example, there is no blooming under hot climate conditions, regardless of shade and water levels. The effect of shade and water is therefore lost when the temperature is cold. The interaction between shade and water is conditional on temperature, making this a three-way interaction. No amount of shade or water will make the tuilps bloom when the temperatures are hot.

8M2. Can you invent a regression equation that would make the bloom size zero, whenever the temperature is hot?

Bloom = α + β1 * temperature * β2 * shade * β3 * water + β 1 * temperature + β 2 * shade + β3 * water

We can code temperature as a categorical variable with, 1 for cold, 0 for hot, and multiply the whole initial model. Then, if the temperature = 0, the model will lead no no blooming. At the same time, if temperature = 1, the model multiplies with 1 and this has no effect on the blooming.

8M3. In parts of North America, ravens depend upon wolves for their food. This is because ravens are carnivorous but cannot usually kill or open carcasses of prey. Wolves however can and do kill and tear open animals, and they tolerate ravens co-feeding at their kills. This species relationship is generally described as a “species interaction.” Can you invent a hypothetical set of data on raven population size in which this relationship would manifest as a statistical interaction? Do you think the biological interaction could be linear? Why or why not?

We could look at whether the population size of ravens would increase or decrease with the presence of wolves. Since they depend on wolves allowing them to co-feed, we would expect that the population size of ravens would be larger with more wolves. We could have a dataset with the population size of ravens and the population size of wolves. The wolf population size is not dependent on the raven population, but raven population is conditional on the wolf population. But this would be a simple correlation, and does not necessarily include an interaction. One could think that if the population size of ravens got too big, then the wolves would not tolerate too many ravens or that the ravens eat too much of their prey, or that the wolves start eating the ravens – thereby decreasing the raven population. So the relationship may not necessarily be linear.

8M4. Repeat the tulips analysis, but this time use priors that constrain the effect of water to be positive and the effect of shade to be negative. Use prior predictive simulation. What do these prior assumptions mean for the interaction prior, if anything?

We were not sure how to solve this, and how to set the prior to negative values for the effect of shade.

library(rethinking)
## Loading required package: rstan
## Loading required package: StanHeaders
## Loading required package: ggplot2
## rstan (Version 2.21.3, GitRev: 2e1f913d3ca3)
## For execution on a local, multicore CPU with excess RAM we recommend calling
## options(mc.cores = parallel::detectCores()).
## To avoid recompilation of unchanged Stan programs, we recommend calling
## rstan_options(auto_write = TRUE)
## Loading required package: cmdstanr
## Warning: package 'cmdstanr' was built under R version 4.0.5
## This is cmdstanr version 0.4.0
## - Online documentation and vignettes at mc-stan.org/cmdstanr
## - CmdStan path set to: /Users/linnssaether/.cmdstanr/cmdstan-2.29.0
## - Use set_cmdstan_path() to change the path
## 
## A newer version of CmdStan is available. See ?install_cmdstan() to install it.
## To disable this check set option or environment variable CMDSTANR_NO_VER_CHECK=TRUE.
## Loading required package: parallel
## rethinking (Version 2.21)
## 
## Attaching package: 'rethinking'
## The following object is masked from 'package:rstan':
## 
##     stan
## The following object is masked from 'package:stats':
## 
##     rstudent
data(tulips)
d <- tulips

d$blooms_std <- d$blooms / max(d$blooms)
d$water_cent <- d$water - mean(d$water)
d$shade_cent <- d$shade - mean(d$shade)

a <- rnorm( 1e4 , 0.5 , 0.25 ); sum( a < 0 | a > 1 ) / length( a )
## [1] 0.0433
m8.4 <- quap(
    alist(
        blooms_std ~ dnorm( mu , sigma ) ,
        mu <- a + bw*water_cent + bs*shade_cent ,
        a ~ dnorm( 0.5 , 0.25 ) ,
        bw ~ dnorm( 0 , 0.25 ) ,
        bs ~ dnorm( 0 , 0.25 ) ,
        sigma ~ dexp( 1 )
) , data=d )