Approximate a Bayesian posterior from a Cyclops
likelihood profile and normal prior
using the Markov chain Monte Carlo engine BEAST.
approximateSimplePosterior(
likelihoodProfile,
chainLength = 1100000,
burnIn = 1e+05,
subSampleFrequency = 100,
priorMean = 0,
priorSd = 0.5,
startingValue = 0,
seed = 1
)
Named vector containing grid likelihood data from Cyclops
.
Number of MCMC iterations.
Number of MCMC iterations to consider as burn in.
Subsample frequency for the MCMC.
Prior mean for the regression parameter
Prior standard deviation for the regression parameter
Initial state for regression parameter
Seed for the random number generator.
A data frame with the point estimates and 95% credible intervals for the regression parameter. Attributes of the data frame contain the MCMC trace for diagnostics.
# Simulate some data for this example:
population <- simulatePopulations(createSimulationSettings(nSites = 1))[[1]]
# Fit a Cox regression at each data site, and approximate likelihood function:
cyclopsData <- Cyclops::createCyclopsData(Surv(time, y) ~ x + strata(stratumId),
data = population,
modelType = "cox"
)
cyclopsFit <- Cyclops::fitCyclopsModel(cyclopsData)
likelihoodProfile <- approximateLikelihood(cyclopsFit, parameter = "x", approximation = "grid")
# Run MCMC
mcmcTraces <- approximateSimplePosterior(
likelihoodProfile = likelihoodProfile,
priorMean = 0, priorSd = 100
)
#> Detected data following grid distribution
#> Performing MCMC. This may take a while
# Report posterior expectation
mean(mcmcTraces$theta)
#> [1] 0.4205803
# (Estimates in this example will vary due to the random simulation)