prepare_ma: Convert from individual to summary data in meta-analyses

View source: R/prepare_ma.R

prepare_maR Documentation

Convert from individual to summary data in meta-analyses


Allows for one-way conversion from full to summary data or for calculation of effects for binary data. Input must be pre-formatted appropriately.


  effect = c("mean", "logOR", "logRR", "RD"),
  rare_event_correction = 0.25,
  correction_type = c("single", "all"),
  log = FALSE,
  cfb = FALSE,
  summarise = TRUE,
  treatment = "treatment",
  baseline = NULL,
  group = "group",
  outcome = "outcome",
  pooling = FALSE



either a data.frame of individual-level observations with columns for outcome (numeric), treatment (values 0 and 1) and group (numeric, character or factor); or, a data frame with binary data (must have columns a, c, b/n1, d/n2).


what effect to calculate? a mean (and SE) of outcome in groups or (for binary data) logOR (odds ratio), logRR (risk ratio), RD (risk difference);


This correction is used when working with binary data (effect logOR or logRR) The value of correction is added to all cells in either some or all rows (groups), depending on correction_type. Using corrections may bias results but is the only alternative to avoid infinite values.


If "single" then rare event correction is only applied to the particular rows that have 0 cells, if "all", then to all studies


logical; log-transform the outcome variable?


logical; calculate change from baseline? If yes, the outcome variable is taken as a difference between values in outcome and baseline columns


logical; TRUE by default, but you can disable it to obtain converted (e.g. logged) data with columns renamed


name of column with treatment variable


name of column with baseline variable


name of the column with grouping variable


name of column with outcome variable


Internal use only, please ignore


The conversions done by this function are not typically needed and may happen automatically when data is given to baggr. However, this function can be used to explicitly convert from full to reduced (summarised) data without analysing it in any model. It can be useful for examining your data and generating summary tables.

If multiple operations are performed, they are taken in this order:

  1. conversion to log scale,

  2. calculating change from baseline,

  3. summarising data (using appropriate effect)


  • If you summarise: a data.frame with columns for group, tau and se.tau (for effect = "mean", also baseline means; for "logRR" or "logOR" also a, b, c, d, which correspond to typical contingency table notation, that is: a = events in exposed; b = no events in exposed, c = events in unexposed, d = no events in unexposed).

  • If you do not summarise data, individual level data will be returned, but some columns may be renamed or transformed (see the arguments above).


Witold Wiecek

See Also

convert_inputs for how any type of data is (internally) converted into a list of Stan inputs; vignette baggr_binary for more details about rare event corrections


# Example of working with binary outcomes data
# Make up some individual-level data first:
df_rare <- data.frame(group = paste("Study", LETTERS[1:5]),
                      a = c(0, 2, 1, 3, 1), c = c(2, 2, 3, 3, 5),
                      n1i = c(120, 300, 110, 250, 95),
                      n2i = c(120, 300, 110, 250, 95))
df_rare_ind <- binary_to_individual(df_rare)
# Calculate ORs; default rare event correction will be applied
prepare_ma(df_rare_ind, effect = "logOR")
# Add 0.5 to all rows
prepare_ma(df_rare_ind, effect = "logOR",
           correction_type = "all",
           rare_event_correction = 0.5)

baggr documentation built on March 18, 2022, 7:02 p.m.