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.
Caramelized = α + β1 * heat * β 2 * dryness + β 1 * heat + β2 * dryness
Political_beliefs = alpha + β1 * parent_opinion_beliefs + β2 * friend_beliefs
Carspeed = alpha + β1 * cylinders + β2 * fuels
Animalintelligence = alpha + β1 * socialtendencies + β2 * manipulativeappendages
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.
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.
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.
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 )