The function converts summary data in vector format to the corresponding long format.

to.long(measure, ai, bi, ci, di, n1i, n2i, x1i, x2i, t1i, t2i,
        m1i, m2i, sd1i, sd2i, xi, mi, ri, ti, sdi, ni, data, slab, subset,
        add=1/2, to="none", drop00=FALSE, vlong=FALSE, append=TRUE, var.names)

Arguments

measure

a character string to specify the effect size or outcome measure corresponding to the summary data supplied. See ‘Details’ and the documentation of the escalc function for possible options.

ai

vector to specify the \(2 \times 2\) table frequencies (upper left cell).

bi

vector to specify the \(2 \times 2\) table frequencies (upper right cell).

ci

vector to specify the \(2 \times 2\) table frequencies (lower left cell).

di

vector to specify the \(2 \times 2\) table frequencies (lower right cell).

n1i

vector to specify the group sizes or row totals (first group/row).

n2i

vector to specify the group sizes or row totals (second group/row).

x1i

vector to specify the number of events (first group).

x2i

vector to specify the number of events (second group).

t1i

vector to specify the total person-times (first group).

t2i

vector to specify the total person-times (second group).

m1i

vector to specify the means (first group or time point).

m2i

vector to specify the means (second group or time point).

sd1i

vector to specify the standard deviations (first group or time point).

sd2i

vector to specify the standard deviations (second group or time point).

xi

vector to specify the frequencies of the event of interest.

mi

vector to specify the frequencies of the complement of the event of interest or the group means.

ri

vector to specify the raw correlation coefficients.

ti

vector to specify the total person-times.

sdi

vector to specify the standard deviations.

ni

vector to specify the sample/group sizes.

data

optional data frame containing the variables given to the arguments above.

slab

optional vector with labels for the studies.

subset

optional (logical or numeric) vector to specify the subset of studies that should included in the data frame returned by the function.

add

see the documentation of the escalc function.

to

see the documentation of the escalc function.

drop00

see the documentation of the escalc function.

vlong

optional logical whether a very long format should be used (only relevant for \(2 \times 2\) or \(1 \times 2\) table data).

append

logical to specify whether the data frame specified via the data argument (if one has been specified) should be returned together with the long format data (the default is TRUE).

var.names

optional vector with variable names (length depends on the data type). If unspecified, the function sets appropriate variable names by default.

Details

The escalc function describes a wide variety of effect size or outcome measures that can be computed for a meta-analysis. The summary data used to compute those measures are typically contained in vectors, each element corresponding to a study. The to.long function takes this information and constructs a long format dataset from these data.

For example, in various fields (such as the health and medical sciences), the response variable measured is often dichotomous (binary), so that the data from a study comparing two different groups can be expressed in terms of a \(2 \times 2\) table, such as:

outcome 1outcome 2total
group 1aibin1i
group 2cidin2i

where ai, bi, ci, and di denote the cell frequencies (i.e., the number of people falling into a particular category) and n1i and n2i the row totals (i.e., the group sizes).

The cell frequencies in \(k\) such \(2 \times 2\) tables can be specified via the ai, bi, ci, and di arguments (or alternatively, via the ai, ci, n1i, and n2i arguments). The function then creates the corresponding long format dataset. The measure argument should then be set equal to one of the outcome measures that can be computed based on this type of data, such as "RR", "OR", "RD" (it is not relevant which specific measure is chosen, as long as it corresponds to the specified summary data). See the documentation of the escalc function for more details on the types of data formats available.

The long format for data of this type consists of two rows per study, a factor indicating the study (default name study), a dummy variable indicating the group (default name group, coded as 1 and 2), and two variables indicating the number of individuals experiencing outcome 1 or outcome 2 (default names out1 and out2). Alternatively, if vlong=TRUE, then the long format consists of four rows per study, a factor indicating the study (default name study), a dummy variable indicating the group (default name group, coded as 1 and 2), a dummy variable indicating the outcome (default name outcome, coded as 1 and 2), and a variable indicating the frequency of the respective outcome (default name freq).

The default variable names can be changed via the var.names argument (must be of the appropriate length, depending on the data type).

The examples below illustrate the use of this function.

Value

A data frame with either \(k\), \(2 \times k\), or \(4 \times k\) rows and an appropriate number of columns (depending on the data type) with the data in long format. If append=TRUE and a data frame was specified via the data argument, then the data in long format are appended to the original data frame (with rows repeated an appropriate number of times).

Author

Wolfgang Viechtbauer wvb@metafor-project.org https://www.metafor-project.org

References

Viechtbauer, W. (2010). Conducting meta-analyses in R with the metafor package. Journal of Statistical Software, 36(3), 1--48. https://doi.org/10.18637/jss.v036.i03

See also

Examples

### convert data to long format dat <- to.long(measure="OR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg) dat
#> trial author year tpos tneg cpos cneg ablat alloc study #> 1 1 Aronson 1948 4 119 11 128 44 random 1 #> 2 1 Aronson 1948 4 119 11 128 44 random 1 #> 3 2 Ferguson & Simes 1949 6 300 29 274 55 random 2 #> 4 2 Ferguson & Simes 1949 6 300 29 274 55 random 2 #> 5 3 Rosenthal et al 1960 3 228 11 209 42 random 3 #> 6 3 Rosenthal et al 1960 3 228 11 209 42 random 3 #> 7 4 Hart & Sutherland 1977 62 13536 248 12619 52 random 4 #> 8 4 Hart & Sutherland 1977 62 13536 248 12619 52 random 4 #> 9 5 Frimodt-Moller et al 1973 33 5036 47 5761 13 alternate 5 #> 10 5 Frimodt-Moller et al 1973 33 5036 47 5761 13 alternate 5 #> 11 6 Stein & Aronson 1953 180 1361 372 1079 44 alternate 6 #> 12 6 Stein & Aronson 1953 180 1361 372 1079 44 alternate 6 #> 13 7 Vandiviere et al 1973 8 2537 10 619 19 random 7 #> 14 7 Vandiviere et al 1973 8 2537 10 619 19 random 7 #> 15 8 TPT Madras 1980 505 87886 499 87892 13 random 8 #> 16 8 TPT Madras 1980 505 87886 499 87892 13 random 8 #> 17 9 Coetzee & Berjak 1968 29 7470 45 7232 27 random 9 #> 18 9 Coetzee & Berjak 1968 29 7470 45 7232 27 random 9 #> 19 10 Rosenthal et al 1961 17 1699 65 1600 42 systematic 10 #> 20 10 Rosenthal et al 1961 17 1699 65 1600 42 systematic 10 #> 21 11 Comstock et al 1974 186 50448 141 27197 18 systematic 11 #> 22 11 Comstock et al 1974 186 50448 141 27197 18 systematic 11 #> 23 12 Comstock & Webster 1969 5 2493 3 2338 33 systematic 12 #> 24 12 Comstock & Webster 1969 5 2493 3 2338 33 systematic 12 #> 25 13 Comstock et al 1976 27 16886 29 17825 33 systematic 13 #> 26 13 Comstock et al 1976 27 16886 29 17825 33 systematic 13 #> group out1 out2 #> 1 1 4 119 #> 2 2 11 128 #> 3 1 6 300 #> 4 2 29 274 #> 5 1 3 228 #> 6 2 11 209 #> 7 1 62 13536 #> 8 2 248 12619 #> 9 1 33 5036 #> 10 2 47 5761 #> 11 1 180 1361 #> 12 2 372 1079 #> 13 1 8 2537 #> 14 2 10 619 #> 15 1 505 87886 #> 16 2 499 87892 #> 17 1 29 7470 #> 18 2 45 7232 #> 19 1 17 1699 #> 20 2 65 1600 #> 21 1 186 50448 #> 22 2 141 27197 #> 23 1 5 2493 #> 24 2 3 2338 #> 25 1 27 16886 #> 26 2 29 17825
### extra long format dat <- to.long(measure="OR", ai=tpos, bi=tneg, ci=cpos, di=cneg, data=dat.bcg, vlong=TRUE) dat
#> trial author year tpos tneg cpos cneg ablat alloc study #> 1 1 Aronson 1948 4 119 11 128 44 random 1 #> 2 1 Aronson 1948 4 119 11 128 44 random 1 #> 3 1 Aronson 1948 4 119 11 128 44 random 1 #> 4 1 Aronson 1948 4 119 11 128 44 random 1 #> 5 2 Ferguson & Simes 1949 6 300 29 274 55 random 2 #> 6 2 Ferguson & Simes 1949 6 300 29 274 55 random 2 #> 7 2 Ferguson & Simes 1949 6 300 29 274 55 random 2 #> 8 2 Ferguson & Simes 1949 6 300 29 274 55 random 2 #> 9 3 Rosenthal et al 1960 3 228 11 209 42 random 3 #> 10 3 Rosenthal et al 1960 3 228 11 209 42 random 3 #> 11 3 Rosenthal et al 1960 3 228 11 209 42 random 3 #> 12 3 Rosenthal et al 1960 3 228 11 209 42 random 3 #> 13 4 Hart & Sutherland 1977 62 13536 248 12619 52 random 4 #> 14 4 Hart & Sutherland 1977 62 13536 248 12619 52 random 4 #> 15 4 Hart & Sutherland 1977 62 13536 248 12619 52 random 4 #> 16 4 Hart & Sutherland 1977 62 13536 248 12619 52 random 4 #> 17 5 Frimodt-Moller et al 1973 33 5036 47 5761 13 alternate 5 #> 18 5 Frimodt-Moller et al 1973 33 5036 47 5761 13 alternate 5 #> 19 5 Frimodt-Moller et al 1973 33 5036 47 5761 13 alternate 5 #> 20 5 Frimodt-Moller et al 1973 33 5036 47 5761 13 alternate 5 #> 21 6 Stein & Aronson 1953 180 1361 372 1079 44 alternate 6 #> 22 6 Stein & Aronson 1953 180 1361 372 1079 44 alternate 6 #> 23 6 Stein & Aronson 1953 180 1361 372 1079 44 alternate 6 #> 24 6 Stein & Aronson 1953 180 1361 372 1079 44 alternate 6 #> 25 7 Vandiviere et al 1973 8 2537 10 619 19 random 7 #> 26 7 Vandiviere et al 1973 8 2537 10 619 19 random 7 #> 27 7 Vandiviere et al 1973 8 2537 10 619 19 random 7 #> 28 7 Vandiviere et al 1973 8 2537 10 619 19 random 7 #> 29 8 TPT Madras 1980 505 87886 499 87892 13 random 8 #> 30 8 TPT Madras 1980 505 87886 499 87892 13 random 8 #> 31 8 TPT Madras 1980 505 87886 499 87892 13 random 8 #> 32 8 TPT Madras 1980 505 87886 499 87892 13 random 8 #> 33 9 Coetzee & Berjak 1968 29 7470 45 7232 27 random 9 #> 34 9 Coetzee & Berjak 1968 29 7470 45 7232 27 random 9 #> 35 9 Coetzee & Berjak 1968 29 7470 45 7232 27 random 9 #> 36 9 Coetzee & Berjak 1968 29 7470 45 7232 27 random 9 #> 37 10 Rosenthal et al 1961 17 1699 65 1600 42 systematic 10 #> 38 10 Rosenthal et al 1961 17 1699 65 1600 42 systematic 10 #> 39 10 Rosenthal et al 1961 17 1699 65 1600 42 systematic 10 #> 40 10 Rosenthal et al 1961 17 1699 65 1600 42 systematic 10 #> 41 11 Comstock et al 1974 186 50448 141 27197 18 systematic 11 #> 42 11 Comstock et al 1974 186 50448 141 27197 18 systematic 11 #> 43 11 Comstock et al 1974 186 50448 141 27197 18 systematic 11 #> 44 11 Comstock et al 1974 186 50448 141 27197 18 systematic 11 #> 45 12 Comstock & Webster 1969 5 2493 3 2338 33 systematic 12 #> 46 12 Comstock & Webster 1969 5 2493 3 2338 33 systematic 12 #> 47 12 Comstock & Webster 1969 5 2493 3 2338 33 systematic 12 #> 48 12 Comstock & Webster 1969 5 2493 3 2338 33 systematic 12 #> 49 13 Comstock et al 1976 27 16886 29 17825 33 systematic 13 #> 50 13 Comstock et al 1976 27 16886 29 17825 33 systematic 13 #> 51 13 Comstock et al 1976 27 16886 29 17825 33 systematic 13 #> 52 13 Comstock et al 1976 27 16886 29 17825 33 systematic 13 #> group outcome freq #> 1 1 1 4 #> 2 1 2 119 #> 3 2 1 11 #> 4 2 2 128 #> 5 1 1 6 #> 6 1 2 300 #> 7 2 1 29 #> 8 2 2 274 #> 9 1 1 3 #> 10 1 2 228 #> 11 2 1 11 #> 12 2 2 209 #> 13 1 1 62 #> 14 1 2 13536 #> 15 2 1 248 #> 16 2 2 12619 #> 17 1 1 33 #> 18 1 2 5036 #> 19 2 1 47 #> 20 2 2 5761 #> 21 1 1 180 #> 22 1 2 1361 #> 23 2 1 372 #> 24 2 2 1079 #> 25 1 1 8 #> 26 1 2 2537 #> 27 2 1 10 #> 28 2 2 619 #> 29 1 1 505 #> 30 1 2 87886 #> 31 2 1 499 #> 32 2 2 87892 #> 33 1 1 29 #> 34 1 2 7470 #> 35 2 1 45 #> 36 2 2 7232 #> 37 1 1 17 #> 38 1 2 1699 #> 39 2 1 65 #> 40 2 2 1600 #> 41 1 1 186 #> 42 1 2 50448 #> 43 2 1 141 #> 44 2 2 27197 #> 45 1 1 5 #> 46 1 2 2493 #> 47 2 1 3 #> 48 2 2 2338 #> 49 1 1 27 #> 50 1 2 16886 #> 51 2 1 29 #> 52 2 2 17825
### convert data to long format dat <- to.long(measure="IRR", x1i=x1i, x2i=x2i, t1i=t1i, t2i=t2i, data=dat.hart1999, var.names=c("id", "group", "events", "ptime")) dat
#> trial study year x1i n1i t1i x2i n2i t2i compgrp prevtype trinr id group #> 1 1 AFASAK 1989 9 335 413 19 336 398 placebo primary 2.8-4.2 1 1 #> 2 1 AFASAK 1989 9 335 413 19 336 398 placebo primary 2.8-4.2 1 2 #> 3 2 SPAF 1991 8 210 263 19 211 245 placebo primary 2.0-4.5 2 1 #> 4 2 SPAF 1991 8 210 263 19 211 245 placebo primary 2.0-4.5 2 2 #> 5 3 BAATAF 1990 3 212 487 13 208 435 control primary 1.5-2.7 3 1 #> 6 3 BAATAF 1990 3 212 487 13 208 435 control primary 1.5-2.7 3 2 #> 7 4 CAFA 1991 6 187 237 9 191 241 placebo primary 2.0-3.0 4 1 #> 8 4 CAFA 1991 6 187 237 9 191 241 placebo primary 2.0-3.0 4 2 #> 9 5 SPINAF 1992 7 281 489 23 290 483 placebo primary 1.4-2.8 5 1 #> 10 5 SPINAF 1992 7 281 489 23 290 483 placebo primary 1.4-2.8 5 2 #> 11 6 EAFT 1993 20 225 507 50 214 405 placebo secondary 2.5-4.0 6 1 #> 12 6 EAFT 1993 20 225 507 50 214 405 placebo secondary 2.5-4.0 6 2 #> events ptime #> 1 9 413 #> 2 19 398 #> 3 8 263 #> 4 19 245 #> 5 3 487 #> 6 13 435 #> 7 6 237 #> 8 9 241 #> 9 7 489 #> 10 23 483 #> 11 20 507 #> 12 50 405
### convert data to long format dat <- to.long(measure="MD", m1i=m1i, sd1i=sd1i, n1i=n1i, m2i=m2i, sd2i=sd2i, n2i=n2i, data=dat.normand1999, var.names=c("id", "group", "mean", "sd", "n")) dat
#> study source n1i m1i sd1i n2i m2i sd2i id group mean sd n #> 1 1 Edinburgh 155 55 47 156 75 64 1 1 55 47 155 #> 2 1 Edinburgh 155 55 47 156 75 64 1 2 75 64 156 #> 3 2 Orpington-Mild 31 27 7 32 29 4 2 1 27 7 31 #> 4 2 Orpington-Mild 31 27 7 32 29 4 2 2 29 4 32 #> 5 3 Orpington-Moderate 75 64 17 71 119 29 3 1 64 17 75 #> 6 3 Orpington-Moderate 75 64 17 71 119 29 3 2 119 29 71 #> 7 4 Orpington-Severe 18 66 20 18 137 48 4 1 66 20 18 #> 8 4 Orpington-Severe 18 66 20 18 137 48 4 2 137 48 18 #> 9 5 Montreal-Home 8 14 8 13 18 11 5 1 14 8 8 #> 10 5 Montreal-Home 8 14 8 13 18 11 5 2 18 11 13 #> 11 6 Montreal-Transfer 57 19 7 52 18 4 6 1 19 7 57 #> 12 6 Montreal-Transfer 57 19 7 52 18 4 6 2 18 4 52 #> 13 7 Newcastle 34 52 45 33 41 34 7 1 52 45 34 #> 14 7 Newcastle 34 52 45 33 41 34 7 2 41 34 33 #> 15 8 Umea 110 21 16 183 31 27 8 1 21 16 110 #> 16 8 Umea 110 21 16 183 31 27 8 2 31 27 183 #> 17 9 Uppsala 60 30 27 52 23 20 9 1 30 27 60 #> 18 9 Uppsala 60 30 27 52 23 20 9 2 23 20 52