guido-s / netmeta

Official Git repository of R package netmeta
http://cran.r-project.org/web/packages/netmeta/index.html
GNU General Public License v2.0
28 stars 12 forks source link

How should event, n and treat be inputted for pairwise? #1

Closed aaronxs closed 6 years ago

aaronxs commented 6 years ago

Hi,

I am trying to use the pairwise function but I am having trouble with the format of the inputs. Initially I have:

pairwise(treat = list(t1, t2, t3, t4), 
event = list(r1, r2, r3, r4), 
n = list(n1, n2, n3, n4), 
data = data)

But because the data I get sometime will have more/less than 4 arms. Is it possible to input the values for event, n and treat along the following lines?

# max number of arm in the studies
max.arm <- 4
t <- apply(datt[, paste0("t", 1:max.arm)], 2,  list)
r <- apply(datt[, paste0("r", 1:max.arm)], 2,  list)
n <- apply(datt[, paste0("n", 1:max.arm)], 2,  list)
pairwise(treat = t,  event = r, n = n)

Thank you! Aaron

guido-s commented 6 years ago

Dear Aaron,

In order to automate the input for pairwise() in such a way, you can use the long arm-based format in the following way.

max.arm <- 4
t <- unlist(apply(datt[, paste0("t", 1:max.arm)], 2,  list))
r <- unlist(apply(datt[, paste0("r", 1:max.arm)], 2,  list))
n <- unlist(apply(datt[, paste0("n", 1:max.arm)], 2,  list))
s <- rep(datt$study, max.arm)
pairwise(treat = t, event = r, n = n, studlab = s)

Note, you have to provide the study labels (argument 'studlab') if you use the long arm-based format.

Best wishes, Guido