R/BayesianMetaAnalysis.R
computeBayesianMetaAnalysis.RdCompute a Bayesian meta-analysis using the Markov chain Monte Carlo (MCMC) engine BEAST.
A normal and half-normal prior are used for the mu and tau parameters, respectively, with standard
deviations as defined by the priorSd argument.
computeBayesianMetaAnalysis(
data,
chainLength = 1100000,
burnIn = 1e+05,
subSampleFrequency = 100,
priorSd = c(2, 0.5),
alpha = 0.05,
robust = FALSE,
df = 4,
seed = 1,
showProgressBar = TRUE
)A data frame containing either normal, skew-normal, custom parametric, or grid likelihood data, with one row per database.
Number of MCMC iterations.
Number of MCMC iterations to consider as burn in.
Subsample frequency for the MCMC.
A two-dimensional vector with the standard deviation of the prior for mu and tau, respectively.
The alpha (expected type I error) used for the credible intervals.
Whether or not to use a t-distribution model; default: FALSE.
Degrees of freedom for the t-model, only used if robust is TRUE.
The seed for the random number generator.
Showing a progress bar for MCMC?
A data frame with the point estimates and 95% credible intervals for the mu and tau parameters (the mean and standard deviation of the distribution from which the per-site effect sizes are drawn). Attributes of the data frame contain the MCMC trace and the detected approximation type.
# Simulate some data for this example:
populations <- simulatePopulations()
# Fit a Cox regression at each data site, and approximate likelihood function:
fitModelInDatabase <- function(population) {
cyclopsData <- Cyclops::createCyclopsData(Surv(time, y) ~ x + strata(stratumId),
data = population,
modelType = "cox"
)
cyclopsFit <- Cyclops::fitCyclopsModel(cyclopsData)
approximation <- approximateLikelihood(cyclopsFit,
parameter = "x",
approximation = "grid with gradients")
return(approximation)
}
approximations <- lapply(populations, fitModelInDatabase)
# At study coordinating center, perform meta-analysis using per-site approximations:
estimate <- computeBayesianMetaAnalysis(approximations)
#> Detected data following grid with gradients distribution
#> Performing MCMC. This may take a while
estimate
#> mu mu95Lb mu95Ub muSe tau tau95Lb tau95Ub
#> 1 0.456537 -0.4352229 1.231871 0.4238033 0.4477577 0.001885051 1.017906
#> logRr seLogRr predictionInterval95Lb predictionInterval95Ub
#> 1 0.456537 0.4238033 -0.9953475 1.934389
# (Estimates in this example will vary due to the random simulation)