Mean-centered variables in brms

Hello!

I am trying to model a behavioral task using brms. There are two independent variables (each with two levels), and I am interested mostly in the interaction effect (var1*var2). Task responses were made on a discrete scale so I chose cumulative().

model_fit <- brm(response ~ var1*var2 + (var1*var2|participant), data = data, family = cumulative(), iter = 5000, chains = 4)

After fitting the model, I checked the stan function call and the stan model using make_standata() and stancode(). The two variables were coded as 0 and 1 instead of mean-centered -0.5 and 0.5 in the stan() function call. The predictors were then centered inside the stan model.

transformed data {
  matrix[N, Kc] Xc;  // centered version of X
  vector[Kc] means_X;  // column means of X before centering
  for (i in 1:K) {
    means_X[i] = mean(X[, i]);
    Xc[, i] = X[, i] - means_X[i];
  }
}

Centered predictors (Xc) were used for the group-level parameters (b), but uncentered predictors (Z_1_1 to Z_1_4) were used for individual-level parameters.

vector[N] mu = rep_vector(0.0, N);
mu += Xc * b; // centered, group-level
for (n in 1:N) {
      // add more terms to the linear predictor
      mu[n] += r_1_1[J_1[n]] * Z_1_1[n] + r_1_2[J_1[n]] * Z_1_2[n] + r_1_3[J_1[n]] * Z_1_3[n] + r_1_4[J_1[n]] * Z_1_4[n]; // uncentered, individual-level
}
for (n in 1:N) {
      target += ordered_logistic_lpmf(Y[n] | mu[n], Intercept);
}

So just wondering what the reason is for using different predictors for group- and individual-level parameters? And will this difference significantly impact the fitting results?

Thanks for answering my question!

Hey @REYZ. I have a 3-part blog series on exactly this topic. Here’s the link to the first post in the series: Learn Stan with brms, Part I | A. Solomon Kurz. However, the third post is the one that focuses most directly on your question: Learn Stan with brms, Part III | A. Solomon Kurz.

Thank you for answering my question! The blogs are very helpful!

I have another question after reading the blogs.

I found that in brms the predictors for the interaction effect are calculated first before mean-centering. For example, when the 2 by 2 condition cells are coded as

var1  var2
1     1
1     0
0     1
0     0

The interaction effect is first calculated as var1*var2

interaction
1
0
0
0

before mean centering (interaction = interaction - mean(interaction))

var1  var2
0.5   0.5
0.5   -0.5
-0.5  0.5
-0.5  -0.5

interaction
0.75
-0.25
-0.25
-0.25

But in many linear regression models, the interaction effect is usually mean-centered first and then calculated, resulting in a different interaction effect predictor pattern.

var1  var2
0.5   0.5
0.5   -0.5
-0.5  0.5
-0.5  -0.5

interaction
0.25
-0.25
-0.25
0.25

Is there any difference in modeling with these two types of interaction effects, and if so, which type should I adopt?

Thank you!

I’m not aware there’s a meaningful difference, but I haven’t looked closely into that issue. I’d recommend coding through a data set both ways, fitting the models, and comparing them.

Thank you!