long2jags: Transform data from long arm-based to JAGS format

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/long2jags.R

Description

This function transforms data from long arm-based format, i.e., two rows for a pairwise comparison, to a list format for Bayesian network meta-analysis using JAGS.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
long2jags(
  studlab,
  treat,
  event,
  n,
  mean,
  sd,
  data = NULL,
  reference.group = 1,
  covar,
  func = "max"
)

Arguments

studlab

A vector with study labels or an object created with longarm.

treat

A vector with treatment labels (mandatory if studlab is a vector).

event

Number of events.

n

Number of observations.

mean

Estimated mean.

sd

Standard deviation.

data

An optional data frame containing the study information.

reference.group

Reference treatment.

covar

Covariable to use in network meta-regression.

func

A character string specifying function to summarize data for additional covariate. Either, "min", "max", "mean", or ""; can be abbreviated.

Details

This function transforms data from long arm-based format, i.e., two rows for a pairwise comparison, to a list format for Bayesian network meta-analysis using JAGS.

At the moment, the function can be used to transform data with a binary or continuous outcome. The following arguments are mandatory if argument studlab is not an R object created with longarm. Arguments studlab and treat must be provided to identify studies and treatments and, depending on the outcome, the following additional arguments:

Value

A list of class jagsdata.

Author(s)

Georgia Salanti georgia.salanti@ispm.unibe.ch, Guido Schwarzer sc@imbi.uni-freiburg.de

See Also

netjags, longarm, netmeta

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
## Not run: 
library(netmeta)
data(Dogliotti2014)
Dogliotti2014$trt <- treats(Dogliotti2014$treatment, nchar = 4)
#
p1 <- pairwise(trt, stroke, total, studlab = study,
               data = Dogliotti2014, sm = "OR")

# Standard frequentist random effects NMA model
#
n1.iv <- netmeta(p1)

# Standard Bayesian random effects NMA model
#
library(R2jags)

# Transform long-arm based data into a list suitable for JAGS
# analysis, with placebo as reference treatment
#
dat.jags <- long2jags(study, trt,
                      event = stroke, n = total,
                      data = Dogliotti2014, 
                      reference = "pl")

# Run JAGS and create JAGS object
#
n1.jags <- netjags(dat.jags)

# Extract lnOR from BUGS output
#
trts <- attr(n1.jags, "trts")
TE.random <- n1.jags$BUGSoutput$mean$LOR.full
rownames(TE.random) <- trts
colnames(TE.random) <- trts

# Extract se(lnOR) from BUGS output
#
seTE.random <- n1.jags$BUGSoutput$sd$LOR.full
rownames(seTE.random) <- trts
colnames(seTE.random) <- trts

# Conduct frequentist NMA with tau from Bayesian NMA
#
tau.jags <- as.numeric(n1.jags$BUGSoutput$mean$tau)
n1.iv.jags <-
  suppressWarnings(netmeta(p1, tau.preset = tau.jags))

# Print treatment matrix for frequentist NMA
#
round(n1.iv$TE.random, 3)[trts, trts]

# Print treatment matrix for Bayesian NMA
#
round(TE.random, 3)

# Print treatment matrix for frequentist NMA
# (using tau from Bayesian NMA)
#
round(n1.iv.jags$TE.random, 3)[trts, trts]

# Print standard errors from frequentist NMA
#
round(n1.iv$seTE.random, 3)[trts, trts]

# Print standard errors from Bayesian NMA
#
round(seTE.random, 3)

# Print standard errors from frequentist NMA
# (using tau from Bayesian NMA)
#
round(n1.iv.jags$seTE.random, 3)[trts, trts]

# Print square root of between-study heterogeneity tau2
#
tau.jags
n1.iv$tau

## End(Not run)

guido-s/nmajags documentation built on Jan. 15, 2022, 12:35 a.m.