# [R-meta] Nonlinear meta-regression with factorial moderator

Cesar Terrer Moreno cesar.terrer at me.com
Mon Mar 19 15:57:18 CET 2018

```Dear all,

I have an effect size that is driven by two moderators: a continuous “C” and a factorial “F”. Let’s say, in this case, that C is temperature, while F is ecosystem type (e.g. grassland, forest, cropland):

rma(ES, VAR, data= dat, mods= ~ 1 + C + F)

The relationship between ES and C is nonlinear, with high ES when C is low, but ES quickly approaching 0 when C becomes higher towards infinite, but never becoming negative.

Previously, you guys helped me define a nonlinear meta-regression ES ~ C like: ES ~ p1 × exp(-p2*C), including a function to predict the nonlinear ES and SE.

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)
# back-transform log(tau2) to tau2
res\$par[3] <- exp(res\$par[3])
tau2_ME <- res\$par[3]

# fit model with tau2=0
res0 <- optim(par=c(8,0.4), llfun, yi=am.df\$es, vi=am.df\$var, x=am.df\$CNr, random=FALSE, hessian=TRUE)

# LRT of H0: tau2=0
x2 <- -2 * (res0\$value - res\$value)
x2 ### test statistic
pchisq(x2, df=1, lower.tail=FALSE) ### p-value

# compute standard errors
vb <- chol2inv(chol(res\$hessian))
se <- sqrt(diag(vb))

# ignore SE for tau2
se[3] <- NA

# estimates, standard errors, z-values, and p-values
data.frame(estimate=round(res\$par,4), se=round(se,4), zval=round(res\$par/se,3), pval=round(2*pnorm(abs(res\$par/se), lower.tail=FALSE),5), row.names=c("p1","p2","tau2"))

# Function to predict the nonlinear effect size (ES)
ESpred <- function(x) {
p1 <- res\$par[1]
p2 <- res\$par[2]
p1*exp(-p2*x)
}

# Function to predict the nonlinear standard error (SE)
SEpred <- function(x) {
p1 <- res\$par[1]
p2 <- res\$par[2]
g <- matrix(c(exp(-p2*x), -p1*exp(-p2*x)*x), ncol=1, nrow=2)
vb <- vb[1:2,1:2]
c(sqrt(t(g) %*% vb %*% g))
}

I wouldn’t be able to figure out how to model the nonlinear relationship ES ~ C in my entire life, so I really appreciate the help.

My question is: how can I incorporate a factorial moderator F in these functions to model ES ~ C + F.?