| Title: | Model Builder Utility Functions and Virtual Classes |
|---|---|
| Description: | Utility functions and virtual classes shared by model builder packages such as tmbr, jmbr and smbr. |
| Authors: | Joe Thorley [aut, cre] (ORCID: <https://orcid.org/0000-0002-7683-4592>), Kirill Müller [aut] (ORCID: <https://orcid.org/0000-0002-1416-3412>), Nicole Hill [ctb] (ORCID: <https://orcid.org/0000-0002-7623-2153>), Ayla Pearson [ctb] (ORCID: <https://orcid.org/0000-0001-7388-1222>), Nadine Hussein [ctb] (ORCID: <https://orcid.org/0000-0003-4470-8361>), Poisson Consulting [cph, fnd], Seb Dalgarno [ctb] (ORCID: <https://orcid.org/0000-0002-3658-4517>) |
| Maintainer: | Joe Thorley <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0.9006 |
| Built: | 2026-07-18 08:40:47 UTC |
| Source: | https://github.com/poissonconsulting/embr |
Add analyses
add_analyses(x, x2)add_analyses(x, x2)
x |
An mb_analysis or mb_analyses object. |
x2 |
n mb_analysis or mb_analyses object. |
An object of class mb_analyses.
Add model(s)
add_models(x, x2)add_models(x, x2)
x |
An mb_model or mb_models object. |
x2 |
n mb_model or mb_models object. |
An object of class mb_models.
Computes power-scaling sensitivity and stores the result as x$sensitivity.
Subsequent calls return x unchanged unless replace = TRUE.
add_sensitivity(x, new_expr = NULL, replace = FALSE, ...)add_sensitivity(x, new_expr = NULL, replace = FALSE, ...)
x |
The object. |
new_expr |
A string of R code specifying the predictive relationship.
Must use |
replace |
A flag specifying whether to replace an existing sensitivity data frame. |
... |
Arguments passed to |
The analysis object with an added sensitivity data frame.
Fit a Bayesian hierarchical model to data using Stan (via rstan or cmdstanr)
or JAGS (via rjags). The estimation backend is determined by the model
class (JAGS or Stan) and, for Stan models, by the stan_engine argument.
analyse(x, ...) ## S3 method for class 'mb_model' analyse( x, data, nchains = getOption("mb.nchains", 3L), niters = getOption("mb.niters", 1000L), nthin = getOption("mb.thin", NULL), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), seed = sample.int(.Machine$integer.max, 1), stan_engine = getOption("mb.stan_engine", character(0)), niters_warmup = niters, ... )analyse(x, ...) ## S3 method for class 'mb_model' analyse( x, data, nchains = getOption("mb.nchains", 3L), niters = getOption("mb.niters", 1000L), nthin = getOption("mb.thin", NULL), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), seed = sample.int(.Machine$integer.max, 1), stan_engine = getOption("mb.stan_engine", character(0)), niters_warmup = niters, ... )
x |
An |
... |
Additional arguments passed to the underlying estimation function. |
data |
A data frame, or a named list of data frames for meta-analysis across datasets. |
nchains |
A count of the number of chains (default: 3). |
niters |
A count of the number of iterations to save per chain (default: 1000). |
nthin |
A count of the thinning interval. |
parallel |
A flag indicating whether to perform the analysis in parallel if possible. |
quiet |
A flag indicating whether to disable messages and warnings, including sampling progress. |
glance |
A flag indicating whether to print a model summary. |
beep |
A flag indicating whether to beep on completion of the analysis. |
seed |
A positive whole number specifying the seed to use. The default is random. This is currently only implemented for Stan models. |
stan_engine |
A string selecting the Stan engine:
Defaults to |
niters_warmup |
A count of the number of warmup iterations. The default is to use the same number of iterations as |
For Stan models using a cmdstan-* engine, embr sets a fixed set of
cmdstanr arguments from its own parameters (listed in each engine section).
These cannot be overridden via ... and are dropped with a warning if
passed. Other cmdstanr arguments pass through ....
init is the sole exception: it can be overridden via ..., replacing
inits generated by gen_inits() in model(). Non-MCMC engines do not use
gen_inits().
nthin and niters_warmup are ignored by non-MCMC engines. For
pathfinder, variational, and laplace, niters sets the number of draws
from the approximated posterior.
An mb_analysis if data is a single data frame, or an
mb_meta_analysis if data is a named list of data frames.
Calls cmdstanr::sample().
embr-controlled: chains, parallel_chains, iter_warmup,
iter_sampling, thin, data, seed, init, show_messages,
show_exceptions.
Common pass-throughs: adapt_delta, max_treedepth, step_size,
refresh, output_dir, save_warmup.
Calls cmdstanr::pathfinder().
embr-controlled: data, seed, init, draws (from niters),
show_messages, show_exceptions.
Common pass-throughs: num_paths, history_size, max_lbfgs_iters,
psis_resample, tol_rel_grad.
Calls cmdstanr::variational().
embr-controlled: data, seed, init, draws (from niters),
show_messages, show_exceptions.
Common pass-throughs: algorithm ("meanfield" or "fullrank"), iter,
tol_rel_obj, eval_elbo, eta.
Calls cmdstanr::optimize().
embr-controlled: data, seed, init, show_messages,
show_exceptions.
Common pass-throughs: algorithm ("lbfgs", "bfgs", or "newton"),
iter, tol_obj, history_size, jacobian.
Calls cmdstanr::laplace().
embr-controlled: data, seed, init, mode, draws (from niters),
show_messages, show_exceptions.
Common pass-throughs: jacobian, opt_args.
For Stan models without a stan_engine matching one of the cmdstan
options above, rstan::sampling() is called. Pass its arguments through
...; for example, control = list(adapt_delta = 0.95).
The analyse article for a walkthrough of the fitting workflow.
model() to build a model.
set_analysis_mode() to set session-wide sampling defaults.
analyse.mb_models() to fit a list of models simultaneously.
analyse.character() to fit from raw model code.
predict.mb_analysis() and coef.mb_analysis() to summarise an
analysis.
reanalyse() to refit with different sampling settings.
## Not run: # Stan model with cmdstanr MCMC analysis <- analyse(stan_model, data, stan_engine = "cmdstan-mcmc", nchains = 4, niters = 1000 ) # JAGS model analysis <- analyse(jags_model, data, nchains = 4, niters = 2000) # Engine-specific argument via ... analysis <- analyse(stan_model, data, stan_engine = "cmdstan-mcmc", adapt_delta = 0.99 ) # Override initial values for cmdstanr MCMC init_fun <- function() list(bIntercept = 0) analysis <- analyse(stan_model, data, stan_engine = "cmdstan-mcmc", init = init_fun ) # Multiple datasets analyses <- analyse(model, list(dataset1 = data1, dataset2 = data2)) ## End(Not run)## Not run: # Stan model with cmdstanr MCMC analysis <- analyse(stan_model, data, stan_engine = "cmdstan-mcmc", nchains = 4, niters = 1000 ) # JAGS model analysis <- analyse(jags_model, data, nchains = 4, niters = 2000) # Engine-specific argument via ... analysis <- analyse(stan_model, data, stan_engine = "cmdstan-mcmc", adapt_delta = 0.99 ) # Override initial values for cmdstanr MCMC init_fun <- function() list(bIntercept = 0) analysis <- analyse(stan_model, data, stan_engine = "cmdstan-mcmc", init = init_fun ) # Multiple datasets analyses <- analyse(model, list(dataset1 = data1, dataset2 = data2)) ## End(Not run)
Analyse Residuals
analyse_residuals(x)analyse_residuals(x)
x |
The mb_analysis object to analyse the residuals for. |
A convenience that builds the model and fits it in one call.
## S3 method for class 'character' analyse( x, data, select_data = list(), nchains = getOption("mb.nchains", 3L), niters = getOption("mb.niters", 1000L), nthin = getOption("mb.nthin", 1L), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), seed = sample.int(.Machine$integer.max, 1), stan_engine = getOption("mb.stan_engine", character(0)), niters_warmup = niters, ... )## S3 method for class 'character' analyse( x, data, select_data = list(), nchains = getOption("mb.nchains", 3L), niters = getOption("mb.niters", 1000L), nthin = getOption("mb.nthin", 1L), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), seed = sample.int(.Machine$integer.max, 1), stan_engine = getOption("mb.stan_engine", character(0)), niters_warmup = niters, ... )
x |
A character string of Stan or JAGS model code. |
data |
A data frame. |
select_data |
A named list specifying columns to select with their
classes, values, transforms, and scaling options. Passed to |
nchains |
A count of the number of chains (default: 3). |
niters |
A count of the number of iterations to save per chain (default: 1000). |
nthin |
A count of the thinning interval. |
parallel |
A flag indicating whether to perform the analysis in parallel if possible. |
quiet |
A flag indicating whether to disable messages and warnings, including sampling progress. |
glance |
A flag indicating whether to print a model summary. |
beep |
A flag indicating whether to beep on completion of the analysis. |
seed |
A positive whole number specifying the seed to use. The default is random. This is currently only implemented for Stan models. |
stan_engine |
A string selecting the Stan engine:
Defaults to |
niters_warmup |
A count of the number of warmup iterations. The default is to use the same number of iterations as |
... |
Additional arguments passed to |
Only select_data is forwarded to model(). If you need to set
new_expr, random_effects, new_expr_vec, or gen_inits, build the
model with model() directly and pass it to analyse().
An mb_analysis or mb_meta_analysis. See analyse() for details.
analyse() for full argument documentation and engine details.
Fits each model in an mb_models list against the same data, returning
an mb_analyses (or mb_meta_analyses if data is a list of data frames).
## S3 method for class 'mb_models' analyse( x, data, nchains = getOption("mb.nchains", 3L), niters = getOption("mb.niters", 1000L), nthin = getOption("mb.thin", NULL), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), seed = sample.int(.Machine$integer.max, 1), stan_engine = getOption("mb.stan_engine", character(0)), niters_warmup = niters, ... )## S3 method for class 'mb_models' analyse( x, data, nchains = getOption("mb.nchains", 3L), niters = getOption("mb.niters", 1000L), nthin = getOption("mb.thin", NULL), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), seed = sample.int(.Machine$integer.max, 1), stan_engine = getOption("mb.stan_engine", character(0)), niters_warmup = niters, ... )
x |
An |
data |
A data frame, or a named list of data frames for meta-analysis. |
nchains |
A count of the number of chains (default: 3). |
niters |
A count of the number of iterations to save per chain (default: 1000). |
nthin |
A count of the thinning interval. |
parallel |
A flag indicating whether to perform the analysis in parallel if possible. |
quiet |
A flag indicating whether to disable messages and warnings, including sampling progress. |
glance |
A flag indicating whether to print a model summary. |
beep |
A flag indicating whether to beep on completion of the analysis. |
seed |
A positive whole number specifying the seed to use. The default is random. This is currently only implemented for Stan models. |
stan_engine |
A string selecting the Stan engine:
Defaults to |
niters_warmup |
A count of the number of warmup iterations. The default is to use the same number of iterations as |
... |
Additional arguments passed to |
An mb_analyses (single data frame) or mb_meta_analyses (list of
data frames).
analyse() for full argument documentation and engine details.
Creates an object inherting from class mb_analyses.
analyses(...)analyses(...)
... |
Named objects. |
An object inheriting from class mb_analyses.
Coerce to an mb_analyses object
as.analyses(x, ...)as.analyses(x, ...)
x |
object to coerce. |
... |
Unused. |
Coerce to an mb_model object
as.model(x, ...)as.model(x, ...)
x |
object to coerce. |
... |
Unused. |
Coerce to an mb_models object
as.models(x, ...)as.models(x, ...)
x |
object to coerce. |
... |
Unused. |
Perform backwards step-wise regression on a model. Returns a list of the analysis at each step starting with the full model.
backwards( model, data, drops = list(), conf_level = getOption("mb.conf_level", 0.95), beep = getOption("mb.beep", TRUE), ... )backwards( model, data, drops = list(), conf_level = getOption("mb.conf_level", 0.95), beep = getOption("mb.beep", TRUE), ... )
model |
An object. |
data |
Data. |
drops |
A list of character vectors specifying the scalar parameters to consider. |
conf_level |
A number specifying the confidence level. By default 0.95. |
beep |
A flag indicating whether to beep on completion of the analysis. |
... |
Unused. |
drop is a list of character vectors specifying the scalar parameters to possibly drop. If a list element consists of two or more strings then the earlier strings are only available to drop after the later strings have been eliminated. This allows polynomial dependencies to be respected.
A list of the analyses.
Base Model
base_model(model, drops = list())base_model(model, drops = list())
model |
The full model. |
drops |
A list of character vectors specifying possible drops. |
The base model (with all drops).
Check MB Analysis
check_mb_analysis(object, object_name = substitute(object))check_mb_analysis(object, object_name = substitute(object))
object |
The object to check. |
object_name |
A string of the object name. |
The object or throws an informative error.
Check MB Code
check_mb_code(object, object_name = substitute(object))check_mb_code(object, object_name = substitute(object))
object |
The object to check. |
object_name |
A string of the object name. |
The object or throws an informative error.
Check MB Model
check_mb_model(object, object_name = substitute(object))check_mb_model(object, object_name = substitute(object))
object |
The object to check. |
object_name |
A string of the object name. |
The object or throws an informative error.
Check Model Parameters
check_model_pars(x, fixed, random, derived, drops)check_model_pars(x, fixed, random, derived, drops)
x |
The model code to check. |
fixed |
A string of a regular expression specifying the fixed parameters to monitor. |
random |
NULL or a character vector of the random effects. |
derived |
NULL or a character vector of the derived parameters. |
drops |
NULL or a character vector of the parameters to drop. |
The possibly updated derived parameters.
Check Uniquely Named List
check_uniquely_named_list(x, x_name = substitute(x))check_uniquely_named_list(x, x_name = substitute(x))
x |
The object to check. |
x_name |
A string of the objects name. |
The original object or throws an informative error.
Gets the MB code for an object.
code(object, ...)code(object, ...)
object |
The object. |
... |
Additional arguments. |
An object inheriting from class mb_code.
Gets coef confidence limits by likelihood profiling.
coef_profile(object, ...)coef_profile(object, ...)
object |
The object. |
... |
Unused. |
Coefficients for fixed parameters from an ML based MB analyses averaged by IC weights.
## S3 method for class 'mb_analyses' coef_profile( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), parallel = getOption("mb.parallel", FALSE), beep = getOption("mb.beep", TRUE), ... )## S3 method for class 'mb_analyses' coef_profile( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), parallel = getOption("mb.parallel", FALSE), beep = getOption("mb.beep", TRUE), ... )
object |
The mb_analyses object. |
param_type |
A flag specifying whether 'fixed', 'random' or 'derived' terms. |
include_constant |
A flag specifying whether to include constant terms. |
conf_level |
A number specifying the confidence level. By default 0.95. |
estimate |
The function to use to calculate the estimate for Bayesian models. |
parallel |
A flag indicating whether to using parallel backend provided by foreach. |
beep |
A flag indicating whether to beep on completion of the analysis. |
... |
Not used. |
A tidy tibble of the coeffcient terms with the model averaged estimate, the Akaike's weight and the proportion of models including the term.
Coefficients for a analysis.
## S3 method for class 'mb_analysis' coef_profile( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), parallel = getOption("mb.parallel", FALSE), beep = getOption("mb.profile", TRUE), simplify = TRUE, ... )## S3 method for class 'mb_analysis' coef_profile( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), parallel = getOption("mb.parallel", FALSE), beep = getOption("mb.profile", TRUE), simplify = TRUE, ... )
object |
The mb_analysis object. |
param_type |
A flag specifying whether 'fixed', 'random' or 'derived' terms. |
include_constant |
A flag specifying whether to include constant terms. |
conf_level |
A number specifying the confidence level. By default 0.95. |
estimate |
The function to use to calculating the estimate for Bayesian models. |
parallel |
A flag indicating whether to using parallel backend provided by foreach. |
beep |
A flag indicating whether to beep on completion of the analysis. |
simplify |
A flag specifying whether to simplify with svalue. |
... |
Not used. |
The zscore is mean / sd.
A tidy tibble of the coefficient terms.
Coef TMB Meta Analyses
## S3 method for class 'mb_meta_analyses' coef_profile( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), parallel = getOption("mb.parallel", FALSE), beep = getOption("mb.parallel", TRUE), ... )## S3 method for class 'mb_meta_analyses' coef_profile( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), parallel = getOption("mb.parallel", FALSE), beep = getOption("mb.parallel", TRUE), ... )
object |
The mb_meta_analyses object. |
param_type |
A flag specifying whether 'fixed', 'random' or 'derived' terms. |
include_constant |
A flag specifying whether to include constant terms. |
conf_level |
A number specifying the confidence level. By default 0.95. |
estimate |
The function to use to calculate the estimate. |
parallel |
A flag indicating whether to using parallel backend provided by foreach. |
beep |
A flag indicating whether to beep on completion of the analysis. |
... |
Not used. |
A tidy tibble.
Coef TMB Meta Analysis
## S3 method for class 'mb_meta_analysis' coef_profile( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), parallel = getOption("mb.parallel", FALSE), beep = getOption("mb.beep", TRUE), ... )## S3 method for class 'mb_meta_analysis' coef_profile( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), parallel = getOption("mb.parallel", FALSE), beep = getOption("mb.beep", TRUE), ... )
object |
The mb_meta_analysis object. |
param_type |
A flag specifying whether 'fixed', 'random' or 'derived' terms. |
include_constant |
A flag specifying whether to include constant terms. |
conf_level |
A number specifying the confidence level. By default 0.95. |
estimate |
The function to use to calculate the estimate. |
parallel |
A flag indicating whether to using parallel backend provided by foreach. |
beep |
A flag indicating whether to beep on completion of the analysis. |
... |
Not used. |
A tidy tibble.
Coefficients for fixed parameters from an ML based MB analyses averaged by IC weights.
## S3 method for class 'mb_analyses' coef( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), ... )## S3 method for class 'mb_analyses' coef( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), ... )
object |
The mb_analyses object. |
param_type |
A flag specifying whether 'fixed', 'random' or 'derived' terms. |
include_constant |
A flag specifying whether to include constant terms. |
conf_level |
A number specifying the confidence level. By default 0.95. |
estimate |
The function to use to calculate the estimate for Bayesian models. |
... |
Not used. |
A tidy tibble of the coeffcient terms with the model averaged estimate, the Akaike's weight and the proportion of models including the term.
Coefficients for a JAGS analysis.
## S3 method for class 'mb_analysis' coef( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), simplify = TRUE, directional_information = FALSE, ... )## S3 method for class 'mb_analysis' coef( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), simplify = TRUE, directional_information = FALSE, ... )
object |
The mb_analysis object. |
param_type |
A flag specifying whether 'fixed', 'random' or 'derived' terms. |
include_constant |
A flag specifying whether to include constant terms. |
conf_level |
A number specifying the confidence level. By default 0.95. |
estimate |
The function to use to calculating the estimate for Bayesian models. |
simplify |
Must be |
directional_information |
A flag specifying whether the svalue column
for a Bayesian analysis should be calculated using
|
... |
Not used. |
A tidy tibble of the coefficient terms with the columns indicating
the term, estimate, lower and upper confidence or credible intervals
and svalue.
Coef TMB Meta Analyses
## S3 method for class 'mb_meta_analyses' coef( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), ... )## S3 method for class 'mb_meta_analyses' coef( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), ... )
object |
The mb_meta_analyses object. |
param_type |
A flag specifying whether 'fixed', 'random' or 'derived' terms. |
include_constant |
A flag specifying whether to include constant terms. |
conf_level |
A number specifying the confidence level. By default 0.95. |
estimate |
The function to use to calculate the estimate. |
... |
Not used. |
A tidy tibble.
Coef TMB Meta Analysis
## S3 method for class 'mb_meta_analysis' coef( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), ... )## S3 method for class 'mb_meta_analysis' coef( object, param_type = "fixed", include_constant = TRUE, conf_level = getOption("mb.conf_level", 0.95), estimate = getOption("mb.estimate", median), ... )
object |
The mb_meta_analysis object. |
param_type |
A flag specifying whether 'fixed', 'random' or 'derived' terms. |
include_constant |
A flag specifying whether to include constant terms. |
conf_level |
A number specifying the confidence level. By default 0.95. |
estimate |
The function to use to calculate the estimate. |
... |
Not used. |
A tidy tibble.
Returns the regular expression used to identify the start of a comment in an mb_code object.
comment_string(object, ...)comment_string(object, ...)
object |
The mb code object. |
... |
Unused. |
A string of the regular expression.
Gets the data set for an object inheriting from class mb_analysis.
data_set( x, modify = FALSE, numericize_factors = FALSE, marginalize_random_effects = FALSE, ... )data_set( x, modify = FALSE, numericize_factors = FALSE, marginalize_random_effects = FALSE, ... )
x |
The object. |
modify |
A flag indicating whether to modify the data. |
numericize_factors |
A flag indicating whether to convert factors to integers if modifying the data. |
marginalize_random_effects |
A flag indicating whether to set each factor in one or more random effects at its first level. |
... |
Unused. |
The data set as a tibble.
dummy data
density99density99
An object of class data.frame with 300 rows and 5 columns.
Drops named scalar fixed pars from an object by fixing them at 0.
drop_pars(x, pars = character(0), ...)drop_pars(x, pars = character(0), ...)
x |
The object. |
pars |
A character vector of the pars to drop. |
... |
Not used. |
The updated object.
Get elapsed duration.
elapsed(x, ...)elapsed(x, ...)
x |
The object to calculate it for. |
... |
Not used. |
Calculates the estimates for an MCMC object.
## S3 method for class 'mb_analysis' estimates(x, param_type = "fixed", ...)## S3 method for class 'mb_analysis' estimates(x, param_type = "fixed", ...)
x |
An object. |
param_type |
A string indicating the type of terms to get the names for. |
... |
Other arguments passed to methods. |
A list of uniquely named numeric objects.
Other MCMC manipulations:
bind_chains(),
bind_iterations(),
collapse_chains(),
split_chains()
Extract fitted values for a MB analysis.
## S3 method for class 'mb_analysis' fitted(object, ...)## S3 method for class 'mb_analysis' fitted(object, ...)
object |
The MB analysis object. |
... |
Unused. |
The new_expr in the model must include the term 'fit'.
The analysis data set with the fitted values.
Gets analysis mode.
get_analysis_mode()get_analysis_mode()
Retrieves what is set for each of the following package options.
A count of the number of chains.
A count of the number of simulations to save per chain.
A count of the thining interval.
A flag indicating whether to perform the analysis in parallel.
A flag indicating whether to disable tracing information.
A flag indicating whether to beep on completion of the analysis.
A flag indicating whether to print a model summary.
A count specifying the maximum number of reanalyses.
A number specifying the rhat threshold.
A number specifying the minimum effective sampling rate.
The maximum total time to spend on analysis and reanalysis.
A number specifying the confidence level.
A named list of the current package options.
## Not run: get_analysis_mode() ## End(Not run)## Not run: get_analysis_mode() ## End(Not run)
Constucts a new analysis object
get_model(analysis)get_model(analysis)
analysis |
An object of class |
Calculates Information Criterion for an analysis.
IC(object, ...)IC(object, ...)
object |
The object to calculate the IC for. |
... |
Not used. |
The Information Criteron as a number.
Test if is bayesian
is_bayesian(x, ...)is_bayesian(x, ...)
x |
the object. |
... |
Unused |
A flag indicating wether bayesian.
Test if is frequentist
is_frequentist(x)is_frequentist(x)
x |
the object. |
A flag indicating whether frequentist
Is Named List
is_namedlist(x)is_namedlist(x)
x |
The object to test. |
A flag.
is_namedlist(1) is_namedlist(list()) is_namedlist(list(1)) is_namedlist(list(x = 1)) is_namedlist(list(x = list(y = 2)))is_namedlist(1) is_namedlist(list()) is_namedlist(list(1)) is_namedlist(list(x = 1)) is_namedlist(list(x = list(y = 2)))
Tests whether x is an object of class 'lmb_analysis'
is.lmb_analysis(x)is.lmb_analysis(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Tests whether x is an object of class 'lmb_code'
is.lmb_code(x)is.lmb_code(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Tests whether x is an object of class 'lmb_model'
is.lmb_model(x)is.lmb_model(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Tests whether x is an object of class 'mb_analyses'
is.mb_analyses(x)is.mb_analyses(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Tests whether x is an object of class 'mb_analysis'
is.mb_analysis(x)is.mb_analysis(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Tests whether x is an object of class 'mb_model'
is.mb_code(x)is.mb_code(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Tests whether x is an object of class 'mb_model'
is.mb_model(x)is.mb_model(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Tests whether x is an object of class 'mb_models'
is.mb_models(x)is.mb_models(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Tests whether x is an object of class 'mb_null_analysis'
is.mb_null_analysis(x)is.mb_null_analysis(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Is syntactic
is.syntactic(x)is.syntactic(x)
x |
A character of possible variable names. |
A logical vector indicating whether a syntactically correct variable name.
is.syntactic(c("0", "x", "1x", "x y", "x1"))is.syntactic(c("0", "x", "1x", "x y", "x1"))
Load Model
load_model(x, quiet, ...)load_model(x, quiet, ...)
x |
The model to load. |
quiet |
A flag indicating whether to suppress warnings and output. |
... |
Additional arguments. |
Extract log likelihood from fitted model and return as a draws
object. Adapted from the priorsense package.
## S3 method for class 'mb_analysis' log_lik_draws(x, joint = FALSE, log_lik_name = "log_lik", ...)## S3 method for class 'mb_analysis' log_lik_draws(x, joint = FALSE, log_lik_name = "log_lik", ...)
x |
The mb_analysis object. |
joint |
A flag indicating whether to return the joint log likelihood or array, default is FALSE. |
log_lik_name |
A string of the name of the parameter corresponding to the log likelihood, default is "log_lik". |
... |
Unused. |
A draws_array object containing log_lik values.
Extract log likelihood from fitted model and return as a draws
object. Adapted from the priorsense package.
## S3 method for class 'mb_analysis' log_prior_draws(x, joint = FALSE, log_prior_name = "lprior", ...)## S3 method for class 'mb_analysis' log_prior_draws(x, joint = FALSE, log_prior_name = "lprior", ...)
x |
The mb_analysis object. |
joint |
A flag indicating whether to return the joint log likelihood or array, default is FALSE. |
log_prior_name |
A string of the name of the parameter corresponding to the log prior, default is "lprior". |
... |
Unused. |
A draws_array object containing log_prior values.
Log-Likelihood for a MB analysis.
## S3 method for class 'mb_analysis' logLik(object, ...)## S3 method for class 'mb_analysis' logLik(object, ...)
object |
The mb_analysis object. |
... |
unused. |
Log-Likelihood for a MB NULL analysis.
## S3 method for class 'mb_null_analysis' logLik(object, ...)## S3 method for class 'mb_null_analysis' logLik(object, ...)
object |
The mb_analysis object. |
... |
unused. |
Make All Models
make_all_models(model, drops = list())make_all_models(model, drops = list())
model |
The full model. |
drops |
A list of character vectors specifying possible drops. |
A list of objects inheriting from class mb_model.
Identifies the type of the code and creates an object of the appropriate class.
mb_code(template) new_mb_code(x, class)mb_code(template) new_mb_code(x, class)
template |
A string, a braced |
x |
A string or a braced |
class |
The class of the new object. |
An object inheriting from class mb_code.
x <- mb_code( "#include <TMB.hpp> template<class Type> Type objective_function<Type>::operator() () { DATA_VECTOR(Count); PARAMETER(bIntercept); int n = Count.size(); Type nll = 0.0; for(int i = 0; i < n; i++){ nll -= dpois(Count(i), bIntercept, true); } return nll; } " ) class(x)x <- mb_code( "#include <TMB.hpp> template<class Type> Type objective_function<Type>::operator() () { DATA_VECTOR(Count); PARAMETER(bIntercept); int n = Count.size(); Type nll = 0.0; for(int i = 0; i < n; i++){ nll -= dpois(Count(i), bIntercept, true); } return nll; } " ) class(x)
Calculate derived parameters.
## S3 method for class 'mb_analyses' mcmc_derive_data( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", modify_new_data = NULL, ref_data = FALSE, ref_fun2 = proportional_change2, new_expr_vec = getOption("mb.new_expr_vec", FALSE), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), beep = getOption("mb.beep", FALSE), ... )## S3 method for class 'mb_analyses' mcmc_derive_data( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", modify_new_data = NULL, ref_data = FALSE, ref_fun2 = proportional_change2, new_expr_vec = getOption("mb.new_expr_vec", FALSE), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), beep = getOption("mb.beep", FALSE), ... )
object |
An object inheriting from class mb_analysis. |
new_data |
The data frame to calculate the predictions for. |
new_expr |
An R expression (e.g. |
new_values |
A named list of new or replacement values to pass to new_expr. |
term |
A string of the term in new_expr. |
modify_new_data |
A single argument function to modify new data (in list form) immediately prior to calculating new_expr. |
ref_data |
A flag or a data frame with 1 row indicating the reference values for calculating the effects size. |
ref_fun2 |
A function whose first argument takes a vector of two numbers and returns a scalar of a metric of the difference between them. |
new_expr_vec |
A flag specifying whether to vectorize the new_expr code. |
parallel |
A flag indicating whether to do predictions using parallel backend provided by foreach. |
quiet |
A flag indicating whether to disable tracing information. |
beep |
A flag indicating whether to beep on completion of the analysis. |
... |
Additional arguments. |
A object of class mcmc_data.
mcmc_derive_data.mb_analysis() for full argument documentation
and examples.
Calculate derived parameters.
## S3 method for class 'mb_analysis' mcmc_derive_data( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", modify_new_data = NULL, ref_data = FALSE, ref_fun2 = proportional_change2, new_expr_vec = getOption("mb.new_expr_vec", FALSE), random_effects = NULL, parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), beep = getOption("mb.beep", FALSE), ... )## S3 method for class 'mb_analysis' mcmc_derive_data( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", modify_new_data = NULL, ref_data = FALSE, ref_fun2 = proportional_change2, new_expr_vec = getOption("mb.new_expr_vec", FALSE), random_effects = NULL, parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), beep = getOption("mb.beep", FALSE), ... )
object |
An object inheriting from class mb_analysis. |
new_data |
A data frame at which to derive the term.
Pass |
new_expr |
An R expression (e.g. |
new_values |
A named list of new or replacement values to pass to new_expr. |
term |
A string of the term in new_expr. |
modify_new_data |
A single argument function to modify new data (in list form) immediately prior to calculating new_expr. |
ref_data |
A flag or a data frame with 1 row indicating the reference values for calculating the effects size.
If |
ref_fun2 |
A function whose first argument takes a vector of two numbers and returns a scalar of a metric of the difference between them. |
new_expr_vec |
A flag specifying whether to vectorize the new_expr code. |
random_effects |
A named list specifying the random effects and the associated factors. |
parallel |
A flag indicating whether to do predictions using parallel backend provided by foreach. |
quiet |
A flag indicating whether to disable tracing information. |
beep |
A flag indicating whether to beep on completion of the analysis. |
... |
Additional arguments. |
A object of class mcmc_data.
The prediction article for worked patterns including group-level summaries.
predict.mb_analysis() for tidy posterior summaries at new covariate
values.
mcmc_derive.mb_analysis() for scalar derived quantities and arithmetic
on mcmcr posteriors.
mcmcr::combine_samples() for combining MCMC samples across independent
analyses on shared data keys.
newdata::xnew_data() for building covariate grids.
## Not run: # `analysis` is a fitted mb_analysis with factors site, treatment and # new_expr that defines per-row term `eCount`. data <- data_set(analysis) # Per-group posterior summaries via group_by() + summarise(). # Default .fun = sum; use mean for the per-treatment posterior mean. mcmc_derive_data(analysis, new_data = data, term = "^eCount$") |> group_by(treatment) |> summarise(.fun = mean) |> coef() # Custom summarise function, e.g. range within group mcmc_derive_data(analysis, new_data = data, term = "^eCount$") |> group_by(treatment) |> summarise(.fun = function(x) max(x) - min(x)) |> coef() ## End(Not run)## Not run: # `analysis` is a fitted mb_analysis with factors site, treatment and # new_expr that defines per-row term `eCount`. data <- data_set(analysis) # Per-group posterior summaries via group_by() + summarise(). # Default .fun = sum; use mean for the per-treatment posterior mean. mcmc_derive_data(analysis, new_data = data, term = "^eCount$") |> group_by(treatment) |> summarise(.fun = mean) |> coef() # Custom summarise function, e.g. range within group mcmc_derive_data(analysis, new_data = data, term = "^eCount$") |> group_by(treatment) |> summarise(.fun = function(x) max(x) - min(x)) |> coef() ## End(Not run)
Calculate derived parameters.
## S3 method for class 'mb_analysis' mcmc_derive( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", modify_new_data = NULL, ref_data = FALSE, ref_fun2 = proportional_change2, random_effects = NULL, new_expr_vec = getOption("mb.new_expr_vec", FALSE), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), ... ) ## S3 method for class 'mb_analyses' mcmc_derive( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", modify_new_data = NULL, ref_data = FALSE, new_expr_vec = getOption("mb.new_expr_vec", FALSE), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), ... )## S3 method for class 'mb_analysis' mcmc_derive( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", modify_new_data = NULL, ref_data = FALSE, ref_fun2 = proportional_change2, random_effects = NULL, new_expr_vec = getOption("mb.new_expr_vec", FALSE), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), ... ) ## S3 method for class 'mb_analyses' mcmc_derive( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", modify_new_data = NULL, ref_data = FALSE, new_expr_vec = getOption("mb.new_expr_vec", FALSE), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), ... )
object |
An object inheriting from class mb_analysis. |
new_data |
A data frame at which to derive the term.
Pass |
new_expr |
An R expression (e.g. |
new_values |
A named list of new or replacement values to pass to new_expr. |
term |
A string of the term in new_expr. |
modify_new_data |
A single argument function to modify new data (in list form) immediately prior to calculating new_expr. |
ref_data |
A flag or a data frame with 1 row indicating the reference values for calculating the effects size.
If |
ref_fun2 |
A function whose first argument takes a vector of two numbers and returns a scalar of a metric of the difference between them. |
random_effects |
A named list specifying the random effects and the associated factors. |
new_expr_vec |
A flag specifying whether to vectorize the new_expr code. |
parallel |
A flag indicating whether to do predictions using parallel backend provided by foreach. |
quiet |
A flag indicating whether to disable tracing information. |
... |
Additional arguments. |
A object of class mcmcr.
The prediction article
for worked patterns including arithmetic on mcmcr posteriors.
predict.mb_analysis() for tidy posterior summaries at new covariate
values.
mcmc_derive_data.mb_analysis() for raw MCMC samples paired with
new_data and group-level summaries.
mcmcr::combine_samples() for combining MCMC samples across independent
analyses on shared data keys.
## Not run: # Pull multiple scalar terms in one call by regex. Quantities defined in # new_expr are usually easiest to extract individually with predict(); # mcmc_derive() is most useful when (a) you want raw mcmcr samples for # downstream operations predict() does not support (probability # statements, custom quantiles) or (b) you want to compose multiple terms # with arbitrary arithmetic. See vignette("prediction") for worked # patterns. scalars <- mcmc_derive( analysis, new_data = character(0), term = "^(eBaseCount|eRestoredEffect)$" ) coef(scalars) # Custom expression with injected scalar constants as.mcmcr(analysis) |> mcmc_derive( expr = "biomass <- exp(bIntercept) * mean_mass_g", values = list(mean_mass_g = 250) ) |> coef() ## End(Not run)## Not run: # Pull multiple scalar terms in one call by regex. Quantities defined in # new_expr are usually easiest to extract individually with predict(); # mcmc_derive() is most useful when (a) you want raw mcmcr samples for # downstream operations predict() does not support (probability # statements, custom quantiles) or (b) you want to compose multiple terms # with arbitrary arithmetic. See vignette("prediction") for worked # patterns. scalars <- mcmc_derive( analysis, new_data = character(0), term = "^(eBaseCount|eRestoredEffect)$" ) coef(scalars) # Custom expression with injected scalar constants as.mcmcr(analysis) |> mcmc_derive( expr = "biomass <- exp(bIntercept) * mean_mass_g", values = list(mean_mass_g = 250) ) |> coef() ## End(Not run)
Define a model, including code, data, monitoring, and post-fitting
specification. The returned mb_model is consumed by analyse() and
downstream by predict.mb_analysis() and mcmc_derive_data().
model( x = NULL, ..., code = NULL, gen_inits = NULL, random_effects = list(), fixed = getOption("mb.fixed", "^[^e]"), derived = character(0), select_data = list(), center = character(0), scale = character(0), modify_data = identity, nthin = getOption("mb.nthin", 1L), new_expr = NULL, new_expr_vec = getOption("mb.new_expr_vec", FALSE), modify_new_data = identity, drops = list() )model( x = NULL, ..., code = NULL, gen_inits = NULL, random_effects = list(), fixed = getOption("mb.fixed", "^[^e]"), derived = character(0), select_data = list(), center = character(0), scale = character(0), modify_data = identity, nthin = getOption("mb.nthin", 1L), new_expr = NULL, new_expr_vec = getOption("mb.new_expr_vec", FALSE), modify_new_data = identity, drops = list() )
x |
An |
... |
These dots are for future extensions and must be empty. |
code |
Model code (Stan or JAGS expression or string) to pass to
|
gen_inits |
A single-argument function returning a named list of
initial values per chain. Receives the modified data list (i.e. after
|
random_effects |
Named list mapping parameter names in the model
code to one or more grouping factor columns from |
fixed |
A string of a regular expression of parameter names to monitor as fixed effects. |
derived |
A character vector of derived parameters to monitor. |
select_data |
A named list specifying the columns to select and their expected classes and values as well as transformations and scaling options. See the select_data section of |
center |
A character vector of the columns to center. |
scale |
A character vector of the columns to scale (after centering). |
modify_data |
A single argument function to modify the data (in list form) immediately prior to the analysis. |
nthin |
An integer specifying the thinning interval. |
new_expr |
An R expression or character string of R code defining
the predictive relationships and derived quantities. See the new_expr
section of |
new_expr_vec |
Flag controlling whether to vectorise the |
modify_new_data |
SA single argument function to modify new data (in list form) immediately prior to calculating new_expr. |
drops |
A list of character vectors naming scalar parameters to fix at 0 in the model. |
The data passed to analyse() is transformed through a fixed pipeline
before reaching the model code: select_data selects columns and applies
any rescaling suffixes; logical, date, and difftime columns are coerced to
numeric; one n<Factor> count is injected per factor; nObs is injected;
and finally the user's modify_data function runs against the resulting
list. gen_inits is then invoked against this same modified list, once
per chain, to seed initial values.
The monitored parameter set is the union of: names matching the fixed
regex, the names of random_effects, and derived. The default
fixed = "^[^e]" matches everything not starting with e. Names listed
in random_effects are always monitored regardless of the regex.
An object inheriting from class "mb_model".
Named list mapping data column names to type or range specifications: 1L for integer, 1
for numeric, factor("") for factor, TRUE for logical. Where an
explicit check is wanted, use a range form such as c(0L, 100L) and
append NA to allow missing values: c(0L, 100L, NA).
Appending a suffix to a column name requests a rescaling transformation; the original column is replaced with the transformed version in the analysis dataset.
| Suffix | Transformation |
| (none) | Raw, untransformed |
+ |
Subtract the mean (center) |
- |
Subtract the minimum (shift to 0) |
= |
Subtract the minimum and add 1 (shift to 1) |
/ |
Divide by SD (scale) |
* |
Subtract the mean and divide by SD (standardise) |
* is conventional for continuous covariates and + for year or date
variables. Never apply a suffix to the response. The center and scale
character-vector arguments are kept for backwards compatibility and emit
a deprecation warning; prefer select_data suffixes.
An R expression (e.g. { ... }) or a character string of R code that is
evaluated post-fitting against the MCMC draws. It has access to the
sampled parameters, the modified data list, and extras helpers such as
log_lik_* and res_*. The expression typically defines the named terms
used by downstream tooling:
prediction[i] for predict.mb_analysis()
fit[i] for fitted.mb_analysis() and for residuals
log_lik[i] for information criteria and prior sensitivity
lprior[k] for prior sensitivity
The scale of fit[i] is model-specific: define it to match the signature
of the res_* and log_lik_* helpers you use (e.g. response-scale for
res_neg_binom, log-scale for res_student on log-normal data). Scalar
derived quantities defined outside the loop are extractable via
predict(analysis, new_data = character(0), term = "myScalar").
If new_expr is supplied as a string without wrapping braces they are
added automatically. Setting new_expr_vec = TRUE vectorises the for-loop
body via mcmcderive::expression_vectorize() for substantial speed gains.
Vectorisation silently falls back to the un-vectorised loop (no error)
when the loop body contains sum(), nested for loops, or dynamic range
indexing such as eK[year[i]:(year[i] + n)]. Safe patterns: linear
predictors built from indexed terms, single-level (bSite[site[i]]) and
multi-level (bParam[site[i], annual[i]]) indexing, link-function
assignments (log(eY[i]) <- ...), and polynomial terms on standardised
predictors.
The analyse article
for a walkthrough including select_data transformations and new_expr
structure.
analyse() to fit the model to data.
analyse.character() for a shortcut that builds and fits in one call.
update_model() to change arguments on an existing mb_model.
## Not run: # Stan model with a standardised continuous covariate and a site # random effect. count_model <- model( code = count_code, # a string or read_file("stan/count.stan") select_data = list( count = 1L, site = factor("a"), `temperature*` = 1 ), random_effects = list(z_bSite = "site"), new_expr = { bSite <- z_bSite * sSite for (i in 1:nObs) { log(eCount[i]) <- bIntercept + bTemp * temperature[i] + bSite[site[i]] prediction[i] <- eCount[i] fit[i] <- eCount[i] log_lik[i] <- log_lik_neg_binom(count[i], eCount[i], bPhi) } }, new_expr_vec = TRUE ) # Reshape multi-pass data into a matrix and add a per-row pass count # before the analysis runs; seed eAbundance with the observed totals. depletion_model <- model( code = depletion_code, select_data = list( Pass1 = 1L, Pass2 = 1L, Pass3 = 1L, site = factor("a") ), modify_data = function(data) { Pass <- as.matrix(data[c("Pass1", "Pass2", "Pass3")]) data$Pass <- Pass data$nPass <- ncol(Pass) data$Pass1 <- data$Pass2 <- data$Pass3 <- NULL data }, gen_inits = function(data) { list(eAbundance = rowSums(data$Pass, na.rm = TRUE) + 1) } ) ## End(Not run)## Not run: # Stan model with a standardised continuous covariate and a site # random effect. count_model <- model( code = count_code, # a string or read_file("stan/count.stan") select_data = list( count = 1L, site = factor("a"), `temperature*` = 1 ), random_effects = list(z_bSite = "site"), new_expr = { bSite <- z_bSite * sSite for (i in 1:nObs) { log(eCount[i]) <- bIntercept + bTemp * temperature[i] + bSite[site[i]] prediction[i] <- eCount[i] fit[i] <- eCount[i] log_lik[i] <- log_lik_neg_binom(count[i], eCount[i], bPhi) } }, new_expr_vec = TRUE ) # Reshape multi-pass data into a matrix and add a per-row pass count # before the analysis runs; seed eAbundance with the observed totals. depletion_model <- model( code = depletion_code, select_data = list( Pass1 = 1L, Pass2 = 1L, Pass3 = 1L, site = factor("a") ), modify_data = function(data) { Pass <- as.matrix(data[c("Pass1", "Pass2", "Pass3")]) data$Pass <- Pass data$nPass <- ncol(Pass) data$Pass1 <- data$Pass2 <- data$Pass3 <- NULL data }, gen_inits = function(data) { list(eAbundance = rowSums(data$Pass, na.rm = TRUE) + 1) } ) ## End(Not run)
Creates an object inherting from class mb_models.
models(...)models(...)
... |
Named objects. |
An object inheriting from class mb_models.
Modifies a data frame to the form it will be passed to the analysis code.
modify_data(data, model, numericize_factors = FALSE)modify_data(data, model, numericize_factors = FALSE)
data |
The data to modify. |
model |
An object inheriting from class mb_model. |
numericize_factors |
A flag indicating whether to convert factors to integer. |
The modified data in list form.
Modifies a data frame to the form it will be passed to the analysis code.
modify_new_data( data, data2, model, modify_new_data = NULL, numericize_factors = FALSE )modify_new_data( data, data2, model, modify_new_data = NULL, numericize_factors = FALSE )
data |
The data to modify. |
data2 |
The base data. |
model |
An object inheriting from class mb_model. |
modify_new_data |
A single argument function to modify new data (in list form) immediately prior to calculating new_expr. |
numericize_factors |
A flag indicating whether to convert factors to integer. |
The modified data in list form.
pars to monitor
monitor(object, param_type = "all")monitor(object, param_type = "all")
object |
An mb model object to get the pars for. |
param_type |
A string specifying the type of pars to get. |
A character vector of the pars to monitor.
Constucts a new analysis object
new_analysis(x, class)new_analysis(x, class)
x |
A list. |
class |
The class of the new object. |
new_expr
new_expr(object, ...)new_expr(object, ...)
object |
The object to get for. |
... |
Not used. |
The new_expr
new_expr set
new_expr(object) <- valuenew_expr(object) <- value
object |
The object to set for. |
value |
The new value of new expr. |
The modified object.
Total Number of MCMC simulations generated (including warmup)
ngens(x, ...)ngens(x, ...)
x |
The object |
... |
Unused. |
A count.
Number Models
nmodels(x, ...)nmodels(x, ...)
x |
the object. |
... |
Named objects. |
An integer of the number of models
Number of terms
## S3 method for class 'mb_analysis' nterms(x, param_type = "fixed", include_constant = TRUE, ...)## S3 method for class 'mb_analysis' nterms(x, param_type = "fixed", include_constant = TRUE, ...)
x |
The object to get the nterms for |
param_type |
A string indicating the type of terms to get the names for. |
include_constant |
A flag specifying whether to include constant terms. |
... |
unused |
Thinning Rate
nthin(x, ...)nthin(x, ...)
x |
The object |
... |
Unused. |
A count.
Parameter Descriptions
param_type |
A string indicating the type of terms to get the names for. |
type |
A string of the residual type. |
nchains |
A count of the number of chains (default: 3). |
niters |
A count of the number of iterations to save per chain (default: 1000). |
nthin |
A count of the thinning interval. |
parallel |
A flag indicating whether to perform the analysis in parallel if possible. |
quiet |
A flag indicating whether to disable messages and warnings, including sampling progress. |
glance |
A flag indicating whether to print a model summary. |
beep |
A flag indicating whether to beep on completion of the analysis. |
seed |
A positive whole number specifying the seed to use. The default is random. This is currently only implemented for Stan models. |
niters_warmup |
A count of the number of warmup iterations. The default is to use the same number of iterations as |
stan_engine |
A string selecting the Stan engine:
Defaults to |
... |
Unused. |
Plot Data
plot_data(x, ...)plot_data(x, ...)
x |
The object to plot the data for. |
... |
Unused. |
Plot Residuals
plot_residuals(x, ...)plot_residuals(x, ...)
x |
The object to plot the residuals for. |
... |
Unused. |
Plot Analysis
## S3 method for class 'mb_analysis' plot(x, param_type = "fixed", ...)## S3 method for class 'mb_analysis' plot(x, param_type = "fixed", ...)
x |
The analysis object to plot |
param_type |
A string indicating the type of terms to get the names for. |
... |
Unused. |
Simulates
posterior_predictive_check(x, ...)posterior_predictive_check(x, ...)
x |
The object |
... |
Unused. |
A tibble of the checks.
Posterior Predictive Check
## S3 method for class 'mb_analysis' posterior_predictive_check(x, zeros = TRUE, ...)## S3 method for class 'mb_analysis' posterior_predictive_check(x, zeros = TRUE, ...)
x |
The MB analysis object. |
zeros |
A flag specifying whether to perform a posterior predictive check on the number of zeros in the data. |
... |
Unused. |
A tibble of the checks.
Calculates the prior/likelihood sensitivity based on power-scaling perturbations. This is done using importance sampling (and optionally moment matching).
## S3 method for class 'mb_analysis' powerscale_sensitivity(x, ...)## S3 method for class 'mb_analysis' powerscale_sensitivity(x, ...)
x |
The mb_analysis object. |
... |
Arguments passed to methods to
|
Table of sensitivity values for each specified variable.
mb_analyses objectReturns IC-weighted model-averaged predictions across an mb_analyses list.
## S3 method for class 'mb_analyses' predict( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", conf_level = getOption("mb.conf_level", 0.95), modify_new_data = NULL, ref_data = FALSE, ref_fun2 = proportional_change2, new_expr_vec = getOption("mb.new_expr_vec", FALSE), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), ... )## S3 method for class 'mb_analyses' predict( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", conf_level = getOption("mb.conf_level", 0.95), modify_new_data = NULL, ref_data = FALSE, ref_fun2 = proportional_change2, new_expr_vec = getOption("mb.new_expr_vec", FALSE), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), ... )
object |
An object inheriting from class mb_analysis. |
new_data |
A data frame at which to derive the term.
Pass |
new_expr |
An R expression (e.g. |
new_values |
A named list of new or replacement values to pass to new_expr. |
term |
A string of the term in new_expr. |
conf_level |
A number specifying the confidence level. By default 0.95. |
modify_new_data |
A single argument function to modify new data (in list form) immediately prior to calculating new_expr. |
ref_data |
A flag or a data frame with 1 row indicating the reference values for calculating the effects size.
If |
ref_fun2 |
A function whose first argument takes a vector of two numbers and returns a scalar of a metric of the difference between them. |
new_expr_vec |
A flag specifying whether to vectorize the new_expr code. |
parallel |
A flag indicating whether to do predictions using parallel backend provided by foreach. |
quiet |
A flag indicating whether to disable tracing information. |
... |
Additional arguments. |
A data frame with one row per row of new_data.
predict.mb_analysis() for full argument documentation and
examples.
mb_analysis objectSummarises the posterior predictive distribution at new covariate values. Returns a tidy data frame with point estimates and compatibility limits.
## S3 method for class 'mb_analysis' predict( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", conf_level = getOption("mb.conf_level", 0.95), modify_new_data = NULL, ref_data = FALSE, ref_fun2 = proportional_change2, new_expr_vec = getOption("mb.new_expr_vec", FALSE), random_effects = NULL, parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), ... )## S3 method for class 'mb_analysis' predict( object, new_data = data_set(object), new_expr = NULL, new_values = list(), term = "prediction", conf_level = getOption("mb.conf_level", 0.95), modify_new_data = NULL, ref_data = FALSE, ref_fun2 = proportional_change2, new_expr_vec = getOption("mb.new_expr_vec", FALSE), random_effects = NULL, parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), ... )
object |
An object inheriting from class mb_analysis. |
new_data |
A data frame at which to derive the term.
Pass |
new_expr |
An R expression (e.g. |
new_values |
A named list of new or replacement values to pass to new_expr. |
term |
A string of the term in new_expr. |
conf_level |
A number specifying the confidence level. By default 0.95. |
modify_new_data |
A single argument function to modify new data (in list form) immediately prior to calculating new_expr. |
ref_data |
A flag or a data frame with 1 row indicating the reference values for calculating the effects size.
If |
ref_fun2 |
A function whose first argument takes a vector of two numbers and returns a scalar of a metric of the difference between them. |
new_expr_vec |
A flag specifying whether to vectorize the new_expr code. |
random_effects |
A named list specifying the random effects and the associated factors. |
parallel |
A flag indicating whether to do predictions using parallel backend provided by foreach. |
quiet |
A flag indicating whether to disable tracing information. |
... |
Additional arguments. |
new_data defaults to data_set(object) (the analysis dataset). Build
covariate grids with
newdata::xnew_data() and related helpers (newdata::xnew_seq(),
newdata::xcast(), newdata::xobs_only()) for explicit control over
which covariates vary. A character vector of column names is also accepted
as a shortcut: predict(analysis, "year") is equivalent to
predict(analysis, new_data = newdata::xnew_data(data_set(analysis), year)),
which generates a grid varying year and holding the rest at their
reference values. Covariates not specified are held at a reference value:
mean for continuous, first level for factors.
term selects the quantity defined in the model's new_expr to calculate
(default "prediction"). Pass new_data = character(0) to extract a scalar
quantity.
A data frame with one row per row of new_data, containing the
posterior summary columns produced by coef.mcmc_data() and all columns
of new_data.
The prediction article for detailed examples of prediction patterns.
predict.mb_analyses() for predictions on meta-analysis object.
mcmc_derive_data.mb_analysis() for raw MCMC samples paired with
new_data, regex term matching, and group-level summaries via
group_by() + summarise().
mcmc_derive.mb_analysis() for scalar derived quantities and arithmetic
on mcmcr posteriors.
mcmcr::combine_samples() for combining MCMC samples across independent
analyses on shared data keys.
newdata::xnew_data() for building covariate grids.
## Not run: library(newdata) data <- data_set(analysis) # Character shortcut: vary a single column, hold others at reference predict(analysis, "temperature") # Equivalent explicit form xnew_data(data, temperature) |> predict(analysis, new_data = _) # Set custom sequence for continuous covariate xnew_data(data, xnew_seq(temperature, length_out = 5)) |> predict(analysis, new_data = _) # Predict for all factor levels and set specific continuous reference value xnew_data(data, site, temperature = 5) |> predict(analysis, new_data = _) # Predict only for observed combinations of factor levels xnew_data(data, xobs_only(site, annual)) |> predict(analysis, new_data = _) # Proportional change relative to a 1-row reference state ref <- xnew_data(data, xcast(treatment = "control")) xnew_data(data, treatment) |> predict(analysis, new_data = _, ref_data = ref) # Predict for first level of random effect levels rather than 'typical' xnew_data(data, temperature) |> predict(analysis, new_data = _, random_effects = FALSE) # Extract a scalar derived quantity from new_expr predict(analysis, new_data = character(0), term = "eBaseCount") ## End(Not run)## Not run: library(newdata) data <- data_set(analysis) # Character shortcut: vary a single column, hold others at reference predict(analysis, "temperature") # Equivalent explicit form xnew_data(data, temperature) |> predict(analysis, new_data = _) # Set custom sequence for continuous covariate xnew_data(data, xnew_seq(temperature, length_out = 5)) |> predict(analysis, new_data = _) # Predict for all factor levels and set specific continuous reference value xnew_data(data, site, temperature = 5) |> predict(analysis, new_data = _) # Predict only for observed combinations of factor levels xnew_data(data, xobs_only(site, annual)) |> predict(analysis, new_data = _) # Proportional change relative to a 1-row reference state ref <- xnew_data(data, xcast(treatment = "control")) xnew_data(data, treatment) |> predict(analysis, new_data = _, ref_data = ref) # Predict for first level of random effect levels rather than 'typical' xnew_data(data, temperature) |> predict(analysis, new_data = _, random_effects = FALSE) # Extract a scalar derived quantity from new_expr predict(analysis, new_data = character(0), term = "eBaseCount") ## End(Not run)
Gets the R2 value for an object.
R2(object, ...)R2(object, ...)
object |
The object. |
... |
Unused. |
An index of the R2 value.
Gets the conditional (or marginal) R2 value for the 'response' for an mb_analysis object.
## S3 method for class 'mb_analysis' R2( object, response, marginal = FALSE, term = "prediction", parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), ... )## S3 method for class 'mb_analysis' R2( object, response, marginal = FALSE, term = "prediction", parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), ... )
object |
The object. |
response |
A string specifying the column in the data corresponding to the response. |
marginal |
A flag indicating whether to calculate the marginal or conditional R2 value. |
term |
A string of the term in new_expr. |
parallel |
A flag indicating whether to do predictions using parallel backend provided by foreach. |
quiet |
A flag indicating whether to disable tracing information. |
... |
Unused |
The conditional R2 value is the proportion of the variance in the response predicted by the full model. The marginal R2 values is just for the fixed effects ie after marginalizing out the random effects.
A number of the R2 value.
Gets the random effects definitions for an object inheriting from class mb_model or mb_analysis.
random_effects(object, ...)random_effects(object, ...)
object |
The object. |
... |
Unused. |
The random effects as a sorted named list.
Reanalyse an analysis.
reanalyse(object, ...)reanalyse(object, ...)
object |
The object to reanalyse. |
... |
Additional arguments. |
Reanalyse
## S3 method for class 'mb_analyses' reanalyse( object, rhat = getOption("mb.rhat", 1.1), esr = getOption("mb.esr", 0.33), nreanalyses = getOption("mb.nreanalyses", 1L), duration = getOption("mb.duration", dhours(1)), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), ... )## S3 method for class 'mb_analyses' reanalyse( object, rhat = getOption("mb.rhat", 1.1), esr = getOption("mb.esr", 0.33), nreanalyses = getOption("mb.nreanalyses", 1L), duration = getOption("mb.duration", dhours(1)), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), ... )
object |
The object to reanalyse. |
rhat |
A number specifying the rhat threshold. |
esr |
A number specifying the effective sampling rate. |
nreanalyses |
A count between 1 and 7 specifying the maximum number of reanalyses. |
duration |
The maximum total time to spend on analysis/reanalysis. |
parallel |
A flag indicating whether to perform the analysis in parallel if possible |
quiet |
A flag indicating whether to disable tracing information. |
glance |
A flag indicating whether to print summary of model. |
beep |
A flag indicating whether to beep on completion of the analysis. |
... |
Unused arguments. |
Reanalyse
## S3 method for class 'mb_analysis' reanalyse( object, rhat = getOption("mb.rhat", 1.1), esr = getOption("mb.esr", 0.33), nreanalyses = getOption("mb.nreanalyses", 1L), duration = getOption("mb.duration", dhours(1)), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), ... )## S3 method for class 'mb_analysis' reanalyse( object, rhat = getOption("mb.rhat", 1.1), esr = getOption("mb.esr", 0.33), nreanalyses = getOption("mb.nreanalyses", 1L), duration = getOption("mb.duration", dhours(1)), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), ... )
object |
The object to reanalyse. |
rhat |
A number specifying the rhat threshold. |
esr |
A number specifying the minimum effective sampling rate. |
nreanalyses |
A count between 0 and 4 specifying the maximum number of reanalyses. |
duration |
The maximum total time to spend on analysis and reanalysis. |
parallel |
A flag indicating whether to perform the analysis in parallel if possible. |
quiet |
A flag indicating whether to disable tracing information. |
glance |
A flag indicating whether to print summary of model. |
beep |
A flag indicating whether to beep on completion of the analysis. |
... |
Unused arguments. |
Reanalyse
## S3 method for class 'mb_meta_analyses' reanalyse( object, rhat = getOption("mb.rhat", 1.1), esr = getOption("mb.esr", 0.33), nreanalyses = getOption("mb.nreanalyses", 1L), duration = getOption("mb.duration", dhours(1)), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), ... )## S3 method for class 'mb_meta_analyses' reanalyse( object, rhat = getOption("mb.rhat", 1.1), esr = getOption("mb.esr", 0.33), nreanalyses = getOption("mb.nreanalyses", 1L), duration = getOption("mb.duration", dhours(1)), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), ... )
object |
The object to reanalyse. |
rhat |
A number specifying the rhat threshold. |
esr |
A number specifying the effective sampling rate. |
nreanalyses |
A count between 1 and 7 specifying the maximum number of reanalyses. |
duration |
The maximum total time to spend on analysis/reanalysis. |
parallel |
A flag indicating whether to perform the analysis in parallel if possible |
quiet |
A flag indicating whether to disable tracing information. |
glance |
A flag indicating whether to print summary of model. |
beep |
A flag indicating whether to beep on completion of the analysis. |
... |
Unused arguments. |
Reanalyse
## S3 method for class 'mb_meta_analysis' reanalyse( object, rhat = getOption("mb.rhat", 1.1), esr = getOption("mb.esr", 0.33), nreanalyses = getOption("mb.nreanalyses", 1L), duration = getOption("mb.duration", dhours(1)), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), ... )## S3 method for class 'mb_meta_analysis' reanalyse( object, rhat = getOption("mb.rhat", 1.1), esr = getOption("mb.esr", 0.33), nreanalyses = getOption("mb.nreanalyses", 1L), duration = getOption("mb.duration", dhours(1)), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), ... )
object |
The object to reanalyse. |
rhat |
A number specifying the rhat threshold. |
esr |
A number specifying the effective sampling rate. |
nreanalyses |
A count between 1 and 7 specifying the maximum number of reanalyses. |
duration |
The maximum total time to spend on analysis/reanalysis. |
parallel |
A flag indicating whether to perform the analysis in parallel if possible |
quiet |
A flag indicating whether to disable tracing information. |
glance |
A flag indicating whether to print summary of model. |
beep |
A flag indicating whether to beep on completion of the analysis. |
... |
Unused arguments. |
Reanalyse an analysis. For user to override.
reanalyse1(object, parallel, quiet, ...)reanalyse1(object, parallel, quiet, ...)
object |
The object to reanalyse. |
parallel |
A flag indicating whether to perform the reanalysis in parallel. |
quiet |
A flag indicating whether to capture output. |
... |
Additional arguments. |
Extract residual values for an MB analysis.
## S3 method for class 'mb_analysis' residuals(object, type = NULL, ...)## S3 method for class 'mb_analysis' residuals(object, type = NULL, ...)
object |
The MB analysis object. |
type |
A string of the residual type. |
... |
Unused. |
The new_expr in the model must include the term 'residual'.
The analysis data set with the residual values.
Removes comments from the template strings(s) of an mb object or a character vector.
rm_comments(object, ...)rm_comments(object, ...)
object |
The mb object or character vector. |
... |
Unused. |
The mb object or character vector without comments in its template string(s).
Get sample size.
sample_size(object, ...)sample_size(object, ...)
object |
The object to calculate the sample size for. |
... |
Not used. |
A count of the sample size.
Filters a named list so only scalar elements remain.wiby its names.
scalar_nlist(x)scalar_nlist(x)
x |
The named list to sort. |
The sorted named list.
scalar_nlist(list(y = 2, x = 1, a = c(10, 1)))scalar_nlist(list(y = 2, x = 1, a = c(10, 1)))
Multiply Standard Deviation of Priors By
sd_priors_by(x, by = 10, distributions = c("normal", "lognormal", "t"), ...) ## S3 method for class 'mb_model' sd_priors_by(x, by = 10, distributions = c("normal", "lognormal", "t"), ...) ## S3 method for class 'mb_analysis' sd_priors_by( x, by = 10, distributions = c("normal", "lognormal", "t"), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), ... )sd_priors_by(x, by = 10, distributions = c("normal", "lognormal", "t"), ...) ## S3 method for class 'mb_model' sd_priors_by(x, by = 10, distributions = c("normal", "lognormal", "t"), ...) ## S3 method for class 'mb_analysis' sd_priors_by( x, by = 10, distributions = c("normal", "lognormal", "t"), parallel = getOption("mb.parallel", FALSE), quiet = getOption("mb.quiet", TRUE), glance = getOption("mb.glance", TRUE), beep = getOption("mb.beep", TRUE), ... )
x |
The object. |
by |
A double scalar of the multiplier. |
distributions |
A character vector of the distributions to adjust. Possible values are "laplace" (double exponential), "logistic", "lognormal", "normal", "t" and "nt" (non-central Student t). |
... |
Not used. |
parallel |
A flag indicating whether to perform the analysis in parallel if possible. |
quiet |
A flag indicating whether to disable messages and warnings, including sampling progress. |
glance |
A flag indicating whether to print a model summary. |
beep |
A flag indicating whether to beep on completion of the analysis. |
The updated object.
sd_priors_by(mb_model): Multiply Standard Deviation of Priors for an MB model
sd_priors_by(mb_analysis): Multiply Standard Deviation of Priors for an MB analysis
Selects and rescales data.
select_rescale_data(data, model, data2 = data)select_rescale_data(data, model, data2 = data)
data |
The data to modify. |
model |
An object inheriting from class mb_model. |
data2 |
The base data. |
The modified data in list form.
Summarize model sensitivity
sensitivity( x, by = "term", param_type = "all", mb.prior_cjs = getOption("mb.prior_cjs", 0.1), mb.lik_cjs = getOption("mb.lik_cjs", 0.05), ... )sensitivity( x, by = "term", param_type = "all", mb.prior_cjs = getOption("mb.prior_cjs", 0.1), mb.lik_cjs = getOption("mb.lik_cjs", 0.05), ... )
x |
The mb_analysis object. |
by |
A string indicating whether to determine by "term", "parameter", or "all". |
param_type |
A string specifying which parameters to include: 'fixed', 'random', 'derived', 'primary', or 'all'. |
mb.prior_cjs |
A number specifying the CJS threshold for weak prior classification. |
mb.lik_cjs |
A number specifying the CJS threshold for strong data classification. |
... |
Arguments passed to |
A tibble summarizing the sensitivity of the analysis object.
Sets analysis mode.
set_analysis_mode(mode = "report")set_analysis_mode(mode = "report")
mode |
A string of the analysis mode. |
The possible modes are as follows:
To rapidly identify problems with a model definition.
To quickly test code runs.
To produce results for a report.
To produce results for a peer-reviewed paper.
To run when checking a package.
To reset all the options to NULL so that they are the default values for each function call.
In each case the mode is a unique combination of the following package options
A count of the number of chains.
A count of the number of simulations to save per chain.
A count of the thining interval.
A flag indicating whether to perform the analysis in parallel.
A flag indicating whether to disable tracing information.
A flag indicating whether to beep on completion of the analysis.
A flag indicating whether to print a model summary.
A count specifying the maximum number of reanalyses.
A number specifying the rhat threshold.
A number specifying the minimum effective sampling rate.
The maximum total time to spend on analysis and reanalysis.
A number specifying the confidence level.
The old options.
## Not run: set_analysis_mode("reset") ## End(Not run)## Not run: set_analysis_mode("reset") ## End(Not run)
Requires that new_expr includes residual <- res_bern(
or residual[i] <- res_norm(.
simulate_residuals(x, type = NULL)simulate_residuals(x, type = NULL)
x |
The MB analysis object. |
type |
A string of the residual type. |
An mcmc_data of the simulated residuals.
extras::res_binom
Sort Analyses by IC
sort_by_ic(x, ...)sort_by_ic(x, ...)
x |
the object. |
... |
Unused |
The sorted object
Sorts a named list by its names.
sort_nlist(x)sort_nlist(x)
x |
The named list to sort. |
The sorted named list.
sort_nlist(list(y = 2, x = 1, a = 10))sort_nlist(list(y = 2, x = 1, a = 10))
Gets the template string for an object.
template(object, ...)template(object, ...)
object |
The object. |
... |
Additional arguments. |
The template model code as a string.
Sets the template for an object.
template(object) <- valuetemplate(object) <- value
object |
The object. |
value |
A string of the new template |
terms
## S3 method for class 'mb_analysis' terms(x, param_type = "fixed", include_constant = TRUE, ...)## S3 method for class 'mb_analysis' terms(x, param_type = "fixed", include_constant = TRUE, ...)
x |
The mb_analysis object. |
param_type |
A string indicating the type of terms to get the names for. |
include_constant |
A flag specifying whether to include constant terms. |
... |
Not used. |
Updates an object inherting from class mb_model.
update_model( model, code = NULL, gen_inits = NULL, random_effects = NULL, fixed = NULL, derived = NULL, select_data = NULL, center = NULL, scale = NULL, modify_data = NULL, nthin = NULL, new_expr = NULL, new_expr_vec = NULL, modify_new_data = NULL, drops = NULL, ... )update_model( model, code = NULL, gen_inits = NULL, random_effects = NULL, fixed = NULL, derived = NULL, select_data = NULL, center = NULL, scale = NULL, modify_data = NULL, nthin = NULL, new_expr = NULL, new_expr_vec = NULL, modify_new_data = NULL, drops = NULL, ... )
model |
The model to update. |
code |
A string of the model template or an object inheriting from class mb_code. |
gen_inits |
A single-argument function returning a named list of
initial values per chain. Receives the modified data list (i.e. after
|
random_effects |
Named list mapping parameter names in the model
code to one or more grouping factor columns from |
fixed |
A string of a regular expression of parameter names to monitor as fixed effects. |
derived |
A character vector of derived parameters to monitor. |
select_data |
A named list specifying the columns to select and their expected classes and values as well as transformations and scaling options. See the select_data section of |
center |
A character vector of the columns to center. |
scale |
A character vector of the columns to scale (after centering). |
modify_data |
A single argument function to modify the data (in list form) immediately prior to the analysis. |
nthin |
An integer specifying the thinning interval. |
new_expr |
An R expression or character string of R code defining
the predictive relationships and derived quantities. See the new_expr
section of |
new_expr_vec |
Flag controlling whether to vectorise the |
modify_new_data |
SA single argument function to modify new data (in list form) immediately prior to calculating new_expr. |
drops |
A list of character vectors naming scalar parameters to fix at 0 in the model. |
... |
These dots are for future extensions and must be empty. |
An object inheriting from class mb_model.