title: Getting R squared from a mixed effects multilevel model in metafor
body: <p>I am doing a meta-analysis in R of a specific treatment on forests. For this model I need to fit random effects to account for between study differences in method and variation in age of sites, since both of these are confounding variables and I am not explicitly interested in investigating the variation caused by them. </p>
  
  <p>However, as far as I can tell the package <code>[metfor]</code> does not permit you to calculate a R squared type statistic when you have a multilevel model.</p>
  
  <p>Anyway, to describe my problem more clearly here is a mock dataset</p>
  
  <pre><code>Log&lt;-data.frame(Method=rep(c("RIL","Conv"),each=10),
       RU=runif(n=20,min=10,max=50),SDU=runif(n=20,5,20),
       NU=round(runif(n=20,10,20),0))
  Log$Study&lt;-rep(1:4,each=5)
  Log$Age&lt;-rep(c(0,10,15,10),times=5)
  RIL&lt;-(Log$RU-(Log$RU*(abs(rnorm(n=20,mean=.6,sd=0.1)))))+(0.5*Log$Age)
  Conv&lt;-(Log$RU-(Log$RU*(abs(rnorm(n=20,mean=.2,sd=0.1)))))+(0.2*Log$Age)
  Log$RL&lt;-ifelse(Log$Method=="RIL",RIL,Conv)
  Log$SDL&lt;-Log$SDU
  Log$NL&lt;-Log$NU
  
  #now we perform a meta-analysis using metafor
  require(metafor)
  ROM&lt;-escalc(data=Log,measure="ROM",m2i=RU,
  sd2i=SDU,n2i=NU,m1i=RL,sd1i=SDL,n1i=NL,append=T)
  Model1&lt;-rma.mv(yi,vi,random=~(1|Study)+(1|Age),method="ML",data=ROM)
  summary(Model1)
  forest(Model1)
  </code></pre>
  
  <p>The above model is a null model looking at whether the intercept is statistically significantly different from zero. In our case it is. However, I also want to see whether differences in treatments describe the differences in effect sizes I see on the forest plot that you can see here
  <img src="https://i.stack.imgur.com/jJLtd.png" alt="enter image description here"></p>
  
  <p>So I run this model:</p>
  
  <pre><code>Model2&lt;-rma.mv(yi,vi,mods=~Method,random=~(1|Study)+(1|Age),method="ML",data=ROM)
  summary(Model2)
  </code></pre>
  
  <p>Which looks good.</p>
  
  <pre><code>    Multivariate Meta-Analysis Model (k = 20; method: ML)
  
    logLik  Deviance       AIC       BIC      AICc  
    0.4725   19.8422    7.0550   11.0380    9.7217  
  
  Variance Components: 
  
  outer factor: Age   (nlvls = 3)
  inner factor: Study (nlvls = 4)
  
              estim    sqrt  fixed
  tau^2      0.0184  0.1357     no
  rho        1.0000             no
  
  Test for Residual Heterogeneity: 
  QE(df = 18) = 23.3217, p-val = 0.1785
  
  Test of Moderators (coefficient(s) 2): 
  QM(df = 1) = 19.6388, p-val &lt; .0001
  
  Model Results:
  
             estimate      se     zval    pval    ci.lb    ci.ub     
  intrcpt     -0.1975  0.1007  -1.9622  0.0497  -0.3948  -0.0002    *
  MethodRIL   -0.4000  0.0903  -4.4316  &lt;.0001  -0.5768  -0.2231  ***
  
  ---
  Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
  </code></pre>
  
  <p>However, I would like to get a goodness of fit measure out of this model equivalent to an R squared. People have had these problems in the past with GLMMs <a href="http://onlinelibrary.wiley.com/doi/10.1111/j.2041-210x.2012.00261.x/abstract" rel="noreferrer">but there are now ways of doing this</a>. I was wondering if anyone knew of a good way of doing something similar with meta-analyses? I have reviewers asking for this and I'm not sure whether I should just tell them that it can't be done or not.</p>
  
  <p>Thanks in advance for the help!</p>