1

I'm using the tab_model function in sjPlot in r. This function normally works smoothly for me, however, I noticed that the output table is oddly ordering variables in an order other than is in the lmer output.

Data at the bottom of the question.

Here is my working r code

#Packages that are currently loaded
library(lmerTest)
library(sjPlot)
library(sjlabelled)

##Run model

model <- lmer(depvar ~ predictor1*predictor2 + covariate1 + covariate2 + (1|id), data = exampledata)
summary(model)

#Make table

table <- tab_model(model)

enter image description here

enter image description here

I know that one solution is to reorder the predictors manually, however, this is not optimal, because I also want to assign labels to the predictors, and when i try to do both, the labels are assigned in the default, as opposed to manually redone, order.

Any leads on why my table is being printed in an order other than the lmer output would be most appreciated!

Thank you in advance for any ideas you might have!

Michael


Data:

exampledata <- structure(list(X = c(142L, 51L, 720L, 730L, 664L, 826L, 605L, 
587L, 216L, 75L, 862L, 928L, 935L, 972L, 724L, 840L, 506L, 771L, 
393L, 14L, 592L, 62L, 635L, 572L, 800L, 36L, 744L, 971L, 166L, 
649L, 901L, 975L, 723L, 145L, 895L, 1017L, 677L, 570L, 106L, 
451L, 1018L, 13L, 735L, 579L, 433L, 586L, 56L, 363L, 889L, 504L
), id = c(202L, 139L, 662L, 671L, 610L, 751L, 566L, 554L, 270L, 
153L, 773L, 819L, 831L, 858L, 665L, 759L, 494L, 707L, 402L, 110L, 
556L, 145L, 592L, 542L, 729L, 130L, 683L, 858L, 221L, 600L, 797L, 
862L, 665L, 204L, 793L, 889L, 624L, 541L, 175L, 453L, 889L, 110L, 
678L, 548L, 440L, 552L, 141L, 381L, 789L, 492L), predictor1 = c(1L, 
0L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 
0L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 
0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 
0L), predictor2 = c(0.5, -0.5, -0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 
0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 
-0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 
0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 
0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, 0.5), covariate1 = c(2L, 
-1L, -1L, -1L, -1L, -1L, -1L, 2L, 2L, -1L, 2L, -1L, -1L, -1L, 
-1L, -1L, -1L, -1L, -1L, -1L, 2L, 2L, -1L, -1L, -1L, -1L, -1L, 
-1L, -1L, -1L, 2L, 2L, -1L, -1L, 2L, -1L, -1L, -1L, -1L, -1L, 
-1L, -1L, -1L, -1L, 2L, 2L, -1L, 2L, -1L, 2L), covariate2 = c(0L, 
-1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, -1L, 1L, 1L, -1L, 
-1L, 1L, 1L, -1L, 0L, 0L, 1L, -1L, 1L, -1L, -1L, 1L, 1L, -1L, 
0L, 0L, 1L, -1L, 0L, -1L, -1L, 1L, -1L, 1L, -1L, -1L, 1L, -1L, 
0L, 0L, 1L, 0L, 1L, 0L), depvar = c(25, 16.6666666666667, 66.6666666666667, 
33.3333333333333, 41.6666666666667, 0, 8.33333333333333, 25, 
83.3333333333333, 58.3333333333333, 91.6666666666667, 33.3333333333333, 
41.6666666666667, 0, 0, 41.6666666666667, 33.3333333333333, 50, 
100, 16.6666666666667, 100, 66.6666666666667, 25, 66.6666666666667, 
50, NA, 16.6666666666667, 0, 8.33333333333333, 16.6666666666667, 
75, 58.3333333333333, 0, 41.6666666666667, 50, 16.6666666666667, 
16.6666666666667, 0, 50, 50, 25, 8.33333333333333, 41.6666666666667, 
41.6666666666667, 41.6666666666667, 50, 66.6666666666667, 58.3333333333333, 
50, 50)), row.names = c(NA, -50L), class = "data.frame")
Community
  • 1
  • 1
Mikey
  • 11
  • 2
  • 1
    You are much more likely to get a useful answer with a reproducible example. You can make one with a built-in dataset, like `mtcars` or `sleepstudy` (from `lme4`). – Axeman Jan 23 '20 at 22:51
  • Thanks @Axeman. I created a stripped version of my code and uploaded a csv file. Oddly, when I use an open data source, the error is not occurring. I tried it with the code below, which worked fine. #Load sample data mlmdata <- read_dta("https://stats.idre.ucla.edu/stat/examples/imm/imm10.dta") #run model model <- lmer(math ~ homework*white + ses + race + sex + (1 | schid), data=mlmdata) summary(model) table <- tab_model(model, show.stat=TRUE, show.p=TRUE) – Mikey Jan 23 '20 at 23:24
  • Can you please post your package versions? Your described bug should have been fixed in parameters 0.4.0 (https://cran.r-project.org/web/packages/parameters/news/news.html) – Daniel Jan 24 '20 at 15:52
  • Thanks, Daniel. I was using parameters 0.4.1 but sjPlot 2.8.1. I just updated sjPlot and voila, it is fixed! THANK YOU for all that you do, and for your responsiveness! – Mikey Jan 24 '20 at 16:06

1 Answers1

0

Underlying problem is not sjPlot, but rather parameters::model_parameters. This is what is used under the hood and gives the odd ordering:

parameters::model_parameters(model)
Parameter               | Coefficient |   SE |           95% CI |     t |    df |      p
----------------------------------------------------------------------------------------
(Intercept)             |       41.08 | 3.82 | [ 33.59,  48.58] | 10.75 | 42.14 | < .001
predictor1              |        3.62 | 2.72 | [ -1.72,   8.95] |  1.33 |  2.78 | > .1  
predictor1 * predictor2 |       -2.60 | 5.46 | [-13.31,   8.11] | -0.48 |  2.74 | > .1  
covariate1              |        8.85 | 2.67 | [  3.62,  14.09] |  3.31 | 41.15 | < .001
predictor2              |       -5.78 | 7.68 | [-20.84,   9.28] | -0.75 | 41.27 | > .1  
covariate2              |        1.39 | 4.34 | [ -7.13,   9.90] |  0.32 | 40.89 | > .1

This misordering happens somewhere in the bowels of parameters (specifically in parameters:::.extract_parameters_mixed). My guess is that it is a bug. An issue could be filed on Github.

Axeman
  • 32,068
  • 8
  • 81
  • 94
  • Thank you! That is really helpful. Will try to file the bug there. Very appreciative of your kindness and help. – Mikey Jan 24 '20 at 00:28