Title: | Bayesian Model for CACE Analysis |
---|---|
Description: | Performs CACE (Complier Average Causal Effect analysis) on either a single study or meta-analysis of datasets with binary outcomes, using either complete or incomplete noncompliance information. Our package implements the Bayesian methods proposed in Zhou et al. (2019) <doi:10.1111/biom.13028>, which introduces a Bayesian hierarchical model for estimating CACE in meta-analysis of clinical trials with noncompliance, and Zhou et al. (2021) <doi:10.1080/01621459.2021.1900859>, with an application example on Epidural Analgesia. |
Authors: | Jinhui Yang [aut, cre] , Jincheng Zhou [aut] , James Hodges [ctb], Haitao Chu [ctb] |
Maintainer: | Jinhui Yang <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.2.3 |
Built: | 2024-11-08 06:35:11 UTC |
Source: | CRAN |
This function performs the Bayesian hierarchical model method for meta-analysis when the dataset has complete compliance information for all studies, as described in Section 2.2, "the Bayesian hierarchical model", of the package manuscript.
cace.meta.c( data, param = c("CACE", "u1out", "v1out", "s1out", "b1out", "pic", "pin", "pia"), random.effects = list(), re.values = list(), model.code = "", digits = 3, n.adapt = 1000, n.iter = 1e+05, n.burnin = floor(n.iter/2), n.chains = 3, n.thin = max(1, floor((n.iter - n.burnin)/1e+05)), conv.diag = FALSE, mcmc.samples = FALSE, study.specific = FALSE )
cace.meta.c( data, param = c("CACE", "u1out", "v1out", "s1out", "b1out", "pic", "pin", "pia"), random.effects = list(), re.values = list(), model.code = "", digits = 3, n.adapt = 1000, n.iter = 1e+05, n.burnin = floor(n.iter/2), n.chains = 3, n.thin = max(1, floor((n.iter - n.burnin)/1e+05)), conv.diag = FALSE, mcmc.samples = FALSE, study.specific = FALSE )
data |
an input dataset with the same structure as the example data |
param |
a character string vector indicating the parameters to be tracked and estimated.
By default the following parameters (see |
random.effects |
a list of logical values indicating whether random effects are included in the model.
The list should contain the assignment for these parameters only: |
re.values |
a list of parameter values for the random effects. It should contain the assignment for these
parameters only: |
model.code |
a string representation of the model code; each line should be separated. Default to constructing
model code using the |
digits |
number of digits. Default to |
n.adapt |
adapt value. Default to |
n.iter |
number of iterations. Default to |
n.burnin |
number of burn-in iterations. Default to |
n.chains |
number of chains. Default to |
n.thin |
thinning rate, must be a positive integer. Default to |
conv.diag |
whether or not to show convergence diagnostics. Default to |
mcmc.samples |
whether to include JAGS samples in the final output. Default to |
study.specific |
a logical value indicating whether to calculate the study-specific
|
It returns a model object whose attribute type is cace.Bayes
Zhou J, Hodges JS, Suri MFK, Chu H (2019). “A Bayesian hierarchical model estimating CACE in meta-analysis of randomized clinical trials with noncompliance.” Biometrics, 75(3), 978–987.
Lunn D, Jackson C, Best N, Thomas A, Spiegelhalter D (2012). The BUGS book: A practical introduction to Bayesian analysis. CRC press.
Zeger SL, Liang K, Albert PS (1988). “Models for longitudinal data: a generalized estimating equation approach.” Biometrics, 1049–1060.
data("epidural_c", package = "BayesCACE") set.seed(123) out.meta.c <- cace.meta.c(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE) # By calling the object smry from the output list out.meta.c, posterior estimates # (posterior mean, standard deviation, posterior median, 95\% credible interval, and # time-series standard error) are displayed. out.meta.c$smry out.meta.c$DIC
data("epidural_c", package = "BayesCACE") set.seed(123) out.meta.c <- cace.meta.c(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE) # By calling the object smry from the output list out.meta.c, posterior estimates # (posterior mean, standard deviation, posterior median, 95\% credible interval, and # time-series standard error) are displayed. out.meta.c$smry out.meta.c$DIC
This function also estimates using the Bayesian hierarchcal model
but can accommodate studies with incomplete compliance data.
The necessary data structure and the likelihood function are presented in Section 2.3 of the
package manuscript, "CACE for meta-analysis with incomplete compliance information".
cace.meta.ic( data, param = c("CACE", "u1out", "v1out", "s1out", "b1out", "pic", "pin", "pia"), random.effects = list(), re.values = list(), model.code = "", digits = 3, n.adapt = 1000, n.iter = 1e+05, n.burnin = floor(n.iter/2), n.chains = 3, n.thin = max(1, floor((n.iter - n.burnin)/1e+05)), conv.diag = FALSE, mcmc.samples = FALSE, study.specific = FALSE )
cace.meta.ic( data, param = c("CACE", "u1out", "v1out", "s1out", "b1out", "pic", "pin", "pia"), random.effects = list(), re.values = list(), model.code = "", digits = 3, n.adapt = 1000, n.iter = 1e+05, n.burnin = floor(n.iter/2), n.chains = 3, n.thin = max(1, floor((n.iter - n.burnin)/1e+05)), conv.diag = FALSE, mcmc.samples = FALSE, study.specific = FALSE )
data |
a input dataset the same structure as the example data |
param |
the list of parameter used. Default to |
random.effects |
a list of logical values indicating whether random effects are included in the model.
The list should contain the assignment for these parameters only: |
re.values |
a list of parameter values for the random effects. It should contain the assignment for these
parameters only: |
model.code |
a string representation of the model code; each line should be separated. Default to constructing
model code using the |
digits |
number of digits. Default to |
n.adapt |
adapt value. Default to |
n.iter |
number of iterations. Default to |
n.burnin |
number of burn-in iterations. Default to |
n.chains |
number of chains. Default to |
n.thin |
thinning rate, must be a positive integer. Default to |
conv.diag |
whether or not to show convergence diagnostics. Default to |
mcmc.samples |
whether to include JAGS samples in the final output. Default to |
study.specific |
a logical value indicating whether to calculate the study-specific
|
Note that when compiling the JAGS
model, the warning ‘adaptation incomplete’ may
occasionally occur, indicating that the number of iterations for the adaptation process
is not sufficient. The default value of n.adapt
(the number of iterations for adaptation)
is 1,000. This is an initial sampling phase during which the samplers adapt their behavior
to maximize their efficiency (e.g., a Metropolis–Hastings random walk algorithm may change
its step size). The ‘adaptation incomplete’ warning indicates the MCMC algorithm may not
achieve maximum efficiency, but it generally has little impact on the posterior estimates
of the treatment effects. To avoid this warning, users may increase n.adapt
.
It returns a model object whose attribute type is cace.Bayes
Zhou J, Hodges JS, Suri MFK, Chu H (2019). “A Bayesian hierarchical model estimating CACE in meta-analysis of randomized clinical trials with noncompliance.” Biometrics, 75(3), 978–987.
data("epidural_ic", package = "BayesCACE") set.seed(123) out.meta.ic <- cace.meta.ic(data = epidural_ic, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE)
data("epidural_ic", package = "BayesCACE") set.seed(123) out.meta.ic <- cace.meta.ic(data = epidural_ic, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE)
This function performs CACE analysis for a single study using the likelihood and model specified in Section 2.1 of the package manuscript, or a two-step approach for meta-analysis with complete compliance information as described in Section 2.2, "the two-step approach".
cace.study( data, param = c("CACE", "u1", "v1", "s1", "b1", "pi.c", "pi.n", "pi.a"), re.values = list(), model.code = "", digits = 3, n.adapt = 1000, n.iter = 1e+05, n.burnin = floor(n.iter/2), n.chains = 3, n.thin = max(1, floor((n.iter - n.burnin)/1e+05)), conv.diag = FALSE, mcmc.samples = FALSE, two.step = FALSE, method = "REML" )
cace.study( data, param = c("CACE", "u1", "v1", "s1", "b1", "pi.c", "pi.n", "pi.a"), re.values = list(), model.code = "", digits = 3, n.adapt = 1000, n.iter = 1e+05, n.burnin = floor(n.iter/2), n.chains = 3, n.thin = max(1, floor((n.iter - n.burnin)/1e+05)), conv.diag = FALSE, mcmc.samples = FALSE, two.step = FALSE, method = "REML" )
data |
a input dataset the same structure as the example data |
param |
a character string vector indicating the parameters to be tracked and estimated.
By default all parameters in the model (see |
re.values |
a list of parameter values for the random effects. It should contain the assignment for these
parameters only: |
model.code |
a string representation of the model code; each line should be separated. Default to constructing
model code using the |
digits |
a positive integer specifying the digits after the decimal point for
the effect size estimates. The default is |
n.adapt |
the number of iterations for adaptation in Markov chain Monte Carlo (MCMC) algorithm;
it is used to maximize the sampling efficiency.
The default is |
n.iter |
the number of iterations of each MCMC chain.
The default is |
n.burnin |
the number of iterations for burn-in period. The default is
the largest integer not greater than |
n.chains |
the number of MCMC chains. The default is |
n.thin |
a positive integer indicating thinning rate for MCMC chains, which is used to
avoid potential high auto-correlation and to save computer memory when |
conv.diag |
a logical value indicating whether to compute the Gelman and Rubin
convergence statistic ( |
mcmc.samples |
a logical value indicating whether to save MCMC posterior samples
in the output object. The default is |
two.step |
a logical value indicating whether to conduct a two-step meta-analysis.
If |
method |
the method used in meta-analysis if |
The likelihood
.
If the input data
includes more than one study, the study-specific CACEs will be
estimated by retrieving data row by row.
By default, the function cace.study()
returns a list
including posterior estimates (posterior mean, standard deviation, median, and a 95%
credible interval (CrI) with 2.5% and 97.5% quantiles as the lower and upper bounds),
and the deviance information criterion (DIC) statistic for each study.
It returns a model object whose attribute type is cace.Bayes
data("epidural_c", package = "BayesCACE") set.seed(123) out.study <- cace.study(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, two.step = TRUE) # Show the estimates of theta for each single study (posterior mean and # standard deviation, posterior median, 95% credible interval, and time-series # standard error): out.study$CACE # If the argument conv.diag is specified as TRUE, the output list contains # a sub-list conv.out, which outputs the Gelman and Rubin convergence statistic, # labelled Point est.) calculated for each parameter from each single study, and # their upper confidence limits (labelled Upper C.I.). out.study$conv.out[[1]]
data("epidural_c", package = "BayesCACE") set.seed(123) out.study <- cace.study(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, two.step = TRUE) # Show the estimates of theta for each single study (posterior mean and # standard deviation, posterior median, 95% credible interval, and time-series # standard error): out.study$CACE # If the argument conv.diag is specified as TRUE, the output list contains # a sub-list conv.out, which outputs the Gelman and Rubin convergence statistic, # labelled Point est.) calculated for each parameter from each single study, and # their upper confidence limits (labelled Upper C.I.). out.study$conv.out[[1]]
This is a helper function from the rjags
library in order to get the names of the individual elements
of a node array. See the package rjags
for more details.
coda.names(basename, dim)
coda.names(basename, dim)
basename |
the node names |
dim |
dimension of the nodes |
It returns a list of the names of individual elements
Plummer M (2021). rjags: Bayesian Graphical Models using MCMC. R package version 4-12, https://CRAN.R-project.org/package=rjags.
This is a wrapper function for jags.samples
which sets a trace
monitor for all requested nodes, updates the model, and coerces the
output to a single mcmc.list
object. It also converts to the output
to dic format. This function is based on the coda.samples
function
from the rjags
library, and modified by Prof. Matthias Mittner.
coda.samples.dic(model, variable.names, n.iter, thin, ...)
coda.samples.dic(model, variable.names, n.iter, thin, ...)
model |
a jags model object |
variable.names |
a character vector giving the names of variables to be monitored |
n.iter |
number of iterations to monitor |
thin |
thinning interval for monitors |
... |
optional arguments that are passed to the |
It returns the output to the input model object, and in dic format.
Plummer M (2021). rjags: Bayesian Graphical Models using MCMC. R package version 4-12, https://CRAN.R-project.org/package=rjags.
https://ihrke.github.io/post/2014/10/07/dicjags/
The data contains a meta analysis of the association between using epidural analgesia in labor and the risk of cesarean section. It contains 10 trials with full compliance information, each with 8 observed counts.
data(epidural_c)
data(epidural_c)
An object of class data.frame
with 10 rows and 10 columns.
https://pubmed.ncbi.nlm.nih.gov/25592169/
Bannister-Tyrrell M, Miladinovic B, Roberts CL, Ford JB (2015). “Adjustment for compliance behavior in trials of epidural analgesia in labor using instrumental variable meta-analysis.” Journal of Clinical Epidemiology, 68(5), 525–533.
data(epidural_c)
data(epidural_c)
The data contains a meta analysis of the association between using epidural analgesia in labor and the risk of cesarean section. It contains 27 studies, only 10 out of which have full compliance information.
data(epidural_ic)
data(epidural_ic)
An object of class data.frame
with 27 rows and 14 columns.
https://pubmed.ncbi.nlm.nih.gov/25592169/
Bannister-Tyrrell M, Miladinovic B, Roberts CL, Ford JB (2015). “Adjustment for compliance behavior in trials of epidural analgesia in labor using instrumental variable meta-analysis.” Journal of Clinical Epidemiology, 68(5), 525–533.
data(epidural_ic)
data(epidural_ic)
This function generates part of the model code for meta-analysis
when the dataset has complete compliance information for all studies,
as described in Section 2.2, "the Bayesian hierarchical model" of the package manuscript.
This function will be called internally if user uses the cace.meta.c
function.
model.meta.c(random.effects = list(), re.values = list())
model.meta.c(random.effects = list(), re.values = list())
random.effects |
a list of logical values indicating whether random effects are included in the model.
The list should contain the assignment for these parameters only: |
re.values |
a list of parameter values for the random effects. It should contain the assignment for these
parameters only: |
It returns a model string
# use default settings model.string <- model.meta.c()
# use default settings model.string <- model.meta.c()
This function generates the model code for meta-analysis
when the dataset has incomplete compliance information for all studies,
as described in Section 2.2.2, "the Bayesian hierarchical model" of the package manuscript.
This function will be called internally if user uses the cace.meta.ic
function.
model.meta.ic(random.effects = list(), re.values = list())
model.meta.ic(random.effects = list(), re.values = list())
random.effects |
a list of logical values indicating whether random effects are included in the model.
The list should contain the assignment for these parameters only: |
re.values |
a list of parameter values for the random effects. It should contain the assignment for these
parameters only: |
It returns a model string
# use default settings model.string <- model.meta.ic()
# use default settings model.string <- model.meta.ic()
This function generates the model code for a single study using the
likelihood and model specified in Section 2.1, or a two-step
approach for meta-analysis with complete compliance information as
described in Section 2.2, "The two-step approach" of the package manuscript.
This function will be called internally if user uses the cace.study
function.
model.study(re.values = list())
model.study(re.values = list())
re.values |
a list of parameter values for the random effects. It should contain the assignment for these
parameters only: |
It returns a model string
model.string <- model.study()
model.string <- model.study()
This is a helper function from the rjags
library in order to parse the string of form
"a" or "a[n,p:q,r]". See the package rjags
for more details.
parse.varname(varname)
parse.varname(varname)
varname |
string name of variable |
It returns a list of parsed parameters
Plummer M (2021). rjags: Bayesian Graphical Models using MCMC. R package version 4-12, https://CRAN.R-project.org/package=rjags.
This function creates an acf (Autocorrelation Function) plot for a model object with the type attribute cace.Bayes
.
plt.acf(obj, param = c("CACE"), trialnumber = 1, ...)
plt.acf(obj, param = c("CACE"), trialnumber = 1, ...)
obj |
a model object, returned by |
param |
list of parameters to plot |
trialnumber |
indicator for which trial number of the mcmc samples
to use. The default is |
... |
optional parameters to pass into the |
It returns an acf plot in an R
plot window.
out.meta.c <- cace.meta.c(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE) plt.acf(obj=out.meta.c)
out.meta.c <- cace.meta.c(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE) plt.acf(obj=out.meta.c)
This function creates a density plot for a model object with the type attribute cace.Bayes
.
plt.density(obj, param = c("CACE"), trialnumber = 1, ...)
plt.density(obj, param = c("CACE"), trialnumber = 1, ...)
obj |
a model object, returned by |
param |
list of parameters to plot |
trialnumber |
indicator for which trial number of the mcmc samples
to use. The default is |
... |
optional parameters to pass into the |
It returns a density plot in an R
plot window.
out.meta.c <- cace.meta.c(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE) plt.density(obj=out.meta.c)
out.meta.c <- cace.meta.c(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE) plt.density(obj=out.meta.c)
This function provides a visual overview (forest plot) for a model object and corresponding dataset.
plt.forest(data, obj, ...)
plt.forest(data, obj, ...)
data |
an input dataset with the same structure as the example data |
obj |
a model object returned by |
... |
optional parameters passed into the |
It returns a forestplot object in an R
plot window.
data("epidural_c", package = "BayesCACE") out.meta.c <- cace.meta.c(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE) plt.forest(data=epidural_c, obj=out.meta.c)
data("epidural_c", package = "BayesCACE") out.meta.c <- cace.meta.c(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE) plt.forest(data=epidural_c, obj=out.meta.c)
Provides a forest plot of noncompliance rates in an R
plot window.
plt.noncomp(data, overall = TRUE, ...)
plt.noncomp(data, overall = TRUE, ...)
data |
a dataset with structure like the example |
overall |
a logical value indicating whether a summary estimate of the compliance rates
per randomization group is provided. The default is |
... |
optional parameters passed into the |
This function provides a visual overview (forest plot) of study-specific noncompliance rates in both randomization arms.
Only studies with full compliance information are included in this plot because noncompliance rates cannot be calculated without compliance data. In the generated plot, the red dot with its horizontal line shows the study-specific noncompliance rate with its 95% exact confidence interval for the patients randomized to the treatment arm, and the blue square with its horizontal line represents that rate and interval for those in the control arm. The confidence intervals are calculated by the Clopper–Pearson exact method, which is based on the cumulative distribution function of the binomial distribution.
A forest plot of noncompliance rates in an R
plot window
data("epidural_c", package = "BayesCACE") plt.noncomp(data=epidural_c, overall = TRUE)
data("epidural_c", package = "BayesCACE") plt.noncomp(data=epidural_c, overall = TRUE)
This function creates a traceplot for a model object with the type attribute cace.Bayes
.
plt.trace(obj, param = c("CACE"), trialnumber = 1, ...)
plt.trace(obj, param = c("CACE"), trialnumber = 1, ...)
obj |
a model object, returned by |
param |
list of parameters to plot |
trialnumber |
indicator for which trial number of the mcmc samples
to use. The default is |
... |
optional parameters to pass into the |
It returns a traceplot in an R
plot window.
out.meta.c <- cace.meta.c(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE) plt.trace(obj=out.meta.c)
out.meta.c <- cace.meta.c(data = epidural_c, conv.diag = TRUE, mcmc.samples = TRUE, study.specific = TRUE) plt.trace(obj=out.meta.c)
This function returns a partially complete prior string. Used internally - cannot be directly used.
prior.meta(random.effects = list(), re.values = list())
prior.meta(random.effects = list(), re.values = list())
random.effects |
a list of logical values indicating whether random effects are included in the model.
The list should contain the assignment for these parameters only: |
re.values |
a list of parameter values for the random effects. It should contain the assignment for these
parameters only: |
custom prior string
model.string <- prior.meta()
model.string <- prior.meta()
This function returns a partially complete prior string. Used internally - cannot be directly used.
prior.study(re.values = list())
prior.study(re.values = list())
re.values |
a list of parameter values for the random effects. It should contain the assignment for these
parameters only: |
custom model string
model.string <- prior.study()
model.string <- prior.study()