0
$\begingroup$

I fit a mixed effect model to one set of data and now I want to check its performance when applied to another data set. I want to plot a figure of "predicted value" and "observed value" and calculate $R^2$ to evaluate model performance.

Is there any code or command for this in R software?

$\endgroup$
1
$\begingroup$

If you fitted your model using the lme4 library, the documentation (listed under the function plot.merMod) suggests the following:

data(Orthodont,package="nlme")
fm1 <- lmer(distance ~ age + (age|Subject), data=Orthodont)

## standardized residuals versus fitted values by gender
plot(fm1, resid(., scaled=TRUE) ~ fitted(.) | Sex, abline = 0)
| cite | improve this answer | |
$\endgroup$
0
$\begingroup$

plot(fm1) also works with the lme function. If you calculate R^2 as

cor(Orthodont$age, predict(fm1))^2

keep in mind that it is in fact only a pseudo R^2 as it does not account for the random structure. Alternatively you can calculate marginal and conditional R^2 as described here:

http://jslefche.wordpress.com/2013/03/13/r2-for-linear-mixed-effects-models/ and http://aghaynes.wordpress.com/2013/03/28/mixed-model-r2/

This is the publication that describes it in detail

Nakagawa, S., and H. Schielzeth. 2013. A general and simple method for obtaining R2 from generalized linear mixed-effects models. Methods in Ecology and Evolution 4(2): 133-142.

There is also a package called lmmfit although I haven't used it, yet

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.