33  Regression models: interactions

polite <- read_csv("data/winter2012/polite.csv")
f0_bm_int <- brm(
  f0mn ~ gender + attitude + gender:attitude,
  family = gaussian,
  data = polite,
  cores = 4,
  seed = 7123,
  file = "cache/ch-regression-interaction_f0_bm_int"
)
summary(f0_bm_int)
 Family: gaussian 
  Links: mu = identity; sigma = identity 
Formula: f0mn ~ gender + attitude + gender:attitude 
   Data: polite (Number of observations: 212) 
  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             256.56      5.20   246.38   267.27 1.00     2632     2950
genderM              -119.38      7.66  -134.08  -104.50 1.00     2532     2665
attitudepol           -17.48      7.28   -31.76    -3.18 1.00     2573     2806
genderM:attitudepol     6.65     10.67   -14.20    27.47 1.00     2191     2693

Further Distributional Parameters:
      Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
sigma    39.10      1.94    35.52    43.14 1.00     3834     2779

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_effects(f0_bm_int, "gender:attitude")

f0_bm_int_draws <- as_draws_df(f0_bm_int)
f0_bm_int_draws <- f0_bm_int_draws |> 
  mutate(
    f_inf = b_Intercept,
    f_pol = b_Intercept + b_attitudepol,
    m_inf = b_Intercept + b_genderM,
    m_pol = b_Intercept + b_genderM + b_attitudepol + `b_genderM:attitudepol`
  )
library(posterior)
This is posterior version 1.6.1

Attaching package: 'posterior'
The following objects are masked from 'package:stats':

    mad, sd, var
The following objects are masked from 'package:base':

    %in%, match
f0_bm_int_draws |> 
  mutate(
    m_pol_inf = m_pol - m_inf
  ) |> 
  summarise(
    mean_diff = mean(m_pol_inf), sd_diff = sd(m_pol_inf),
    lo_diff = quantile2(m_pol_inf, probs = 0.025), hi_diff = quantile2(m_pol_inf, probs = 0.975)
  ) |>
  round()