1

I'm trying to summarize a lmer model with sjPlot::tab_model. It works until I try to get "kr" p-values to also obtain degrees of freedom. I have pbkrtest installed, and can use it separately, but it's unsuccessfully called by tab_model. Does anyone know what I'm missing?

I ran a linear mixed effects model. I can generate a table using

tab_model(BWRTmod1b,show.stat = TRUE)

When I change the call to get p-values based on the Kenward-Roger approximated degrees of freedom like this:

tab_model(BWRTmod1b,p.val= "kr" ,show.stat = TRUE) 

I get the following error message:

Error in round(attr(pv, "df.kr", exact = TRUE)) : non-numeric argument to mathematical function

I have googled the problem and the only thing I found was a missing pbkrtest package, but that's not the case here. I also googled the error message itself and found that this can happen when a data frame is fed into a function that wants numerical input. I have also updated R and reinstalled/updated all packages and that didn't help.

I don't know whether and how I can fix this and it's also entirely possible that I am missing something else. Any hints would be appreciated.

Link to the model output

# working
tab_model(BWRTmod1b,show.stat = TRUE)

# not working
tab_model(BWRTmod1b,p.val= "kr" ,show.stat = TRUE) 

# long term goal
tab_model(BWRTmod1b,p.val= "kr", show.df=TRUE ,show.stat = TRUE) 

I expected to generate a table of my linear mixed effects model results that includes degrees of freedom. I can generate a table with a summary based on Wald approximation, but I cannot get the Kenward-Roger version with degrees of freedom.

  • I'm afraid this is more or less unanswerable without a [mcve]. I tried constructing some basic LMMs, even forcing one to be singular by making the data set very small, and haven't managed to generate your error so far. Do you get any warnings when fitting the model ... ? – Ben Bolker Aug 09 '19 at 01:44
  • Hi Ben, I got no error when fitting the model and I can tab it with the wald approximation. lmerTest gives me a reasonable summary, too, so I don't think there's anything wrong with the model (it converged fine and everything). Mhm. Let me see whether I can attach the model output somehow. – Romy Frömer Aug 09 '19 at 13:17
  • the link you posted needs permission ... – Ben Bolker Aug 09 '19 at 13:43
  • Oh man, sorry! I changed that. Is it working now? It should be. – Romy Frömer Aug 09 '19 at 13:57
  • Update: I refit the model after detaching lmerTest and that worked! – Romy Frömer Aug 09 '19 at 15:12
  • Hmm, I'm now puzzled trying to reproduce this/find an example where this *does* work ... – Ben Bolker Aug 09 '19 at 15:16
  • In case that helps, when I do the summary with KR df like you suggest below, it ignores the KR df argument, so that does not work, but the interface with tab_model does. – Romy Frömer Aug 09 '19 at 15:23
  • yes, but are you actually getting KR p-values? If you refit the model with `lmerTest` attached, I don't think you can get KR values ... ? I'm pretty deeply confused at this point. I think it might be worth posting an issue on the issues list for sjPlot ... – Ben Bolker Aug 09 '19 at 15:30
  • Oh I think you misunderstood me: I refit it WITHOUT lmerTest. So lmerTest was the issue and when I detached it, it worked. – Romy Frömer Aug 09 '19 at 15:36
  • Hmm. I'm still not sure I get it. In case you need it: https://github.com/strengejacke/sjPlot/issues – Ben Bolker Aug 09 '19 at 15:37
  • Thanks! I actually put it up there yesterday, too: https://github.com/strengejacke/sjPlot/issues/446 – Romy Frömer Aug 09 '19 at 15:39

1 Answers1

0

This turns out to be a bug/infelicitous interaction between the lmerTest and sjPlot packages. Reproducible example:

library(lmerTest)
fm3 <- lmer(Reaction ~ Days + (Days|Subject), sleepstudy,
            REML=TRUE)
sjPlot::tab_model(fm3,p.val="kr")
## Error in round(attr(pv, "df.kr", exact = TRUE)) : 
## non-numeric argument to mathematical function

whereas the same thing works if you start with library(lme4) instead of library(lmerTest). It should now be fixed in the development version of sjPlot

Not sure how this interacts with REML=TRUE ...

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Huh! Before detaching lmerTest, I tried fitting REML and that didn't work, while now I'm fitting with REML= FALSE, just without lmerTest and it works. – Romy Frömer Aug 09 '19 at 15:19