[R-meta] R^2 in nonlinear model
Cesar Terrer Moreno
cesar.terrer at me.com
Thu Mar 1 19:23:16 CET 2018
Hi Wolfgang,
Thanks so much for your response. Please let me know if my code is correct:
res <- optim(par=c(8,0.4,log(.01)), llfun, yi=am.df$es, vi=am.df$var, x=am.df$CNr, hessian=TRUE)
res$par[3] <- exp(res$par[3])
tau2_ME <- res$par[3]
resp0 <- optim(par=c(8,0.4,log(.01)), llfun, yi=am.df$es, vi=am.df$var, x=0, hessian=TRUE)
resp0$par[3] <- exp(resp0$par[3])
tau2_RE <- resp0$par[3]
> (tau2_RE - tau2_ME) / tau2_RE
[1] 0.9999999
Does this 99% R^2 make sense?
Best,
César
> On 1 Mar 2018, at 18:23, Viechtbauer Wolfgang (SP) <wolfgang.viechtbauer at maastrichtuniversity.nl> wrote:
>
> 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
More information about the R-sig-meta-analysis
mailing list