[R-meta] Meta-regression with nonlinear and factorial moderators
Cesar Terrer Moreno
cesar.terrer at me.com
Thu Mar 15 09:17:22 CET 2018
Dear all,
Based on model selection, I have an effect size that is driven by two moderators: a continuous “C” and a factorial “F”:
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, but staying at 0 even when C is very high.
Previously, you guys helped me define a nonlinear meta-regression for C of the form: y ~ p1 × exp(-p2*x), with x=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 this myself in my entire life, so I really appreciate the help. However, now I don’t really know how to modify this code to accommodate F.
My question is: how can I incorporate a factorial moderator in these functions?
Many thanks in advance
César
[[alternative HTML version deleted]]
More information about the R-sig-meta-analysis
mailing list