cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
cbhalpern
Level III

Generating conditional and marginal R-squared for mixed models

I am running a series of mixed models in JMP 16 (one random effect, multiple fixed effects). 

I would like to generate estimates of:

  1. Marginal R^2 (R^2m):  the proportion of variance explained by the fixed effects relative to the overall variance 
  2. Conditional R^2 (R^2c): the proportion of variance explained by both fixed and random effects relative to the overall variance 

Is there a script readily available? 

In addition, how does JMP compute the R^2 and adjusted R^2 in the "Summary of Fit" tab in the Fit Model report for a mixed model?

 

Note regarding conditional and marginal R^2: The method proposed by Nakagawa & Schielzeth (2013) applies to random intercept models. Johnson (2014) proposed an extension for models that include random slopes (see also Nakagawa, Schielzeth, & Johnson 2017).

 

Johnson, P. C. D. 2014. Extension of Nakagawa & Schielzeth’s R2GLMM to random slopes models. Methods in Ecology and Evolution 5: 944–46. doi:10.1111/2041-210X.12225.

Nakagawa, S., & 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–42. doi:10.1111/j.2041-210x.2012.00261.x.

Nakagawa, S., H. Schielzeth, & P. C. D. Johnson. 2017. The coefficient of determination R2 and intra-class correlation coefficient from generalized linear mixed-effects models revisited and expanded. Journal of the Royal Society Interface 14(134). doi:10.1098/rsif.2017.0213.

28 REPLIES 28
cbhalpern
Level III

Re: Generating conditional and marginal R-squared for mixed models

Hello again. A follow up to our recent conversation. I have compared the variance components (VCs) in column 2 of Table 2 from the Nakagawa paper with those from JMP based on the test data set (running a mixed model or a SLS model with REML). In the JMP output, I am able to find all of the variance components required to produce the marginal and conditional R^2 values of Nakagawa, except for the variance associated with the fixed effects (equals 1.809 in column 2 of Table 2). Can JMP's LMM or SLS produce that variance estimate for the fixed effects?

Thanks.  

peng_liu
Staff

Re: Generating conditional and marginal R-squared for mixed models

JMP does not produce the quantity.

After looking at it again, I think that I have figured it out for you. The link http://samcarcagno.altervista.org/stat_notes/r2_lmm_jags/r_squared_lmm.html that you provided has the clue.

It all happens after the lmer call. Then you should see this:

peng_liu_0-1647383347455.png

Notice lmeFit@pp$X is the design matrix of the fixed effect together with the intercept. fixef(lmeFit) returns the fixed effect estimates.

So the first line of code is calculating the predictions (excluding intercept) for every row in the data using the estimates.

Then the second line of code is calculating the sample variance of what come from above. And this is their sigma_f^2. So it is not what I thought it was after all.

cbhalpern
Level III

Re: Generating conditional and marginal R-squared for mixed models

Thank you, but unfortunately, I don't use R (which has scripts to produce the marginal and conditional R^2 directly).

 

peng_liu
Staff

Re: Generating conditional and marginal R-squared for mixed models

Just use the Predicted value (not Cond Pred value) and calculate the variance:

peng_liu_0-1647391308481.png

 

cbhalpern
Level III

Re: Generating conditional and marginal R-squared for mixed models

Wonderful, thank you. That matches the value in Table 2.  Much appreciated.

Re: Generating conditional and marginal R-squared for mixed models

I have a question related to this topic, is there a link to show how JMP computes the reported RSquare with REML?
peng_liu
Staff

Re: Generating conditional and marginal R-squared for mixed models

The following was copied from one of my early replies in this thread. The calculation is the same as what should be done in ANOVA, but just pay attention to what predicted value you should use. In addition, I think that it is better to open up a different post to ask the question, and you may refer to this thread if it is related. That way should be better than burying the question in a long thread. And you get a better chance to be helped.

 

To answer how JMP gets R^2. Run the script embedded in the data table to bring up the report. And go to platform menu and use "Save Columns" -> "Conditional Pred Values" to save predictions. Now you get R^2 the same way as you get one from a linear least square model. Formula is here Summary of Fit . E.g. you need responses and predictions to get residuals and calculate sum of squares of errors SSE; you need responses and their mean to calculate sum of squares of total SST. Then R^2 is (SST - SSE)/SST. And here is my proof of calculation:

peng_liu_0-1646925016549.png

Re: Generating conditional and marginal R-squared for mixed models

Thank you very much for the reply! I did see your answer in the thread but I thought that was to match Conditional Rsquare in R.  

Re: Generating conditional and marginal R-squared for mixed models

Ok I see now I didn't go back far enough in the thread.  Thank you for your patience!