1

I am trying to use the package 'mitml' in R to calculate R squared measures for a multilevel model. I have tried using lme4 and nlme to specify my models. However, when I use lme4 to specify the model the R squared values are the same across all 4 calculations (not what I would expect) and when I use nlme I am getting an error. Here is the code I am using to specify the model across both packages:

lme4: H1 <- lmer(PAA_groupmc ~ Velocity.difference+(1|mydata$ID), data=mydata)

nlme: h1.1 <- lme(PAA_groupmc ~ Velocity.difference, data=mydata, random = ~1|ID, method="REML")

PAA_groupmc and Velocity.difference are both continuous variables, and ID is a factor that represents each person since I have a repeated-measures dataset. I have allowed for random intercepts by person.

When I run multilevelR2(H1) I get the following results: RB1: 0.1004472
RB2: 0.1004472
SB: 0.1004472
MVP: 0.1013596

Question 1: I think it is strange that the results are so similar, as I would not expect that to be the case. Can someone explain why that could happen or what I might be doing wrong?

Question 2: When I run multilevelR2(h1.1) I get the following error:

Error in multilevelR2(h1.1):Calculation of R-squared statistics not supported for models of class

What does this error mean and how can I address it?

  • Is there any chance we can have a [mcve]? This might turn out to be more appropriate for [CrossValidated](https://stats.stackexchange.com) ... – Ben Bolker Sep 13 '20 at 15:41

1 Answers1

1

For your second question, the error looks like a bug in mitml::multilevelR2, which misinterprets the lme object as a list of models (and then can't find an appropriate class for the first element of the list); you can work around it via

mitml:::.getRsquared(<your_model>,
                     print=c("RB1", "RB2", "SB", "MVP"), 
                     method="nlme")

Note that the startup message for the package does say

*** This is beta software. Please report any bugs!

The "issues" (bug-reporting) list for the package is here ...

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Thank you, Ben! Your solution worked for me. Interestingly, by using a model specified with the nlme package, my first question might also be solved. When specifying the same model using nlme, my RB2 value changed to -.06. All others stayed the same, so I would interpret this by assuming that the mitml package doesn't interact nicely with the lme4 package. – Victoria Whitaker Sep 18 '20 at 16:11
  • I'm glad it worked. If you think you've found problems with the package I *strongly* encourage you to report them to the developers, on the issues list linked above ... – Ben Bolker Sep 18 '20 at 16:13
  • I submitted both the error message and the finding that the RB2 estimates are different depending on whether the model was specified in lme4 or nlme. Thanks for the tips! – Victoria Whitaker Sep 18 '20 at 18:29