rlme4sjplot

Multi-level modelling with lmer plotting interactions with sjPlot


I am running a multi-level model with two continuous level 2 predictors (A and B) and a dichotomous level 1 predictor (cond, coded -1 and 1). Y is the dependent variable.

M2<-lmer(Y ~ 1 + (1|subject) + A*cond + B*cond, data, na.action = na.omit)
summary(M2)
tab_model(M2)

This yields the following:

Output

I'm already confused by what it means that the interaction term is written A x cond one time but cond x B the other time.

And when I'm plotting the interactions using:

plot_model(M2, type = c("int"), terms = "Pred*Mod", mdrt.values = c("minmax", "meansd", "zeromax", "quart", "all"), ci.lvl = NA)

For "A x cond" I get a plot with A on the x-axis, for "cond x B" I get a plot with cond on the x-axis.

A x cond cond x B

I would like two plots for each interaction. So for the first case, I would also like one that has cond on the x-axis, for the second case one that has B on the x-axis. I realize this might be a really basic thing but somehow I haven't been able to do it. I would really appreciate any help with this!

EDIT: Here's a link to download the complete data.

EDIT2: And here's a snippet of the data:

    structure(list(subject = c(66, 66, 66, 66, 66, 66, 66, 66, 66, 
66, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 61, 61, 61, 61, 61, 
61, 61, 61, 61, 61, 67, 67, 67, 67, 67, 67, 67, 67, 67, 67, 59, 
59, 59, 59, 59, 59, 59, 59, 59, 59, 64, 64, 64, 64, 64, 64, 64, 
64, 64, 64, 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, 62, 62, 62, 
62, 62, 62, 62, 62, 62, 62, 60, 60, 60, 60, 60, 60, 60, 60, 60, 
60, 69, 69, 69, 69, 69, 69, 69, 69, 69, 69), cond = c("1", "1", 
"1", "1", "1", "-1", "-1", "-1", "-1", "-1", "1", "1", "1", "1", 
"1", "-1", "-1", "-1", "-1", "-1", "1", "1", "1", "1", "1", "-1", 
"-1", "-1", "-1", "-1", "1", "1", "1", "1", "1", "-1", "-1", 
"-1", "-1", "-1", "1", "1", "1", "1", "1", "-1", "-1", "-1", 
"-1", "-1", "1", "1", "1", "1", "1", "-1", "-1", "-1", "-1", 
"-1", "1", "1", "1", "1", "1", "-1", "-1", "-1", "-1", "-1", 
"1", "1", "1", "1", "1", "-1", "-1", "-1", "-1", "-1", "1", "1", 
"1", "1", "1", "-1", "-1", "-1", "-1", "-1", "1", "1", "1", "1", 
"1", "-1", "-1", "-1", "-1", "-1"), Y = c(2, 4, 2, 2, 4, 4, 5, 
4, 4, 4, 1, 1, 3, 2, 3, 4, 5, 2, 4, 5, 3, 1, 4, 2, 4, 4, 5, 5, 
5, 5, 3, 3, 3, 4, 3, 2, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 3, 1, 2, 3, 3, 3, 1, 4, 5, 3, 1, 1, 4, 3, 5, 2, 4, 
3, 2, 1, 1, 2, 4, 5, 2, 5, 5, 1, 1, 3, 4, 4, 6, 5, 6, 3, 2, 2, 
2, 4, 3, 3, 4, 4, 5, 4, 5), A = c(-0.83201581027668, -0.83201581027668, 
-0.83201581027668, -0.83201581027668, -0.83201581027668, -0.83201581027668, 
-0.83201581027668, -0.83201581027668, -0.83201581027668, -0.83201581027668, 
3.16798418972332, 3.16798418972332, 3.16798418972332, 3.16798418972332, 
3.16798418972332, 3.16798418972332, 3.16798418972332, 3.16798418972332, 
3.16798418972332, 3.16798418972332, -1.83201581027668, -1.83201581027668, 
-1.83201581027668, -1.83201581027668, -1.83201581027668, -1.83201581027668, 
-1.83201581027668, -1.83201581027668, -1.83201581027668, -1.83201581027668, 
3.16798418972332, 3.16798418972332, 3.16798418972332, 3.16798418972332, 
3.16798418972332, 3.16798418972332, 3.16798418972332, 3.16798418972332, 
3.16798418972332, 3.16798418972332, 0.16798418972332, 0.16798418972332, 
0.16798418972332, 0.16798418972332, 0.16798418972332, 0.16798418972332, 
0.16798418972332, 0.16798418972332, 0.16798418972332, 0.16798418972332, 
-4.83201581027668, -4.83201581027668, -4.83201581027668, -4.83201581027668, 
-4.83201581027668, -4.83201581027668, -4.83201581027668, -4.83201581027668, 
-4.83201581027668, -4.83201581027668, -1.83201581027668, -1.83201581027668, 
-1.83201581027668, -1.83201581027668, -1.83201581027668, -1.83201581027668, 
-1.83201581027668, -1.83201581027668, -1.83201581027668, -1.83201581027668, 
-2.83201581027668, -2.83201581027668, -2.83201581027668, -2.83201581027668, 
-2.83201581027668, -2.83201581027668, -2.83201581027668, -2.83201581027668, 
-2.83201581027668, -2.83201581027668, -5.83201581027668, -5.83201581027668, 
-5.83201581027668, -5.83201581027668, -5.83201581027668, -5.83201581027668, 
-5.83201581027668, -5.83201581027668, -5.83201581027668, -5.83201581027668, 
-3.83201581027668, -3.83201581027668, -3.83201581027668, -3.83201581027668, 
-3.83201581027668, -3.83201581027668, -3.83201581027668, -3.83201581027668, 
-3.83201581027668, -3.83201581027668), B = c(1.78853754940711, 
1.78853754940711, 1.78853754940711, 1.78853754940711, 1.78853754940711, 
1.78853754940711, 1.78853754940711, 1.78853754940711, 1.78853754940711, 
1.78853754940711, 2.78853754940711, 2.78853754940711, 2.78853754940711, 
2.78853754940711, 2.78853754940711, 2.78853754940711, 2.78853754940711, 
2.78853754940711, 2.78853754940711, 2.78853754940711, 1.78853754940711, 
1.78853754940711, 1.78853754940711, 1.78853754940711, 1.78853754940711, 
1.78853754940711, 1.78853754940711, 1.78853754940711, 1.78853754940711, 
1.78853754940711, 1.78853754940711, 1.78853754940711, 1.78853754940711, 
1.78853754940711, 1.78853754940711, 1.78853754940711, 1.78853754940711, 
1.78853754940711, 1.78853754940711, 1.78853754940711, -1.21146245059289, 
-1.21146245059289, -1.21146245059289, -1.21146245059289, -1.21146245059289, 
-1.21146245059289, -1.21146245059289, -1.21146245059289, -1.21146245059289, 
-1.21146245059289, 1.78853754940711, 1.78853754940711, 1.78853754940711, 
1.78853754940711, 1.78853754940711, 1.78853754940711, 1.78853754940711, 
1.78853754940711, 1.78853754940711, 1.78853754940711, 0.788537549407114, 
0.788537549407114, 0.788537549407114, 0.788537549407114, 0.788537549407114, 
0.788537549407114, 0.788537549407114, 0.788537549407114, 0.788537549407114, 
0.788537549407114, 7.78853754940711, 7.78853754940711, 7.78853754940711, 
7.78853754940711, 7.78853754940711, 7.78853754940711, 7.78853754940711, 
7.78853754940711, 7.78853754940711, 7.78853754940711, -0.211462450592886, 
-0.211462450592886, -0.211462450592886, -0.211462450592886, -0.211462450592886, 
-0.211462450592886, -0.211462450592886, -0.211462450592886, -0.211462450592886, 
-0.211462450592886, -4.21146245059289, -4.21146245059289, -4.21146245059289, 
-4.21146245059289, -4.21146245059289, -4.21146245059289, -4.21146245059289, 
-4.21146245059289, -4.21146245059289, -4.21146245059289)), row.names = c(221L, 
222L, 223L, 224L, 225L, 226L, 227L, 228L, 229L, 230L, 701L, 702L, 
703L, 704L, 705L, 706L, 707L, 708L, 709L, 710L, 841L, 842L, 843L, 
844L, 845L, 846L, 847L, 848L, 849L, 850L, 1501L, 1502L, 1503L, 
1504L, 1505L, 1506L, 1507L, 1508L, 1509L, 1510L, 2131L, 2132L, 
2133L, 2134L, 2135L, 2136L, 2137L, 2138L, 2139L, 2140L, 2141L, 
2142L, 2143L, 2144L, 2145L, 2146L, 2147L, 2148L, 2149L, 2150L, 
2221L, 2222L, 2223L, 2224L, 2225L, 2226L, 2227L, 2228L, 2229L, 
2230L, 3541L, 3542L, 3543L, 3544L, 3545L, 3546L, 3547L, 3548L, 
3549L, 3550L, 5041L, 5042L, 5043L, 5044L, 5045L, 5046L, 5047L, 
5048L, 5049L, 5050L, 5051L, 5052L, 5053L, 5054L, 5055L, 5056L, 
5057L, 5058L, 5059L, 5060L), class = "data.frame")

Solution

  • I finally found the solution.

    M2<-lmer(Y ~ 1 + (1|subject) + A + B + cond + A:cond + B:cond, data, na.action = na.omit)
    summary(M2)
    tab_model(M2)
    

    Enter predictors and interaction terms separately and the categorical predictor last. Then using plot_model(M2, type = c("int")) will yield plots with the continuous predictor on the x axis.