knitr::opts_chunk$set(
  message = TRUE,
  warning = TRUE,
  collapse = TRUE,
  comment = "#>"
)

Simple Data Structures

Here, we'll use an example dataset taken from the metafor website, which also hosts the very famous metafor package.[@Viechtbauer2010-ss]

library(metafor)
library(concurve)
library(ggplot2)
dat.hine1989

I will quote Wolfgang (the creator of the metafor package) here, since he explains it best,

"As described under help(dat.hine1989), variables n1i and n2i are the number of patients in the lidocaine and control group, respectively, and ai and ci are the corresponding number of deaths in the two groups. Since these are 2×2 table data, a variety of different outcome measures could be used for the meta-analysis, including the risk difference, the risk ratio (relative risk), and the odds ratio (see Table III). Normand (1999) uses risk differences for the meta-analysis, so we will proceed accordingly. We can calculate the risk differences and corresponding sampling variances with:

dat <- escalc(measure = "RD", n1i = n1i, n2i = n2i, ai = ai, ci = ci, data = dat.hine1989)
dat

"Note that the yi values are the risk differences in terms of proportions. Since Normand (1999) provides the results in terms of percentages, we can make the results directly comparable by multiplying the risk differences by 100 (and the sampling variances by $100^{2}$):

dat$yi <- dat$yi * 100
dat$vi <- dat$vi * 100^2

We can fit a fixed-effects model with the following

fe <- rma(yi, vi, data = dat, method = "FE")

Now that we have our metafor object, we can compute the consonance function using the curve_meta() function.

fecurve <- curve_meta(fe, cores = 1L)

Now we can graph our function.

ggcurve(fecurve[[1]], nullvalue = TRUE)

We used a fixed-effects model here, but if we wanted to use a random-effects model, we could do so with the following, where we can specify a restricted maximum likelihood estimator (REML) for the random-effects model

re <- rma(yi, vi, data = dat, method = "REML")

And then we could use curve_meta() to get the relevant list

recurve <- curve_meta(re, cores = 1L)

Now we can plot our object.

ggcurve(recurve[[1]], nullvalue = TRUE)

We could also compare our two models to see how much consonance/overlap there is

curve_compare(fecurve[[1]], recurve[[1]], plot = TRUE)

The results are practically the same and we cannot actually see any difference, and the AUC % overlap also is consisten with this.

Complex Data Structures

concurve can also handle complex data structures from metafor that are clustered.

### copy data from Berkey et al. (1998) into 'dat'
dat <- dat.berkey1998

### construct list of the variance-covariance matrices of the observed outcomes for the studies
V <- lapply(split(dat[, c("v1i", "v2i")], dat$trial), as.matrix)

### construct block diagonal matrix
V <- bldiag(V)

### fit multivariate model
res <- rma.mv(yi, V, mods = ~ outcome - 1, random = ~ outcome | trial, struct = "UN", data = dat)

### results based on sandwich method
(a <- robust(res, cluster = dat$trial))

l <- concurve::curve_meta(res, method = "uni", robust = TRUE, cluster = dat$trial, adjust = TRUE, steps = 1000, cores = 1L)

ggcurve(data = l[[1]], type = "c") +
  ggplot2::theme_minimal()

The interval function is quite narrow because there were so many iterations that were set by us.

Here, we simulate a more complicated set of trials using the simstudy package.

library(simstudy)
library(parallel)
library(nlme)
library(data.table)
library(metafor)
library(concurve)

defS <- defData(varname = "a.k", formula = 3, variance = 2, id = "study")
defS <- defData(defS, varname = "d.0", formula = 3, dist = "nonrandom")
defS <- defData(defS, varname = "v.k", formula = 0, variance = 6, dist= "normal")
defS <- defData(defS, varname = "s2.k", formula = 16, variance = .2, dist = "gamma")
defS <- defData(defS, varname = "size.study", formula = ".3;.5;.2", dist = "categorical")
defS <- defData(defS, varname = "n.study",
                formula = "(size.study==1) * 20 + (size.study==2) * 40 + (size.study==3) * 60",
                dist = "poisson")

defI <- defDataAdd(varname = "y", formula = "a.k + x * (d.0 + v.k)", variance = "s2.k")

RNGkind(kind = "L'Ecuyer-CMRG")
set.seed(1031)

ds <- genData(12, defS)
ds

dc <- genCluster(ds, "study", "n.study", "id", )
dc <- trtAssign(dc, strata = "study", grpName = "x")
dc <- addColumns(defI, dc)


d.obs <- dc[, .(study, id,s2.k, x, y)]
d.obs <-  as.data.frame(d.obs)
res <- rma.mv(yi = y, V = s2.k, W = NULL, mods = ~  factor(study) + factor(x),  random = ~ factor(x) | study, struct="CS", data = d.obs, method = "REML")

a <- curve_meta(x = res, measure = "default", method = "mv", parm = "factor(x)1", cores = 1L)
ggcurve(a[[2]], type = "cdf")

Cite R packages

Please remember to cite the packages that you use.

citation("concurve")
citation("ggplot2")
citation("metafor")
citation("simstudy")
citation("nlme")
citation("data.table")
citation("parallel")

References




Zadchow/concurve documentation built on Jan. 11, 2024, 4:55 a.m.