R/BayesianMetaAnalysis.R
computeBayesianMetaAnalysis.Rd
Compute 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
)
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.
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 = "custom")
return(approximation)
}
approximations <- lapply(populations, fitModelInDatabase)
approximations <- do.call("rbind", approximations)
# At study coordinating center, perform meta-analysis using per-site approximations:
estimate <- computeBayesianMetaAnalysis(approximations)
#> Detected data following custom parameric distribution
#> Performing MCMC. This may take a while
estimate
#> mu mu95Lb mu95Ub muSe tau tau95Lb tau95Ub logRr
#> 1 0.6080768 -0.287342 1.444109 0.4401307 0.54771 0.001126101 1.121517 0.6080768
#> seLogRr
#> 1 0.4401307
# (Estimates in this example will vary due to the random simulation)