metastan_data: Prepare meta-analysis dataset for meta_stan function

View source: R/metastan_data.R

metastan_dataR Documentation

Prepare meta-analysis dataset for meta_stan function

Description

metastan_data creates datasets suitable for meta_stan function

Usage

metastan_data(
  id,
  treatment,
  x,
  type = c("normal", "binomial", "poisson"),
  y,
  se,
  v,
  count,
  total,
  exposure,
  labels,
  data,
  sort = TRUE,
  checkForConflicts = TRUE
)

Arguments

id

a vector of study IDs (labels)

treatment

(optional) vector indicating treatment groups

x

(optional) covariable/regressor vector or matrix

type

type of outcome

y

estimates (for normal outcomes)

se

associated standard errors (normal outcomes)

v

variances / squared standard errors (normal outcomes)

count

event count (for binomial or Poisson outcomes)

total

sample size (for binomial outcomes)

exposure

exposure (for Poisson outcomes)

labels

(optional) vector of row labels

data

a data frame from which (some of) above variables may be taken

sort

if TRUE (the default), output rows will be sorted (keeping entries corresponding to the same study ("id") next to each other, and sorting by "treatment" and "x")

Details

The resulting data.frame can be used as data argument in meta_stan.

NB: arguments "id", "treatment", "x", "y", "se", "v", "count", "total", "exposure", "labels" may be taken from local environment OR from "data" (data frame) argument.

Value

The returned object is a "list" of class "metastan_data" containing the following elements: * "id" : study identifier (a vector of type factor) * "treatment" : (optional) a treatment identifier (a vector of type factor, or NULL) * "x" : (optional) covariable(s), (a numeric matrix, or NULL) * "type" : a flag identifying the outcome type ("normal", "binomial", or "poisson") * "outcome" : the actual outcome data (a two-column numeric matrix) * "call" : the original function call

Examples

# 3 studies, binomial endpoint, one covariable (named "dose"):
msd <- metastan_data(id=c("Smith","Smith", "Taylor","Taylor",
                          "Jones", "Jones","Taylor"),
                     treatment=c("placebo","verum","placebo","verum",
                                 "verum","placebo","verum"),
                     type="binomial",
                     count=c(3, 2, 7, 5, 4, 5, 6),
                     total=c(10, 10, 25, 27, 15, 16, 23),
                     x=cbind("dose"=c(0, 50, 0, 50, 30, 0, 20)))
msd
print(msd, n=7)     # (show all 7 lines of data)
print.default(msd)  # default view of returned object

gunhanb/metastan documentation built on March 18, 2023, 12:09 a.m.