[R-meta] Network meta-analysis with randomized and non-randomized studies in metafor

Chris Rose m@|||ng@||@t@ @end|ng |rom y@|etown@|o
Fri Feb 15 09:28:43 CET 2019


Many thanks, Wolfgang! I had tried something like that, but not exactly that :-)

Have a good weekend,

— Chris

> On 14 Feb 2019, at 23:32, Viechtbauer, Wolfgang (SP) <wolfgang.viechtbauer using maastrichtuniversity.nl> wrote:
> 
> Hi Chris,
> 
> That's not how 'newmods' works. This will work:
> 
> newvals <- c(1, 0, 0, 1)
> predict(res, newmods = newvals)
> 
> newvals <- c(1, 0, 0, 1)
> predict(res, newmods = newvals, tau2.levels="RS", gamma2.levels="RS")
> 
> To be more explicit:
> 
> newvals <- c("trt self_help" = 1, "trt ind_counseling" = 0, "trt grp_counseling" = 0, "typeRS" = 1)
> 
> Best,
> Wolfgang
> 
> -----Original Message-----
> From: R-sig-meta-analysis [mailto:r-sig-meta-analysis-bounces using r-project.org] On Behalf Of Chris Rose
> Sent: Thursday, 14 February, 2019 20:47
> To: r-sig-meta-analysis using r-project.org
> Subject: Re: [R-meta] Network meta-analysis with randomized and non-randomized studies in metafor
> 
> Hi Michael, all
> 
> I think I had actually tried your suggestion of constructing a matrix but did not include it my attempt in my original email. After exhausting a few alternatives that seemed sensible based on my reading of the docs, I started to try some “random stuff" in the hope that I would learn something purely by experimentation — unfortunately not.
> 
> I’ve included below an example from the beginning, which includes what I think you mean towards the end. It’d be great if you could have a look and tell me where I’m going wrong.
> 
> Best,
> 
> — Chris
> 
> ### load the library
> library(metafor)
> 
> ### copy data into 'dat'
> dat <- dat.hasselblad1998
> 
> ### calculate log odds for each study arm
> dat <- escalc(measure="PLO", xi=xi, ni=ni, add=1/2, to="all", data=dat)
> 
> ### convert trt variable to factor with desired ordering of levels
> dat$trt <- factor(dat$trt, levels=c("no_contact", "self_help", "ind_counseling", "grp_counseling"))
> 
> ### add a space before each level (this makes the output a bit more legible)
> levels(dat$trt) <- paste0(" ", levels(dat$trt))
> 
> ### simulate a RS/NRS moderator (type)
> set.seed(1234)
> dat$type <- rep(sample(c("RS", "NRS"), length(unique(dat$study)), replace=TRUE), times=tapply(dat$study, dat$study, length))
> 
> ### fit a meta-regression model
> res <- rma.mv(yi, vi, mods = ~ trt + type, random = list(~ type | study, ~ type | id), struct=c("DIAG","DIAG"), data=dat)
> 
> ### call predict without additional arguments
> predict(res) # This works!
> 
> ### make a matrix of moderator values at which to predict, and try to predict
> newvals <- as.matrix(c(trt = " self_help", type = "RS"))
> predict(res, newmods = newvals) # fails with...
> # Error in predict.rma(res, newmods = newvals) : 
> #   Dimensions of 'newmods' do not match dimensions of the model.
> 
> ### try to specify the tau and gamma levels
> predict(res, newmods = newvals, tau2.levels = "RS", gamma2.levels = "RS") # fails with...
> # Error in predict.rma(res, newmods = newvals, tau2.levels = "RS", gamma2.levels = "RS") : 
> #   Dimensions of 'newmods' do not match dimensions of the model.
> 
> ### is the matrix moderators incorrectly transposed?
> predict(res, newmods = t(newvals), tau2.levels = "RS", gamma2.levels = "RS") # fails with...
> # Error in dimnames(x) <- dn : 
> #   length of 'dimnames' [2] not equal to array extent


	[[alternative HTML version deleted]]



More information about the R-sig-meta-analysis mailing list