autojags: Automatically run jagsUI analyses to convergence

Description Usage Arguments Details Author(s)

View source: R/autojags.R


The autojags function runs repeated updates of jagsUI models, until a specified convergence level (based on the statistic Rhat) or a maximum number of iterations is reached.


autojags(data, inits,, model.file,
  n.chains, n.adapt=NULL, iter.increment=1000, n.burnin=0, n.thin=1,
  save.all.iter=FALSE, modules=c('glm'), factories=NULL, 
  parallel=FALSE, n.cores=NULL, DIC=TRUE,, codaOnly=FALSE,seed=NULL, 
  bugs.format=FALSE, Rhat.limit=1.1, max.iter=100000, verbose=TRUE)



A named list of the data objects required by the model, or a character vector containing the names of the data objects required by the model. Use of a character vector will be deprecated in the next version - switch to using named lists.


A list with n.chains elements; each element of the list is itself a list of starting values for the BUGS model, or a function creating (possibly random) initial values. If inits is NULL, JAGS will generate initial values for parameters.

Character vector of the names of the parameters in the model which should be monitored.


Path to file containing the model written in BUGS code


Number of Markov chains to run.


Number of iterations to run in the JAGS adaptive phase. The default is NULL, which will result in the function running groups of 100 adaptation iterations (to a max of 10,000) until JAGS reports adaptation is sufficient. If you set n.adapt manually, 1000 is the recommended minimum value.


Number of iterations per model auto-update. Set to larger values when you suspect the model will take a long time to converge.


Number of iterations at the beginning of the chain to discard (i.e., the burn-in). Does not include the adaptive phase iterations.


Thinning rate. Must be a positive integer.


Option to combine MCMC samples from all iterative updates into final posterior (by default only the final iteration is included in the posterior).


List of JAGS modules to load before analysis. By default only module 'glm' is loaded (in addition to 'basemod' and 'bugs'). To force no additional modules to load, set modules=NULL.


Optional character vector of factories to enable or disable, in the format <factory> <type> <setting>. For example, to turn TemperedMix on you would provide 'mix::TemperedMix sampler TRUE' (note spaces between parts). Make sure you have the corresponding modules loaded as well.


If TRUE, run MCMC chains in parallel on multiple CPU cores


If parallel=TRUE, specify the number of CPU cores used. Defaults to total available cores or the number of chains, whichever is smaller.


Option to report DIC and the estimated number of parameters (pD). Defaults to TRUE.

Option to store the input dataset and initial values in the output object for future use. Defaults to FALSE.


Optional character vector of parameter names for which you do NOT want to calculate detailed statistics. This may be helpful when you have many output parameters (e.g., predicted values) and you want to save time. For these parameters, only the mean value will be calculated but the mcmc output will still be found in $sims.list and $samples.


Option to set a custom seed to initialize JAGS chains, for reproducibility. Should be an integer. This argument will be deprecated in the next version, but you can always set the outside the function yourself.


Option to print JAGS output in classic R2WinBUGS format. Default is FALSE.


Set the desired cutoff point for convergence; when all Rhat values are less than this value the model assumes convergence has been reached and will stop auto-updating.


Maximum number of total iterations allowed via auto-update (including burn-in).


If set to FALSE, all text output in the console will be suppressed as the function runs (including most warnings).


Usage and output is otherwise identical to the jags function.


Ken Kellner

kenkellner/jagsUI documentation built on Oct. 10, 2020, 12:20 p.m.