# [R-meta] R^2 in nonlinear model

Viechtbauer Wolfgang (SP) wolfgang.viechtbauer at maastrichtuniversity.nl
Thu Mar 1 18:23:19 CET 2018

```If you want an R^2-type value, you could use the same approach that is typically used in regular meta-regression:

Fit the model with p2 constrained to 0; save the estimate of tau^2. Call this tau^2_RE.
Fit the model with p2 left free to estimate; save the estimate of tau^2. Call this tau^2_ME.

Then R^2 = (tau^2_RE - tau^2_ME) / tau^2_RE.

It's the proportional reduction in the amount of heterogeneity when 'x' is added as a predictor. Or in other words, it indicates how much of the total amount of heterogeneity is accounted for by 'x'.

I wouldn't think of this as indicating 'goodness of fit' though.

Best,
Wolfgang

>-----Original Message-----
>From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces at r-
>project.org] On Behalf Of Cesar Terrer Moreno
>Sent: Thursday, 01 March, 2018 17:15
>To: r-sig-meta-analysis at r-project.org
>Subject: [R-meta] R^2 in nonlinear model
>
>Dear all,
>
>I am using a nonlinear meta-regression of the form y ~ p1 * exp(-p2*A):
>
>nlfun <- function(x, p1, p2)
>  p1 * exp(-p2*x)
>
># optimization function
>llfun <- function(par, yi, vi, x, random=TRUE) {
>  p1 <- par[1]
>  p2 <- par[2]
>  if (random) {
>    tau2 <- exp(par[3])
>  } else {
>    tau2 <- 0
>  }
>  mu <- nlfun(x, p1, p2)
>  -sum(dnorm(yi, mean=mu, sd=sqrt(vi + tau2), log=TRUE))
>}
>
># optimize
>res <- optim(par=c(8,0.4,log(.01)), llfun, yi=am.df\$es, vi=am.df\$var,
>x=am.df\$CNr, hessian=TRUE)
>
>My question is: how can I compute something equivalent to R^2 that I can
>report to have an idea of the goodness of the fit?
>Thanks

```