Introduction to Bayesian Linear Models

04 - Interactions

Stefano Coretta

University of Edinburgh

Interactions: the traditional way

brm_4 <- brm(
  # RT ~ IsWord + PhoneLev + IsWord:PhonLev
  RT ~ IsWord * PhonLev,
  family = gaussian,
  data = mald,
  cores = 4,
  file = "data/cache/brm_4",
  seed = my_seed
)

Interactions: the traditional way (model summary)

brm_4
 Family: gaussian 
  Links: mu = identity; sigma = identity 
Formula: RT ~ IsWord * PhonLev 
   Data: mald (Number of observations: 3000) 
  Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
         total post-warmup draws = 4000

Regression Coefficients:
                    Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
Intercept             756.43     46.72   664.91   847.91 1.00     1659     2339
IsWordFALSE           233.39     67.38    99.57   364.92 1.01     1435     1596
PhonLev                31.85      6.52    19.11    44.57 1.00     1633     2368
IsWordFALSE:PhonLev   -14.36      9.30   -32.23     4.09 1.00     1409     1692

Further Distributional Parameters:
      Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma   339.71      4.26   331.39   348.18 1.00     2936     2600

Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).

Interactions: no intercept

brm_4a <- brm(
  RT ~ 0 + IsWord + IsWord:PhonLev,
  family = gaussian,
  data = mald,
  cores = 4,
  file = "data/cache/brm_4a",
  seed = my_seed
)

Interactions: no intercept (model summary)

brm_4a
 Family: gaussian 
  Links: mu = identity; sigma = identity 
Formula: RT ~ 0 + IsWord + IsWord:PhonLev 
   Data: mald (Number of observations: 3000) 
  Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
         total post-warmup draws = 4000

Regression Coefficients:
                    Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
IsWordTRUE            757.23     48.11   659.92   849.49 1.00     1809     1888
IsWordFALSE           989.60     49.66   893.35  1089.27 1.00     1776     1971
IsWordTRUE:PhonLev     31.75      6.71    18.79    44.99 1.00     1779     1948
IsWordFALSE:PhonLev    17.51      6.86     3.67    31.05 1.00     1839     1988

Further Distributional Parameters:
      Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma   339.52      4.29   330.97   347.98 1.00     2941     2292

Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
and Tail_ESS are effective sample size measures, and Rhat is the potential
scale reduction factor on split chains (at convergence, Rhat = 1).

Conditional posterior probabilities

conditional_effects(brm_4a, "PhonLev:IsWord")

Conditional posterior probabilities: spaghetti

brm_4a_condp <- conditional_effects(brm_4a, "PhonLev:IsWord", spaghetti = TRUE, ndraws = 100)
plot(brm_4a_condp, plot = FALSE, spaghetti_args = list(linewidth = 2))[[1]] +
  theme(
    plot.background = element_rect(fill = "black"),
    text = element_text(colour = "white")
  )

Conditional posteriors at specific values

conds <- tibble(
  PhonLev = c(7.5, 10),
  cond__ = c("PhonLev = 7.5", "PhonLev = 10")
)

conditional_effects(brm_4a, "IsWord", conditions = conds)

Comparisons (aka contrasts) at specific values

# library(marginaleffects)

comparisons(brm_4a, variables = "IsWord", newdata = datagrid(PhonLev = c(7.5, 10, 12)))

   Term     Contrast PhonLev Estimate 2.5 % 97.5 % IsWord
 IsWord FALSE - TRUE     7.5    125.8 100.3    151   TRUE
 IsWord FALSE - TRUE    10.0     90.0  31.2    150   TRUE
 IsWord FALSE - TRUE    12.0     62.1 -32.5    155   TRUE

Columns: rowid, term, contrast, estimate, conf.low, conf.high, PhonLev, predicted_lo, predicted_hi, predicted, tmp_idx, RT, IsWord 
Type:  response 

Comparisons (aka contrasts): 70% CrI

comparisons(brm_4a, variables = "IsWord", newdata = datagrid(PhonLev = c(7.5, 10, 12)), conf_level = 0.7)

   Term     Contrast PhonLev Estimate 15.0 % 85.0 % IsWord
 IsWord FALSE - TRUE     7.5    125.8  112.2    139   TRUE
 IsWord FALSE - TRUE    10.0     90.0   58.6    121   TRUE
 IsWord FALSE - TRUE    12.0     62.1   11.4    111   TRUE

Columns: rowid, term, contrast, estimate, conf.low, conf.high, PhonLev, predicted_lo, predicted_hi, predicted, tmp_idx, RT, IsWord 
Type:  response 

Comparisons (aka contrasts) along PhonLev

plot_comparisons(brm_4a, variables = "IsWord", condition = "PhonLev", conf_level = 0.7)

Posterior predictive checks

pp_check(brm_4a, ndraws = 100)