| Title: | Bayesian Methods for Calibrating Simulation Sets |
|---|---|
| Description: | More about what it does (maybe more than one line) Use four spaces when indenting paragraphs within the Description. |
| Authors: | Who wrote it |
| Maintainer: | Anthony Todd Fojo <[email protected]> |
| License: | What license is it under? |
| Version: | 0.2.2 |
| Built: | 2026-11-14 17:21:42 UTC |
| Source: | https://github.com/tfojo1/bayesian.simulations |
Add parameters to a simset or parameter_set
add.parameters( simset, parameters, parameter.names = NULL, parameter.transformations = NULL, parameter.lower.bounds = -Inf, parameter.upper.bounds = Inf )add.parameters( simset, parameters, parameter.names = NULL, parameter.transformations = NULL, parameter.lower.bounds = -Inf, parameter.upper.bounds = Inf )
simset |
A simset or parameter_set to which to add parameters |
parameters |
The parameters to add. If only one new parameter, can be either a vector of length [email protected] or length 1, or a matrix with one column and [email protected] rows. If more than one parameter is to be added, a matrix with one column for parameter and [email protected] rows |
parameter.names |
The names of the new parameters being added. If NULL, takes the parameter names from the column names of parameters |
parameter.transformations |
Objects of class distributions::transformation, or the names of defined transformations, according to which parameters should be smoothed when making smoothed distributions |
parameter.lower.bounds, parameter.upper.bounds
|
The min and max values each parameter can take. If given a scalar value, will apply the same bounds to all parameters |
Assemble an MCMC object from iterations stored in a cache
assemble.mcmc.from.cache( dir, allow.incomplete = F, chains = NULL, remove.cache.when.done = F )assemble.mcmc.from.cache( dir, allow.incomplete = F, chains = NULL, remove.cache.when.done = F )
dir |
The directory where the cache is stored |
allow.incomplete |
If FALSE, throws an error if the cache has not finished running. If TRUE, assembles an MCMC object out of all chains where any iterations have been run past the burn period, with a number of iterations equal to the mininum number of iterations run in any chain past the burn period |
chains |
The numbers of the chains to run. If passed NULL (the default), runs all chains |
An mcmc.sim object
Report the progress of an MCMC process running from a cache
cache.progress(dir)cache.progress(dir)
dir |
The directory where the cache is stored |
Set up a cache for running an MCMC from
create.mcmc.cache( dir, control, n.iter, starting.values = NULL, prior.mcmc = NULL, cache.frequency = 1000, allow.overwrite.cache = F, merge.with.prior.mcmc = T )create.mcmc.cache( dir, control, n.iter, starting.values = NULL, prior.mcmc = NULL, cache.frequency = 1000, allow.overwrite.cache = F, merge.with.prior.mcmc = T )
dir |
The directory where the cache should be stored |
cache.frequency |
How often to cache to the disk |
allow.overwrite.cache |
If a previous cache is in place in dir, the function will throw an error if allow.overwrite.cache is FALSE. If allow.overwrite.cache is TRUE, it will overwrite the previously existing cache |
cache.prefix |
??? |
Extend the simulations of a simset
extend.simulations(simset, fn)extend.simulations(simset, fn)
simset |
An object of class simset |
fn |
A function that takes two arguments: sim (the prior simulation object) and parameters (the corresponding numeric vector of parameters) and returns a new simulation object |
An updated simset
Extracts a simset from an object containing simulations
extract.simset(object, ...)extract.simset(object, ...)
object |
The object from which to extract the simset |
Gets a probability distribution over the results of a function applied to each simulation or its parameters or both
extract.simset.distribution( simset, fn, pass.to.fn = c("simulation", "parameters", "both")[1], ..., smooth = F )extract.simset.distribution( simset, fn, pass.to.fn = c("simulation", "parameters", "both")[1], ..., smooth = F )
simset |
A simset object |
fn |
A function to be applied. If pass.to.fn=='simulation', the function's first parameters should be 'sim' (a simulation objet). If pass.to.fn=='parameters', the function's first argument should be 'parameters' (a vector of parameters). If pass.to.fn=='both', the function's first two parameters should be 'sim' and 'parameters' |
pass.to.fn |
What to pass to fn as arguments |
... |
Additional parameters to be passed to fn |
smooth |
Whether to return a smoothed distribution over continuous parameters |
Gets a probability distribution over the parameters in a simset
extract.simset.parameter.distribution(simset, smooth = F)extract.simset.parameter.distribution(simset, smooth = F)
simset |
A simset object |
smooth |
Whether to return a smoothed distribution over continuous parameters |
Calculates the R-hat of Gelman 2013, or the R-hat using rank-normalization as per Vehtari 2019
get.rhats( mcmc, var.names = [email protected], chains = 1:[email protected], additional.burn = 0, additional.thin = 1, exact.var.names = F, rank.normalize = F, sort = T )get.rhats( mcmc, var.names = mcmc@var.names, chains = 1:mcmc@n.chains, additional.burn = 0, additional.thin = 1, exact.var.names = F, rank.normalize = F, sort = T )
mcmc |
A mcmc.sim object |
var.names |
var.names is the names of variables to include or a set of integer indices. If exact.var.names is TRUE, matches the given strings exactly. If exact.var.names is FALSE, matches any variable name that begins with any element of var.names, where the * character is treated as a wild card |
chains |
Which chains from the MCMC to use |
exact.var.names |
var.names is the names of variables to include or a set of integer indices. If exact.var.names is TRUE, matches the given strings exactly. If exact.var.names is FALSE, matches any variable name that begins with any element of var.names, where the * character is treated as a wild card |
rank.normalize |
Whether to rank-normalize samples before calculating the R-hat, as in Vehtari 2019 |
sort |
If TRUE, the rhats are sorted from greatest to least |
Check if a cached MCMC has completed sampling
is.mcmc.cache.complete(dir)is.mcmc.cache.complete(dir)
dir |
The cache directory |
A boolean indicator of whether the cache is done sampling
Merges two or more mcmcsim objects by treating the chains in each as parallel chains
mcmc.merge.parallel(...)mcmc.merge.parallel(...)
Merges two or more mcmcsim objects by treating the chains in each a serial chains (ie, extensions of the previous chains)
mcmc.merge.serial(...)mcmc.merge.serial(...)
... |
One or more mcmcsim objects or lists containing only mcmcsim objects |
Generate a pairs plot of variables from an mcmc run
pair.plot( mcmc, var.names = [email protected], chains = 1:[email protected], additional.burn = 0, additional.thin = 1, exact.var.names = F )pair.plot( mcmc, var.names = mcmc@var.names, chains = 1:mcmc@n.chains, additional.burn = 0, additional.thin = 1, exact.var.names = F )
mcmc |
A mcmc.sim object |
var.names |
var.names is the names of variables to include or a set of integer indices. If exact.var.names is TRUE, matches the given strings exactly. If exact.var.names is FALSE, matches any variable name that begins with any element of var.names, where the * character is treated as a wild card |
chains |
Which chains from the MCMC to use |
exact.var.names |
var.names is the names of variables to include or a set of integer indices. If exact.var.names is TRUE, matches the given strings exactly. If exact.var.names is FALSE, matches any variable name that begins with any element of var.names, where the * character is treated as a wild card |
exporting for now for debugging
process.transformations( var.names, transformations, n.var = length(var.names), var.names.name = "var.names" )process.transformations( var.names, transformations, n.var = length(var.names), var.names.name = "var.names" )
Delete previously set-up cache for running MCMC
remove.mcmc.cache(dir, allow.remove.incomplete = F)remove.mcmc.cache(dir, allow.remove.incomplete = F)
dir |
The directory where the cache is stored |
allow.remove.incomplete |
If FALSE, the function will only succeed in removing the cached files if all the MCMC chains are complete. If TRUE, removes all file regardless |
Runs MCMC iterations from a previously set up cache
run.mcmc.from.cache( dir, chains = NULL, update.frequency = 100, update.detail = c("none", "low", "med", "high")[3], cores = parallel::detectCores(), remove.cache.when.done = F, output.file = "" )run.mcmc.from.cache( dir, chains = NULL, update.frequency = 100, update.detail = c("none", "low", "med", "high")[3], cores = parallel::detectCores(), remove.cache.when.done = F, output.file = "" )
dir |
The directory where the cache is stored |
chains |
The numbers of the chains to run. If passed NULL (the default), runs all chains |
update.frequency |
How often to print updates (print an update every update.frequency iterations). If NA, no updates are printed |
update.detail |
The level of detail for updates |
cores |
The maximum number of cores to use to run chains in parallel |
An MCMC object with length(chains) number of chains
A class representing a weighted set of simulations
simulationsA list of simulations
weightsA numeric weight for each simulation
n.simThe number of unique simulations
parametersA matrix of parameters for each simulation, where row i corresponds to the parameters used to run the ith simulation, and each column represents a parameter value
parameter.names,n.parametersThe names and number of the parameters used to run simulations
Subset an MCMC object by either burning additional iterations of the front, further thinning iterations, selecting a subset of chains, or some combination of the three
subset.mcmc( .Object, chains = 1:[email protected], additional.burn = 0, additional.thin = 1 )subset.mcmc( .Object, chains = 1:.Object@n.chains, additional.burn = 0, additional.thin = 1 )
.Object |
The mcmc.sim object |
chains |
The chains to subset |
additional.burn |
Additional number of iterations to burn off the front (this represents the number of iterations AFTER the thinning which has already been done to the mcmc.sim object but BEFORE applying additional.thin) |
additional.thin |
The factor by which to further thin iterations (applied to the already thinned simulations) |
An mcmc.sim object
Subset a simset by indexing a subset of the included simulations
subset.simset(simset, indices)subset.simset(simset, indices)
simset |
An object of class simset |
indices |
Either numeric indices or a logical mask according to which to subset simulations |
A new simset object
For a simset whose weights are integer values, extracts a subset of the simualtions by thinning every nth simulation (eg, if thin=3, the resulting simset keeps every third simulation). Maintains the weighting - simulations with higher weights are more likely to be kept
thin.simset(simset, thin)thin.simset(simset, thin)
simset |
A simset object |
thin |
How much to thin the simulations |
A thinned simset object
Generate a trace plot from an mcmc run
trace.plot( mcmc, var.names = [email protected], chains = 1:[email protected], additional.burn = 0, additional.thin = 1, exact.var.names = F, include.rhat = [email protected] > 1, ncol = NULL )trace.plot( mcmc, var.names = mcmc@var.names, chains = 1:mcmc@n.chains, additional.burn = 0, additional.thin = 1, exact.var.names = F, include.rhat = mcmc@n.chains > 1, ncol = NULL )
mcmc |
A mcmc.sim object |
var.names, exact.var.names
|
var.names is the names of variables to include or a set of integer indices. If exact.var.names is TRUE, matches the given strings exactly. If exact.var.names is FALSE, matches any variable name that begins with any element of var.names, where the * character is treated as a wild card |
chains |
Which chains from the MCMC to use |
include.rhat |
If TRUE, includes the rhat value in the facet header |
ncol |
Number of columns in the facet_wrap for the resulting plot object |