# Variable with effect coding in conditional_effects()

Dear brms users,

For a psychological experiment, I have a mixed effect linear regression model with brms like…

model <- brm(DV ~ 1 + A + B + A:B + (1 + A + B + A:B | participant),…

Here, A is a categorical variable with two levels and B is a standardized continuous variable. I used effect coding for the categorical variable A (-1 and 1). This data frame recognises the effect coding variable as a continuous variable, not factor. Then, I wanna draw a figure with…

plot(conditional_effects(model, effects=“B:A”), points=TRUE)))

But the figure has three lines (with each 95%CRI) for A = -1, 1, and their mean 0, which are different colors. On the other hand, all plots are black. What I want is that the figure is depicted as A is referred as factor; coloring/grouping by levels of A for lines and plots.
So I tried…

g <- plot(conditional_effects(model, effects=“B:A”), points=TRUE)
g <- g + geom_points(aes(colour=factor(A)))
g

But not well-worked. Also I tried…

cond = data.frame(A = c(-1, 1))
plot(conditional_effects(model, conditions = cond, effects=“B:A”), points=TRUE)

But same two figures out alongside and they had no change from the original figure. Would someone tell me how to solve this?

I need keep this type of effect coding. Of course, the simplest way is that I look for a way to translate variable A to factorial variable with effect coding of -1 and +1 before estimation and re-estimate it (is there such way?). But I have many other model with the same problem and re-estimation need super long time. I don’t wanna do it.

My environment

• Operating System: MacOS Mojave 10.14.6
• brms Version: 2.13.5
• R Version: 3.6.3
• Rstudio Version: 1.3.1056

Thank you very much,
Yutani

I think the only solution is to recode your variable A to sum coding prior to fitting the model. This can be done by using

``contrasts(your_data_frame\$A) = contr.sum(2)``

“This data frame recognises the effect coding variable as a continuous variable, not factor.” If you want to use the `conditional_effects()` function, it might be easiest to save your `A` variable as a factor and refit the model. If you prefer to keep the data as they are, you might be better off using the `fitted()` function.

Thank you for replying. I didn’t know the contrast function! Thank you very much!!

Thank you for replying. I understand that as you and @andymilne said, `contrasts()` function before estimation is the way for `conditional_effects()` function.

I didn’t think about `fitted()` function. I will play with it!! Thank you very much!!

1 Like