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?
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 ...