Extracts the sample from a bayesianOutput

getSample(sampler, parametersOnly = T, coda = F, start = 1, end = NULL,
  thin = 1, numSamples = NULL, whichParameters = NULL,
  includesProbabilities = F, reportDiagnostics = FALSE, ...)

Arguments

sampler

an object of class mcmcSampler, mcmcSamplerList, smcSampler, smcSamplerList, mcmc, mcmc.list, double, numeric

parametersOnly

if F, likelihood, posterior and prior values are also provided in the output

coda

works only for mcmc classes - provides output as a coda object. Note: if mcmcSamplerList contains mcmc samplers such as DE that have several chains, the internal chains will be collapsed. This may not be the desired behavior for all applications.

start

for mcmc samplers start value in the chain. For SMC samplers, start particle

end

for mcmc samplers end value in the chain. For SMC samplers, end particle

thin

thinning parameter. Either an integer determining the thinning intervall (default is 1) or "auto" for automatic thinning.

numSamples

sample size (only used if thin = 1). If you want to use numSamples set thin to 1.

whichParameters

possibility to select parameters by index

includesProbabilities

applies only to getSample.Matrix. logical, determining whether probabilities should be included in the result.

reportDiagnostics

logical, determines whether settings should be included in the output

...

further arguments

Details

If thin is greater than the total number of samples in the sampler object the first and the last element (of each chain if a sampler with multiples chains is used) are sampled. If numSamples is greater than the total number of samples all samples are selected. In both cases a warning is displayed.

If thin and numSamples is passed, the function will use the thin argument if it is valid and greater than 1, else numSamples will be used.

Examples

ll = function(x) sum(dnorm(x, log = TRUE)) setup = createBayesianSetup(ll, lower = c(-10,-10), upper = c(10,10)) settings = list(nrChains = 2, iterations = 1000) out <- runMCMC(bayesianSetup = setup, sampler = "DEzs", settings = settings)
#> Running DEzs-MCMC, chain 1 iteration 300 of 1002 . Current logp -14.26114 -8.366528 -8.935835 . Please wait! Running DEzs-MCMC, chain 1 iteration 600 of 1002 . Current logp -9.937957 -8.081307 -7.929941 . Please wait! Running DEzs-MCMC, chain 1 iteration 900 of 1002 . Current logp -8.117279 -8.05287 -9.947761 . Please wait! Running DEzs-MCMC, chain 1 iteration 1002 of 1002 . Current logp -8.392833 -10.03726 -9.426219 . Please wait!
#> runMCMC terminated after 0.150000000000091seconds
#> Running DEzs-MCMC, chain 2 iteration 300 of 1002 . Current logp -7.991262 -8.611373 -7.993276 . Please wait! Running DEzs-MCMC, chain 2 iteration 600 of 1002 . Current logp -8.018305 -13.25595 -8.069903 . Please wait! Running DEzs-MCMC, chain 2 iteration 900 of 1002 . Current logp -8.563249 -7.926249 -8.226997 . Please wait! Running DEzs-MCMC, chain 2 iteration 1002 of 1002 . Current logp -7.835189 -8.293727 -8.162822 . Please wait!
#> runMCMC terminated after 0.150000000000091seconds
# population MCMCs divide the interations by the number of internal chains, # so the end of the 3 chains is 1000/3 = 334 sample <- getSample(out, start = 100, end = 334, thin = 10) # sampling with number of samples instead of thinning and # returning a coda object sample <- getSample(out, start = 100, numSamples = 60, coda = TRUE) plot(sample)
# MCMC with a single chain: settings_2 <- list(nrChains = 1, iterations = 1000) out_2 <- runMCMC(setup, sampler = "Metropolis", settings = settings_2)
#> BT runMCMC: trying to find optimal start and covariance values 
#> BT runMCMC: Optimization finished, setting startValues to 0.000180983530656439 -0.000617049956313312 - Setting covariance to 1.00030603546159 2.97025209409184e-06 2.97025209409184e-06 1.00000530260387
#> Running Metropolis-MCMC, chain 1 iteration 100 of 1000 . Current logp: -9.532038 Please wait! Running Metropolis-MCMC, chain 1 iteration 200 of 1000 . Current logp: -8.668119 Please wait! Running Metropolis-MCMC, chain 1 iteration 300 of 1000 . Current logp: -7.900279 Please wait! Running Metropolis-MCMC, chain 1 iteration 400 of 1000 . Current logp: -8.629034 Please wait! Running Metropolis-MCMC, chain 1 iteration 500 of 1000 . Current logp: -8.510623 Please wait! Running Metropolis-MCMC, chain 1 iteration 600 of 1000 . Current logp: -9.273203 Please wait! Running Metropolis-MCMC, chain 1 iteration 700 of 1000 . Current logp: -7.956503 Please wait! Running Metropolis-MCMC, chain 1 iteration 800 of 1000 . Current logp: -8.932149 Please wait! Running Metropolis-MCMC, chain 1 iteration 900 of 1000 . Current logp: -8.071972 Please wait! Running Metropolis-MCMC, chain 1 iteration 1000 of 1000 . Current logp: -8.17257 Please wait!
#> runMCMC terminated after 0.199999999999818seconds
sample_2 <- getSample(out_2, numSamples = 100)