# R-squared of mixed model using lmmfit package

I am fitting my data using nlme package. The syntax is as follow:

 model<-lme(Energy efficiency ~ADF + CP + DE, random =~1|Study, data=phuong).


Can someone tell me how to find the R-squared for this model?.

I've found the lmmfit package of Aleksandra Maj (2011): But there are several functions to estimate R-squared. Could you please tell me which one should I apply.

fm2<-lme(Eeff~ADF+CP+DE+ADF2+DE2, random=~1|Study,data=na.omit(binh))
summary(fm2)
Linear mixed-effects model fit by REML
Data: na.omit(binh)
AIC      BIC    logLik
888.6144 915.1201 -436.3072

Random effects:
Formula: ~1 | Study
(Intercept) Residual
StdDev:    3.304345 1.361858

Fixed effects: Eeff ~ ADF + CP + DE + ADF2 + DE2
Value Std.Error  DF   t-value p-value
(Intercept)  -0.66390 18.870908 158 -0.035181  0.9720
ADF           1.16693  0.424561 158  2.748556  0.0067
CP            0.25723  0.097524 158  2.637575  0.0092
DE          -36.09593 12.031791 158 -3.000046  0.0031
ADF2         -0.03708  0.011014 158 -3.366625  0.0010
DE2           4.77918  1.932924 158  2.472513  0.0145
Correlation:
CP   -0.032  0.070
DE    0.978 -0.291 -0.043
DE2  -0.978  0.308  0.039 -0.997 -0.265

Standardized Within-Group Residuals:
Min          Q1         Med          Q3         Max
-2.28168116 -0.45260885  0.06528363  0.57071734  2.54144168

Number of Observations: 209
Number of Groups: 46

-
This question might be of interest. – Roland Nov 29 '12 at 16:41

Maybe I am stating some obvious but at the following link http://glmm.wikidot.com/faq under the section How do I compute a coefficient of determination (R2), or an analogue, for (G)LMMs? provides a quite good treatment of the issue. Just to quote some of the final lines from there to avoid possible link rot and provide the reference they present:

The bottom line is that there are some simple recipes (and some more complex recipes that may or may not have been coded up by someone), but that '''you have to think carefully about what information you want to get out of the coefficient of determination''', because no recipe will have all of the properties of $R^2$ in the simple linear model case.

A rather helpful reference of the subject seems to be Xu's: Measuring explained variation in linear mixed effects models (2003) where the author computes the residual variance of the full model against the residual variance of a (fixed) intercept-only null model (in R syntax): 1-var(residuals(m))/(var(model.response(model.frame(m)))

-

[Disclaimer: it has been a couple years since I have worked on a project using mixed effects models.]

A simple summary(model) should provide much of what you need. Check out this SE/CV answer which is a good example of how to extract the covariance estimates for the random effects, etc.

Word of advice: you probably need is available between lme, nlme, and lme4 -- I have never used lmmfit myself ...

Studying contribution of each param to variance in the response is not so straightforward with mixed effect models because of the random effects. The variance in your random intercept is contributing to that variance in your response. This is more of an art, and requires you to get familiar with the relationships in your data.

If you want to understand the contribution of each of the params to the variance in your response, you are better off building a full linear model with all the (scientifically relevant) params, then comparing with a statistic like Mallow's $C_{p}$. You need to rescale/center appropriately, to compare the structure of relationships between your variables (e.g., geometric?) You then need to pre-define your model selection procedure, and compare ML estimates between the models (not REML, as @Roland mentioned, because we want the "nuisance" random effects included when we are selecting our model based on BIC/AIC/etc. -- as opposed to our final REML estimate, where we want to understand the loglik of our fixed effects).

It sounds like you are new to mixed effects models; I would strongly suggest you work through all of Gelman's magnum opus -- tons of live R examples, clear explanations, only as much theory as you need to develop an intuition for the techniques.

-
Hi egbutter, thanks for your comments but I wonder how can you get R-squared with summary(model). An example I made is follow: – user12714 Nov 29 '12 at 14:13
I posted the example on my original post because I could not add it here in the "add comment" part. COuld you please have a look. – user12714 Nov 29 '12 at 14:17
Hi user12714, your output is very hard to read without the "code" {} formatting, but the "Correlation" line is what you want. Big warning: REML is not appropriate for "final" estimates but rather for model selection -- I strongly suggest you read Gelman before you get too deep into this project. – egbutter Nov 29 '12 at 14:38
Dear Egbutter, thank you very much again for your comments. yes, I could imagine the problem with the output, but I do not know why I could not pots in the commnent. Anyway, probably you misunderstood me about R-squared I need. I need to evaluate how well my model fit (explain the variation) the data. In fixed model it is given, but not mixed effect model – user12714 Nov 29 '12 at 14:52
@egbutter It is my understanding that ML fits should be used for model selection and a REML fit is appropriate for the estimation of parameters. – Roland Nov 29 '12 at 16:11