| Title: | Quick Bayesian Regression Models Using 'INLA' with 'brms' Syntax |
|---|---|
| Description: | Provides a 'brms'-like interface for fitting Bayesian regression models using 'INLA' (Integrated Nested Laplace Approximations) and 'TMB' (Template Model Builder). The package offers faster model fitting while maintaining familiar 'brms' syntax and output formats. Supports fixed and mixed effects models, multiple probability distributions, conditional effects plots, and posterior predictive checks with summary methods compatible with 'brms'. 'TMB' integration provides fast ordinal regression capabilities. Implements methods adapted from 'emmeans' for marginal means estimation and 'bayestestR' for Bayesian inference assessment. Methods are based on Rue et al. (2009) <doi:10.1111/j.1467-9868.2008.00700.x>, Kristensen et al. (2016) <doi:10.18637/jss.v070.i05>, Lenth (2016) <doi:10.18637/jss.v069.i01>, Bürkner (2017) <doi:10.18637/jss.v080.i01>, Makowski et al. (2019) <doi:10.21105/joss.01541>, and Kruschke (2014, ISBN:9780124058880). |
| Authors: | Tony Myers [aut, cre] (ORCID: <https://orcid.org/0000-0003-4516-4829>) |
| Maintainer: | Tony Myers <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.1 |
| Built: | 2026-05-14 09:10:19 UTC |
| Source: | https://github.com/tony-myers/qbrms |
The qbrms package provides a brms-like interface for fitting Bayesian regression models using INLA (Integrated Nested Laplace Approximations). It offers faster model fitting while maintaining familiar brms syntax and output formats.
The main function is qbrms which fits Bayesian models using
INLA with brms-like syntax. The package supports:
Fixed and mixed effects models
Multiple probability distributions
Conditional effects plots
Posterior predictive checks
Summary methods compatible with brms
Interactive model building with model_builder
RStudio add-in for point-and-click model specification
Tony Myers
Useful links:
Asymmetric Laplace for Quantile Regression
asymmetric_laplace()asymmetric_laplace()
An object of class "family" representing the Asymmetric Laplace distribution.
Compute Bayesian R-squared values for qbrms regression models following the method of Gelman et al. (2019). This corrected version properly handles mixed-effects models to match brms output exactly.
bayes_R2( object, summary = TRUE, robust = FALSE, probs = c(0.025, 0.975), ndraws = 1000, newdata = NULL, verbose = TRUE )bayes_R2( object, summary = TRUE, robust = FALSE, probs = c(0.025, 0.975), ndraws = 1000, newdata = NULL, verbose = TRUE )
object |
A |
summary |
Logical; if |
robust |
Logical; if |
probs |
Numeric vector of quantiles for summary (default: c(0.025, 0.975)). |
ndraws |
Number of posterior draws to use (default: 1000). |
newdata |
Optional data frame for predictions. If |
verbose |
Logical; print progress information. |
This implementation handles mixed-effects models by:
Using INLA's fitted values that include random effects when available
Correctly sampling random effects from their posterior distributions
Properly accounting for the variance decomposition in mixed models
If summary = TRUE, a matrix with summary statistics.
If summary = FALSE, a vector of R-squared values from posterior draws.
Compute a crude Bayes factor for a point, interval, or comparison hypothesis
using approximate posterior draws recovered from a qbrms_fit.
This is deliberately simple and intended for exploratory use.
bayesfactor( object, hypothesis, prior = NULL, null = 0, direction = "two-sided", rope = NULL, nsim = 4000, verbose = TRUE )bayesfactor( object, hypothesis, prior = NULL, null = 0, direction = "two-sided", rope = NULL, nsim = 4000, verbose = TRUE )
object |
A |
hypothesis |
Character string, for example "Intercept > 0", "b_x = 0", or "b_x > 0.2". |
prior |
Optional prior information (unused here, kept for API compatibility). |
null |
Numeric null value for point tests (default 0). |
direction |
One of "two-sided", "greater", "less" (kept for API compatibility). |
rope |
Optional numeric length-2 vector |
nsim |
Number of posterior draws to simulate from the fitted summary. |
verbose |
Logical; print progress information. |
An object of class qbrms_bayesfactor.
Beta distribution family for response variables in (0,1)
Beta(link = "logit", link.phi = "log") Beta(link = "logit", link.phi = "log")Beta(link = "logit", link.phi = "log") Beta(link = "logit", link.phi = "log")
link |
Link function for the mean parameter (default: "logit") |
link.phi |
Link function for precision parameter (default: "log") |
A family object of class "family".
A family object for use with qbrms()
## Not run: # Beta regression for proportions fit <- qbrms(proportion ~ predictor, data = data, family = Beta()) ## End(Not run)## Not run: # Beta regression for proportions fit <- qbrms(proportion ~ predictor, data = data, family = Beta()) ## End(Not run)
Beta Binomial Family for Overdispersed Binary Data
beta_binomial(link = "logit")beta_binomial(link = "logit")
link |
Link function for probability parameter (default: "logit") |
A family object of class "family".
Specify Beta Prior Distribution
beta_prior(alpha = 1, beta = 1)beta_prior(alpha = 1, beta = 1)
alpha |
First shape parameter |
beta |
Second shape parameter |
A prior distribution object
Alternative Beta Parameterizations
beta0(link = "logit") beta1(link = "logit") logitbeta(link = "logit")beta0(link = "logit") beta1(link = "logit") logitbeta(link = "logit")
link |
Link function (default: "logit") |
A family object of class "family".
Function to set up a model formula for use in qbrms, allowing
specification of distributional parameters (e.g., sigma) in addition to the
mean structure.
bf(formula, ..., flist = NULL, family = NULL, nl = FALSE)bf(formula, ..., flist = NULL, family = NULL, nl = FALSE)
formula |
Main model formula (for the mean/location parameter). |
... |
Additional formulas for distributional parameters (e.g., |
flist |
Optional list of formulas (for internal use). |
family |
Same as in |
nl |
Logical; indicating if the model is non-linear (not yet fully supported). |
This function mimics the brms::bf() syntax to allow users familiar
with brms to define distributional models.
Supported distributional parameters depend on the family:
gaussian: sigma (residual standard deviation)
student_t: sigma, nu (degrees of freedom)
lognormal: sigma (shape parameter)
beta: phi (precision)
simplex: phi (precision)
An object of class brmsformula (and qbrmsformula)
containing the parsed formulas.
## Not run: # Standard model f1 <- bf(y ~ x) # Distributional model (heteroscedasticity) # Sigma varies by group f2 <- bf(y ~ x, sigma ~ group) ## End(Not run)## Not run: # Standard model f1 <- bf(y ~ x) # Distributional model (heteroscedasticity) # Sigma varies by group f2 <- bf(y ~ x, sigma ~ group) ## End(Not run)
Binomial Family
binomial()binomial()
An object of class "family" representing the Binomial distribution.
Combine Multiple Prior Specifications
## S3 method for class 'qbrms_prior_spec' c(...)## S3 method for class 'qbrms_prior_spec' c(...)
... |
Prior specification objects created by prior() |
A combined prior object
Specify Cauchy Prior Distribution
cauchy(location = 0, scale = 1)cauchy(location = 0, scale = 1)
location |
Location parameter (default 0) |
scale |
Scale parameter (default 1) |
A prior distribution object
Quick model diagnostics
check_convergence(object)check_convergence(object)
object |
A qbrms_fit object. |
Invisible TRUE if successful.
Circular Normal Family for Directional Data
circular_normal(link = "tan_half", link.kappa = "log") von_mises(link = "tan_half", link.kappa = "log")circular_normal(link = "tan_half", link.kappa = "log") von_mises(link = "tan_half", link.kappa = "log")
link |
Link function for mean direction |
link.kappa |
Link function for concentration |
A family object of class "family".
Extract Coefficients from qbrms Models
## S3 method for class 'qbrms_fit' coef(object, ...)## S3 method for class 'qbrms_fit' coef(object, ...)
object |
A qbrms_fit object |
... |
Additional arguments (unused) |
Named vector of coefficients
Extract a concatenated vector of coefficients from a
qbrms_multinomial_fit, combining the per-category binary submodels
if present.
## S3 method for class 'qbrms_multinomial_fit' coef(object, ...)## S3 method for class 'qbrms_multinomial_fit' coef(object, ...)
object |
A |
... |
Unused. |
A named numeric vector of coefficients. If coefficient information is not available, a minimal intercept-only vector is returned.
Coefficients Method for TMB Ordinal Fits
## S3 method for class 'tmb_ordinal_qbrms_fit' coef(object, ...)## S3 method for class 'tmb_ordinal_qbrms_fit' coef(object, ...)
object |
A tmb_ordinal_qbrms_fit object |
... |
Additional arguments |
Named vector of coefficients
Compares multiple fitted models using information criteria and simple predictive metrics. Preference order for criterion = "auto" is: LOO (from CPO) > WAIC > DIC. When information criteria are unavailable it falls back to predictive metrics (RMSE/MAE).
compare_models( ..., criterion = c("auto", "loo", "waic", "dic", "all"), compare_predictions = TRUE, weights = TRUE )compare_models( ..., criterion = c("auto", "loo", "waic", "dic", "all"), compare_predictions = TRUE, weights = TRUE )
... |
Two or more fitted model objects (qbrms_fit or qbrmO_fit) |
criterion |
One of "auto","loo","waic","dic","all" |
compare_predictions |
Logical; if TRUE, include RMSE/MAE comparison |
weights |
Logical; if TRUE, compute weights when a single criterion is used |
An object of class "qbrms_comparison".
Compare the probability of practical significance for parameters across multiple qbrms models.
compare_significance( ..., parameters = NULL, threshold = "default", model_names = NULL )compare_significance( ..., parameters = NULL, threshold = "default", model_names = NULL )
... |
qbrms_fit objects to compare |
parameters |
Character vector of parameters to compare |
threshold |
Threshold specification (same as p_significance) |
model_names |
Character vector of model names |
Data frame with comparison results
Compute one-dimensional conditional effects / marginal fitted values as a
predictor varies while other covariates are held fixed (typically at means /
modes). Methods should return an object that plot() can visualise.
conditional_effects(object, ...)conditional_effects(object, ...)
object |
A model object. |
... |
Passed to methods. |
An object of class "qbrms_conditional_effects" containing
conditional effect estimates. The structure is method-dependent.
Build point/interval summaries at a few values of a numeric moderator, plotted against the factor on the x-axis.
conditional_effects_slices( object, effects, slices = NULL, nslices = 3L, prob = 0.95, ndraws = 200L, at = list(), seed = NULL, ... )conditional_effects_slices( object, effects, slices = NULL, nslices = 3L, prob = 0.95, ndraws = 200L, at = list(), seed = NULL, ... )
object |
A qbrms_fit object. |
effects |
Character vector specifying effects to plot. If NULL, all numeric predictors are used. |
slices |
Named list of variables and values at which to slice the data. |
nslices |
Number of slices to use for each slicing variable. |
prob |
Probability mass to include in uncertainty intervals (default 0.95). |
ndraws |
Number of posterior draws to use for predictions. |
at |
Named list of values at which to fix other predictors. |
seed |
Random seed for reproducibility. |
... |
Additional arguments passed to prediction functions. |
An object of class "qbrms_conditional_effects" containing
a list with one element per effect. Each element is a data frame with
columns for the predictor values, estimates, and credible intervals.
Conditional effects for qbrms Gaussian models
## S3 method for class 'qbrms_fit' conditional_effects( object, effects = NULL, spaghetti = FALSE, ndraws = 200L, n_points = 100L, at = list(), seed = NULL, prob = 0.95, ... )## S3 method for class 'qbrms_fit' conditional_effects( object, effects = NULL, spaghetti = FALSE, ndraws = 200L, n_points = 100L, at = list(), seed = NULL, prob = 0.95, ... )
object |
A qbrms fit object (Gaussian). |
effects |
Character vector: names of predictors to vary. Supports simple two-way interactions "num:fac" or "fac:num" where one is numeric and the other factor. |
spaghetti |
Logical; if TRUE draw per-draw "spaghetti" lines. If FALSE, draw a mean line with a credible-interval ribbon. |
ndraws |
Number of joint coefficient draws for uncertainty (default 200). |
n_points |
Size of the x-grid across the observed range (default 100). |
at |
Optional named list of covariate values to hold constant. |
seed |
Optional integer seed for reproducibility. |
prob |
Interval probability for ribbons (default 0.95). |
... |
Ignored. |
An object of class "qbrms_conditional_effects" containing
a list with one element per effect. Each element is a data frame with
columns for the predictor values, point estimates (estimate__),
and credible interval bounds (lower__, upper__).
Conditional Effects for TMB Ordinal Models
## S3 method for class 'tmb_ordinal_qbrms_fit' conditional_effects( object, effects = NULL, prob = 0.95, ndraws = 100, spaghetti = FALSE, n_points = 100, plot = TRUE, at = list(), seed = NULL, conditions = NULL, categorical = TRUE, resolution = NULL, ... )## S3 method for class 'tmb_ordinal_qbrms_fit' conditional_effects( object, effects = NULL, prob = 0.95, ndraws = 100, spaghetti = FALSE, n_points = 100, plot = TRUE, at = list(), seed = NULL, conditions = NULL, categorical = TRUE, resolution = NULL, ... )
object |
A tmb_ordinal_qbrms_fit object |
effects |
Character vector of effect names (defaults to auto-detected) |
prob |
Confidence level |
ndraws |
Number of draws |
spaghetti |
Logical |
n_points |
Number of points for continuous predictors |
plot |
Logical, whether to return plots |
at |
Named list of conditioning values |
seed |
Random seed |
conditions |
Ordinal-specific conditions (for backwards compatibility) |
categorical |
Whether to show categorical plot (for backwards compatibility) |
resolution |
Grid resolution (for backwards compatibility) |
... |
Additional arguments |
List of conditional effects
Enhanced family conversion supporting all standard and additional families with automatic routing to specialised implementations when enabled.
convert_family_to_inla(family, quantile = 0.5, allow_ordinal_routing = FALSE)convert_family_to_inla(family, quantile = 0.5, allow_ordinal_routing = FALSE)
family |
A family object, character string, or list specifying the response distribution |
quantile |
Numeric value between 0 and 1 for quantile regression |
allow_ordinal_routing |
Logical; if TRUE, enables routing for ordinal families |
Character string, list, or routing object specifying family/routing info
Create dummy data that preserves structure for testing purposes.
create_dummy_data( formula, data, n_dummy = 10, family_name = "gaussian", verbose = FALSE )create_dummy_data( formula, data, n_dummy = 10, family_name = "gaussian", verbose = FALSE )
formula |
Model formula. |
data |
Original data frame. |
n_dummy |
Number of dummy observations to create. |
family_name |
The name of the model family (e.g., "gaussian"). |
verbose |
Logical, whether to print messages. |
Data frame with dummy structure.
Construct a small qbrms_prior_only object that contains simulated data
and prior draws, suitable for passing to pp_check().
create_prior_object( formula, family = gaussian(), prior = NULL, n_obs = 100, predictor_values = NULL, verbose = TRUE )create_prior_object( formula, family = gaussian(), prior = NULL, n_obs = 100, predictor_values = NULL, verbose = TRUE )
formula |
Model formula. |
family |
Model family (default |
prior |
Prior specifications (default |
n_obs |
Number of observations to simulate (default |
predictor_values |
Named list of fixed predictor values (default |
verbose |
Logical; print progress messages (default |
An object of class qbrms_prior_only.
Cumulative Family for Ordinal Regression
cumulative(link = "logit")cumulative(link = "logit")
link |
Link function (default: "logit"). |
An object of class "family" representing the Cumulative distribution for ordinal models.
Default Priors for qbrms Models
default_priors()default_priors()
A default prior list
Create density plots of posterior distributions with optional prior and
observed-data overlays. Returns a ggplot2 object that can be modified
with standard ggplot2 syntax.
density_plot( object, parameter = NULL, show_prior = FALSE, show_data = FALSE, ndraws = 100, prior_ndraws = 100, alpha_levels = list(posterior = 0.8, prior = 0.6, data = 1), colours = list(posterior = "#1F78B4", prior = "#E31A1C", data = "#000000"), seed = NULL, verbose = TRUE )density_plot( object, parameter = NULL, show_prior = FALSE, show_data = FALSE, ndraws = 100, prior_ndraws = 100, alpha_levels = list(posterior = 0.8, prior = 0.6, data = 1), colours = list(posterior = "#1F78B4", prior = "#E31A1C", data = "#000000"), seed = NULL, verbose = TRUE )
object |
A |
parameter |
Parameter name to plot. If |
show_prior |
Logical; if |
show_data |
Logical; if |
ndraws |
Number of posterior draws to use (default |
prior_ndraws |
Number of prior draws to use (default |
alpha_levels |
Named list controlling transparency for layers. |
colours |
Named list of colours for layers. |
seed |
Optional random seed. |
verbose |
Logical; print progress messages. |
A ggplot2 object.
Diagnose potential issues in binomial mixed effects models before fitting
diagnose_binomial_mixed(formula, data, verbose = TRUE)diagnose_binomial_mixed(formula, data, verbose = TRUE)
formula |
Model formula with mixed effects |
data |
Data frame containing variables |
verbose |
Logical; print diagnostic information (default: TRUE) |
List with diagnostic information
Comprehensive automated diagnostics for qbrms models with actionable recommendations for model improvement.
diagnose_model(model, checks = "all", verbose = TRUE)diagnose_model(model, checks = "all", verbose = TRUE)
model |
A fitted qbrms model object |
checks |
Character vector specifying which checks to perform. Options: "all" (default), "convergence", "fit", "residuals", "posterior", "influential" |
verbose |
Logical; if TRUE, prints detailed diagnostic information (default: TRUE) |
This function performs comprehensive model diagnostics including:
Convergence checks (for MCMC-based inference)
Goodness-of-fit assessment
Residual analysis
Posterior predictive checks
Influential observation detection
Prior-posterior overlap assessment
Each check produces a pass/warning/fail status with specific recommendations for addressing any issues detected.
An object of class "qbrms_diagnostics" containing:
summary: Overall assessment (pass/warning/fail)
checks: Detailed results for each diagnostic check
recommendations: Specific suggestions for improvement
plots: List of diagnostic plots
## Not run: # Fit a model fit <- qbrms(mpg ~ hp + wt, data = mtcars, family = gaussian()) # Run diagnostics diag <- diagnose_model(fit) # View summary print(diag) # View specific recommendations diag$recommendations # Create diagnostic plots plot(diag) ## End(Not run)## Not run: # Fit a model fit <- qbrms(mpg ~ hp + wt, data = mtcars, family = gaussian()) # Run diagnostics diag <- diagnose_model(fit) # View summary print(diag) # View specific recommendations diag$recommendations # Create diagnostic plots plot(diag) ## End(Not run)
Remove random effects terms from a model formula.
drop_random_effects(formula)drop_random_effects(formula)
formula |
A model formula that may contain random effects. |
Formula with random effects terms removed.
This wrapper lets you call emmeans() on a qbrms_fit without attaching
the external emmeans package. For non-qbrms_fit objects, it
forwards to emmeans if that package is installed.
emmeans(object, specs, ...)emmeans(object, specs, ...)
object |
A model object; if it is a |
specs |
Term(s) for which to compute estimated marginal means. For
|
... |
Additional arguments forwarded either to |
A data frame for qbrms_fit; otherwise whatever
emmeans::emmeans() returns.
Exponential Distribution (Prior or Family)
exponential(rate_or_link = "log", link = NULL, ...) prior_exponential(rate_or_link = 1)exponential(rate_or_link = "log", link = NULL, ...) prior_exponential(rate_or_link = 1)
rate_or_link |
Rate parameter (numeric) or link function (character). |
link |
Optional link function (if acting as family). |
... |
Additional arguments. |
A family object or prior object depending on inputs.
Export model specifications to various formats for sharing, documentation, or reproduction.
export_model( model, file, format = c("R", "markdown", "text", "json"), include_data = TRUE, include_diagnostics = FALSE )export_model( model, file, format = c("R", "markdown", "text", "json"), include_data = TRUE, include_diagnostics = FALSE )
model |
A fitted qbrms model object or qbrms_model_spec object |
file |
Character string specifying output file path |
format |
Character string specifying export format: "R" (R script), "markdown" (Rmd document), "text" (plain text), or "json" (JSON format) |
include_data |
Logical; if TRUE, includes data summary in export (default: TRUE) |
include_diagnostics |
Logical; if TRUE and model is fitted, includes diagnostic information (default: FALSE) |
This function facilitates model sharing and documentation by exporting:
Model formula and family specification
Prior specifications (if any)
Data summary and structure
Model fitting code
Results summary (for fitted models)
Diagnostic information (if requested)
The exported content can be used to:
Share analyses with collaborators
Document modelling decisions
Create reproducible research reports
Archive model specifications
Invisibly returns the export content as a character string
## Not run: # Export model specification spec <- model_builder(data = mtcars, response = "mpg") export_model(spec, "my_model_spec.R", format = "R") # Export fitted model fit <- qbrms(mpg ~ hp + wt, data = mtcars, family = gaussian()) export_model(fit, "my_model.Rmd", format = "markdown", include_diagnostics = TRUE) # Export as JSON export_model(spec, "my_model.json", format = "json") ## End(Not run)## Not run: # Export model specification spec <- model_builder(data = mtcars, response = "mpg") export_model(spec, "my_model_spec.R", format = "R") # Export fitted model fit <- qbrms(mpg ~ hp + wt, data = mtcars, family = gaussian()) export_model(fit, "my_model.Rmd", format = "markdown", include_diagnostics = TRUE) # Export as JSON export_model(spec, "my_model.json", format = "json") ## End(Not run)
Get Family Documentation
family_info(family_name)family_info(family_name)
family_name |
Name of the family |
Character string with family information
Determine whether a given family supports quantile regression.
family_supports_quantile(family_obj)family_supports_quantile(family_obj)
family_obj |
Family object or name. |
Logical indicating whether the family supports quantile regression.
Extract fitted values from qbrms models
## S3 method for class 'qbrms_fit' fitted(object, ...)## S3 method for class 'qbrms_fit' fitted(object, ...)
object |
A qbrms_fit object |
... |
Additional arguments (currently unused) |
Numeric vector of fitted values
## Not run: fit <- qbrms(mpg ~ hp, data = mtcars, family = gaussian()) fitted_values <- fitted(fit) ## End(Not run)## Not run: fit <- qbrms(mpg ~ hp, data = mtcars, family = gaussian()) fitted_values <- fitted(fit) ## End(Not run)
Fitted Values Method for TMB Ordinal Fits
## S3 method for class 'tmb_ordinal_qbrms_fit' fitted(object, ...)## S3 method for class 'tmb_ordinal_qbrms_fit' fitted(object, ...)
object |
A tmb_ordinal_qbrms_fit object |
... |
Additional arguments |
Fitted values
Gamma Distribution (Prior or Family)
gamma(shape_or_link = "log", rate = 1, link = NULL, ...) gamma_prior(shape_or_link = 2, rate = 1)gamma(shape_or_link = "log", rate = 1, link = NULL, ...) gamma_prior(shape_or_link = 2, rate = 1)
shape_or_link |
Shape parameter (numeric) or link function (character). |
rate |
Rate parameter. |
link |
Optional link function (if acting as family). |
... |
Additional arguments. |
A family object or prior object depending on inputs.
Gamma family constructor to avoid conflict with base::gamma.
Gamma(link = "log")Gamma(link = "log")
link |
Link function (default: "log") |
A family object of class "family".
Gaussian Family
gaussian()gaussian()
An object of class "family" representing the Gaussian distribution.
Generalized t Family
gen_student_t(link = "identity", link.sigma = "log", link.nu = "log")gen_student_t(link = "identity", link.sigma = "log", link.nu = "log")
link |
Link function for location |
link.sigma |
Link function for scale |
link.nu |
Link function for degrees of freedom |
A family object of class "family".
Get Default Prior for Parameter Class
get_default_prior(class)get_default_prior(class)
class |
Parameter class |
A default prior for that class
Generalized Extreme Value Family
gev(link = "identity", link.sigma = "log", link.xi = "identity") gumbel(link = "identity", link.sigma = "log")gev(link = "identity", link.sigma = "log", link.xi = "identity") gumbel(link = "identity", link.sigma = "log")
link |
Link function for location |
link.sigma |
Link function for scale |
link.xi |
Link function for shape |
A family object of class "family".
Compute highest density intervals for parameters based on simulated
posterior draws from a qbrms_fit.
hdi(object, parameters = NULL, prob = 0.95, nsim = 4000)hdi(object, parameters = NULL, prob = 0.95, nsim = 4000)
object |
A |
parameters |
Optional character vector; default uses all fixed effects. |
prob |
Probability mass for the interval (default 0.95). |
nsim |
Number of draws to simulate. |
A data frame of class qbrms_hdi.
Hurdle Families for Two-Part Models
hurdle_poisson(link = "log", link.hu = "logit") hurdle_negbinomial(link = "log", link.hu = "logit")hurdle_poisson(link = "log", link.hu = "logit") hurdle_negbinomial(link = "log", link.hu = "logit")
link |
Link function for count component |
link.hu |
Link function for hurdle component |
A family object of class "family".
IID Random Effects
iid(scale.model = "log", diagonal = 1e-06)iid(scale.model = "log", diagonal = 1e-06)
scale.model |
Scaling model for precision |
diagonal |
Diagonal precision matrix structure |
A family object of class "family".
Import a previously exported model specification from JSON format.
import_model(file)import_model(file)
file |
Character string specifying JSON file path |
A list containing the model specification components
## Not run: # Import model spec <- import_model("my_model.json") # Recreate model fit <- qbrms( formula = as.formula(spec$model$formula), data = my_data, family = get(spec$model$family)() ) ## End(Not run)## Not run: # Import model spec <- import_model("my_model.json") # Recreate model fit <- qbrms( formula = as.formula(spec$model$formula), data = my_data, family = get(spec$model$family)() ) ## End(Not run)
Performs K-fold cross-validation either from a fitted model or from
formula + data. For ordinal (cumulative/ordinal) families, you can
choose the re-fit engine used inside CV: TMB (qbrmO) or a robust
fallback using MASS::polr that avoids TMB compilation in each fold.
Your original fitted model is unchanged.
kfold_cv( object, data = NULL, family = gaussian(), K = 10, folds = NULL, seed = NULL, stratify = TRUE, parallel = FALSE, workers = NULL, keep_fits = FALSE, engine = c("auto", "tmb", "polr"), verbose = TRUE, ... )kfold_cv( object, data = NULL, family = gaussian(), K = 10, folds = NULL, seed = NULL, stratify = TRUE, parallel = FALSE, workers = NULL, keep_fits = FALSE, engine = c("auto", "tmb", "polr"), verbose = TRUE, ... )
object |
Either a fitted qbrms/qbrmO object or a formula. |
data |
Required only if |
family |
Optional family override (used if |
K |
Number of folds (default 10). |
folds |
Optional integer vector of length |
seed |
Optional seed for stratified folds. |
stratify |
Logical; stratify on response if factor/ordered (default TRUE). |
parallel |
Logical; use |
workers |
Optional workers when parallel and no plan is set. |
keep_fits |
Logical; keep per-fold fits (default FALSE). |
engine |
Ordinal CV engine: |
verbose |
Logical; brief progress (default TRUE). |
... |
Passed to |
An object of class qbrms_kfold with ELPD, pointwise elpd, SE, etc.
Laplace (Double Exponential) Family
laplace(link = "identity", link.sigma = "log") double_exponential(link = "identity", link.sigma = "log")laplace(link = "identity", link.sigma = "log") double_exponential(link = "identity", link.sigma = "log")
link |
Link function for location |
link.sigma |
Link function for scale |
A family object of class "family".
List Available Extended Families
list_extended_families()list_extended_families()
Data frame with family names, categories, and brief descriptions
Lognormal distribution family for positive continuous responses
lognormal(meanlog_or_link = "identity", sdlog = 1, link = NULL, ...) lognormal(meanlog_or_link = "identity", sdlog = 1, link = NULL, ...) lognormal_prior(meanlog_or_link = 0, sdlog = 1)lognormal(meanlog_or_link = "identity", sdlog = 1, link = NULL, ...) lognormal(meanlog_or_link = "identity", sdlog = 1, link = NULL, ...) lognormal_prior(meanlog_or_link = 0, sdlog = 1)
meanlog_or_link |
Mean on log scale (numeric) or link function (character). |
sdlog |
SD on log scale (numeric). |
link |
Optional link function (if acting as family). |
... |
Additional arguments. |
A family object for use with qbrms()
A family object or prior object depending on inputs.
## Not run: # Lognormal regression fit <- qbrms(response ~ predictor, data = data, family = lognormal()) ## End(Not run)## Not run: # Lognormal regression fit <- qbrms(response ~ predictor, data = data, family = lognormal()) ## End(Not run)
Compare multiple fitted models and rank them by out-of-sample fit.
If you pass qbrms/qbrmO fit objects, this uses the package's loo()
/ waic() wrappers under the hood. If you pass actual loo
objects (from the loo package), it will delegate to
loo::loo_compare() automatically.
loo_compare(..., criterion = c("loo", "waic"), sort = TRUE)loo_compare(..., criterion = c("loo", "waic"), sort = TRUE)
... |
One or more fitted models (qbrms/qbrmO), or |
criterion |
Character, "loo" (default) or "waic". |
sort |
Logical; if TRUE (default) the best model is first. |
A data.frame with model names, estimate on the ELPD scale (higher is better), standard error (if available), differences vs best, and ranks.
An interactive assistant that guides users through model specification by asking questions about their data, suggesting appropriate families, helping with prior selection, and building qbrms model code.
model_builder(data = NULL, response = NULL, predictors = NULL, quiet = FALSE)model_builder(data = NULL, response = NULL, predictors = NULL, quiet = FALSE)
data |
A data frame containing the variables to be modelled (optional). If not provided, the user will be prompted to specify it. |
response |
Character string specifying the response variable name (optional). |
predictors |
Character vector of predictor variable names (optional). |
quiet |
Logical; if TRUE, suppresses welcome messages (default: FALSE). |
An object with class "qbrms_model_spec" containing:
formula: The model formula
family: A list with name and the constructed family object
prior: Prior specifications (if provided)
data: The data frame
data_name: The symbol used for data in the emitted code
model_code: Character string with executable qbrms code
response_info: Summary information about the response
## Not run: spec <- model_builder() fit <- eval(parse(text = spec$model_code)) ## End(Not run)## Not run: spec <- model_builder() fit <- eval(parse(text = spec$model_code)) ## End(Not run)
Compare plausible families, run prior/posterior checks, plot conditional effects, compute diagnostics, and emit reproducible code. Does not load 'brms'.
model_lab_addin()model_lab_addin()
This function is called for its side effects (launching a Shiny
gadget in RStudio). It returns NULL invisibly.
A comprehensive, step-by-step assistant for Bayesian model building with qbrms.
model_workflow_addin()model_workflow_addin()
No return value. This function launches an interactive Shiny gadget for model building and code generation.
Multinomial Family
multinomial()multinomial()
An object of class "family" representing the Multinomial distribution.
Negative Binomial Family
neg_binomial()neg_binomial()
An object of class "family" representing the Negative Binomial distribution.
Negative Binomial Family (Alias)
negbinomial()negbinomial()
An object of class "family" representing the Negative Binomial distribution.
Specify Normal Prior Distribution
normal(mean = 0, sd = 1)normal(mean = 0, sd = 1)
mean |
Mean of the normal distribution (default 0) |
sd |
Standard deviation of the normal distribution (default 1) |
A prior distribution object
Estimate the probability that a parameter is strictly positive
(or strictly negative) under the posterior, based on simulated draws
from a qbrms_fit.
p_direction(object, parameters = NULL, nsim = 4000, null = 0)p_direction(object, parameters = NULL, nsim = 4000, null = 0)
object |
A |
parameters |
Optional character vector of parameter names. If |
nsim |
Number of draws to simulate from the fitted summary. |
null |
Numeric value defining the reference for direction (default 0). |
A data frame of class qbrms_p_direction.
Compute the probability that each parameter is above a threshold in the median's direction, similar to bayestestR::p_significance(). This represents the proportion of the posterior distribution that indicates a "significant" effect in the median's direction.
p_significance( object, parameters = NULL, threshold = "default", nsim = 1000, verbose = TRUE )p_significance( object, parameters = NULL, threshold = "default", nsim = 1000, verbose = TRUE )
object |
A |
parameters |
Optional character vector of parameter names; if |
threshold |
The threshold value that separates significant from negligible effect:
|
nsim |
Number of draws to simulate for the approximation. |
verbose |
Logical; print progress information. |
A data frame of class qbrms_p_significance with columns
Parameter, ps, Median, CI_low, CI_high,
Threshold_low, Threshold_high, and Interpretation.
Create density plots for multiple model parameters, optionally comparing posterior estimates with their priors. Returns a ggplot2 object with faceted parameter plots.
Create density plots for multiple model parameters, optionally comparing posterior estimates with their priors. Returns a ggplot2 object with faceted parameter plots.
plot_parameters( object, pars = NULL, show_prior = FALSE, ndraws = 200, prior_ndraws = 200, ncol = 2, alpha_levels = c(0.8, 0.5), colours = c("#1F78B4", "#E31A1C"), verbose = TRUE, ... ) plot_parameters( object, pars = NULL, show_prior = FALSE, ndraws = 200, prior_ndraws = 200, ncol = 2, alpha_levels = c(0.8, 0.5), colours = c("#1F78B4", "#E31A1C"), verbose = TRUE, ... )plot_parameters( object, pars = NULL, show_prior = FALSE, ndraws = 200, prior_ndraws = 200, ncol = 2, alpha_levels = c(0.8, 0.5), colours = c("#1F78B4", "#E31A1C"), verbose = TRUE, ... ) plot_parameters( object, pars = NULL, show_prior = FALSE, ndraws = 200, prior_ndraws = 200, ncol = 2, alpha_levels = c(0.8, 0.5), colours = c("#1F78B4", "#E31A1C"), verbose = TRUE, ... )
object |
A |
pars |
Optional character vector of parameter names to plot. If |
show_prior |
Logical; if |
ndraws |
Number of posterior draws to use for plotting. |
prior_ndraws |
Number of prior draws to use if |
ncol |
Number of columns for faceting (default 2). |
alpha_levels |
Numeric vector of length 2 giving alpha levels for c(posterior, prior). Default c(0.8, 0.5). |
colours |
Character vector of length 2 giving colours for c(posterior, prior). Default c("#1F78B4", "#E31A1C"). |
verbose |
Logical; print progress information. |
... |
Additional arguments (currently unused). |
A ggplot2 object with faceted parameter density plots.
A ggplot2 object with faceted parameter density plots.
## Not run: fit <- qbrms(y ~ x1 + x2, data = my_data, sample_prior = "yes") # Plot all parameters plot_parameters(fit) # Plot specific parameters with priors plot_parameters(fit, pars = c("x1", "x2"), show_prior = TRUE) # Customize appearance plot_parameters(fit, show_prior = TRUE) + theme_bw() + labs(title = "My Parameter Estimates") ## End(Not run) ## Not run: fit <- qbrms(y ~ x1 + x2, data = my_data, sample_prior = "yes") # Plot all parameters plot_parameters(fit) # Plot specific parameters with priors plot_parameters(fit, pars = c("x1", "x2"), show_prior = TRUE) # Customize appearance plot_parameters(fit, show_prior = TRUE) + theme_bw() + labs(title = "My Parameter Estimates") ## End(Not run)## Not run: fit <- qbrms(y ~ x1 + x2, data = my_data, sample_prior = "yes") # Plot all parameters plot_parameters(fit) # Plot specific parameters with priors plot_parameters(fit, pars = c("x1", "x2"), show_prior = TRUE) # Customize appearance plot_parameters(fit, show_prior = TRUE) + theme_bw() + labs(title = "My Parameter Estimates") ## End(Not run) ## Not run: fit <- qbrms(y ~ x1 + x2, data = my_data, sample_prior = "yes") # Plot all parameters plot_parameters(fit) # Plot specific parameters with priors plot_parameters(fit, pars = c("x1", "x2"), show_prior = TRUE) # Customize appearance plot_parameters(fit, show_prior = TRUE) + theme_bw() + labs(title = "My Parameter Estimates") ## End(Not run)
Plot method for objects returned by conditional_effects and
related helpers. For a single effect, this produces either a spaghetti plot
of draws or a ribbon / slice plot of summary statistics. For multiple effects
it can combine the plots using patchwork if available.
## S3 method for class 'qbrms_conditional_effects' plot(x, ...)## S3 method for class 'qbrms_conditional_effects' plot(x, ...)
x |
An object of class |
... |
Currently ignored. Included for future extensions and method compatibility. |
For a single effect, a ggplot2 object.
For multiple effects, either
a patchwork object combining the individual plots (if the patchwork package is installed), or
a named list of ggplot2 objects otherwise.
Plot Method for Diagnostics
## S3 method for class 'qbrms_diagnostics' plot(x, which = "all", ...)## S3 method for class 'qbrms_diagnostics' plot(x, which = "all", ...)
x |
A qbrms_diagnostics object |
which |
Character vector specifying which plots to show |
... |
Additional arguments (unused) |
Invisibly returns the input object x.
Create a visual plot of probability of practical significance results.
Create a visual plot of probability of practical significance results.
## S3 method for class 'qbrms_p_significance' plot(x, ...) ## S3 method for class 'qbrms_p_significance' plot(x, ...)## S3 method for class 'qbrms_p_significance' plot(x, ...) ## S3 method for class 'qbrms_p_significance' plot(x, ...)
x |
A |
... |
Additional arguments passed to ggplot2 functions. |
A ggplot2 object.
A ggplot2 object.
Poisson Family
poisson()poisson()
An object of class "family" representing the Poisson distribution.
Create posterior or prior predictive diagnostic plots for fitted qbrms models.
pp_check(object, ...) ## S3 method for class 'qbrms_fit' pp_check( object, type = "dens_overlay", ndraws = 5000, seed = NULL, show_observed = FALSE, ... ) ## S3 method for class 'qbrms_prior' pp_check( object, type = "dens_overlay", ndraws = 5000, seed = NULL, show_observed = FALSE, ... )pp_check(object, ...) ## S3 method for class 'qbrms_fit' pp_check( object, type = "dens_overlay", ndraws = 5000, seed = NULL, show_observed = FALSE, ... ) ## S3 method for class 'qbrms_prior' pp_check( object, type = "dens_overlay", ndraws = 5000, seed = NULL, show_observed = FALSE, ... )
object |
A model object. |
... |
Additional arguments passed to methods. |
type |
Character string indicating the check type: one of
|
ndraws |
Integer number of draws to use. |
seed |
Optional RNG seed. |
show_observed |
Logical; show observed data where applicable. |
Posterior predictive checks for TMB ordinal models
## S3 method for class 'tmb_ordinal_qbrms_fit' pp_check( object, type = "bars", ndraws = 100, seed = NULL, newdata = NULL, prob = 0.9, ... )## S3 method for class 'tmb_ordinal_qbrms_fit' pp_check( object, type = "bars", ndraws = 100, seed = NULL, newdata = NULL, prob = 0.9, ... )
object |
A fitted TMB ordinal qbrms model object |
type |
Character; type of posterior predictive check |
ndraws |
Integer; number of posterior draws to use |
seed |
Random seed for reproducibility. |
newdata |
Optional data frame for predictions. If NULL, uses original data. |
prob |
Probability mass for credible intervals (default 0.95). |
... |
Additional arguments passed to methods. |
A ggplot object showing the posterior predictive check
Nicely formatted one-line summary plus key diagnostics for a qbrmb_fit.
Prints a summary of a regularised binomial qbrms model.
## S3 method for class 'qbrmb_fit' print(x, digits = 2, ...) ## S3 method for class 'qbrmb_fit' print(x, digits = 2, ...)## S3 method for class 'qbrmb_fit' print(x, digits = 2, ...) ## S3 method for class 'qbrmb_fit' print(x, digits = 2, ...)
x |
A |
digits |
Number of decimal places for output (default: 2). |
... |
Additional arguments (currently unused). |
Invisibly returns the input object x.
Print Method for Diagnostics
## S3 method for class 'qbrms_diagnostics' print(x, ...)## S3 method for class 'qbrms_diagnostics' print(x, ...)
x |
A qbrms_diagnostics object |
... |
Additional arguments (unused) |
Invisibly returns the input object x.
Prints a summary of a fitted qbrms model object.
## S3 method for class 'qbrms_fit' print(x, digits = 2, ...)## S3 method for class 'qbrms_fit' print(x, digits = 2, ...)
x |
A |
digits |
Number of decimal places for output (default: 2). |
... |
Additional arguments (currently unused). |
Invisibly returns the input object x.
if (requireNamespace("INLA", quietly = TRUE)) { fit <- qbrms(mpg ~ hp, data = mtcars, family = gaussian(), verbose = FALSE) print(fit) }if (requireNamespace("INLA", quietly = TRUE)) { fit <- qbrms(mpg ~ hp, data = mtcars, family = gaussian(), verbose = FALSE) print(fit) }
Print Method for qbrms_kfold Objects
## S3 method for class 'qbrms_kfold' print(x, ...)## S3 method for class 'qbrms_kfold' print(x, ...)
x |
A qbrms_kfold object |
... |
Additional arguments (unused) |
Invisibly returns the input object x.
Print Method for qbrms_loo_compare Objects
## S3 method for class 'qbrms_loo_compare' print(x, ...)## S3 method for class 'qbrms_loo_compare' print(x, ...)
x |
A qbrms_loo_compare object |
... |
Additional arguments (unused) |
Invisibly returns the input object x.
Print Method for qbrms_model_spec
## S3 method for class 'qbrms_model_spec' print(x, ...)## S3 method for class 'qbrms_model_spec' print(x, ...)
x |
A qbrms_model_spec object |
... |
Additional arguments (unused) |
Invisibly returns the input object x.
Shorthand print method that delegates to
summary.qbrms_multinomial_fit().
## S3 method for class 'qbrms_multinomial_fit' print(x, digits = 2, ...)## S3 method for class 'qbrms_multinomial_fit' print(x, digits = 2, ...)
x |
A |
digits |
Integer; number of decimal places to display. |
... |
Unused. |
The input x, returned invisibly.
Print results from probability of practical significance analysis.
## S3 method for class 'qbrms_p_significance' print(x, digits = 3, ...) ## S3 method for class 'qbrms_p_significance' print(x, digits = 3, ...)## S3 method for class 'qbrms_p_significance' print(x, digits = 3, ...) ## S3 method for class 'qbrms_p_significance' print(x, digits = 3, ...)
x |
A |
digits |
Number of decimal places to display (default 3). |
... |
Additional arguments passed to |
Invisibly returns the input object.
Invisibly returns the input object.
Nicely formats the result of prior_build_from_beliefs(), showing the
elicited beliefs, implied prior distributions, and (optionally) the
corresponding prior code.
## S3 method for class 'qbrms_prior_build' print( x, digits = 3, show_data = FALSE, show_code = TRUE, code_object_name = "priors", max_terms = 12, ... )## S3 method for class 'qbrms_prior_build' print( x, digits = 3, show_data = FALSE, show_code = TRUE, code_object_name = "priors", max_terms = 12, ... )
x |
An object of class |
digits |
Integer scalar giving the number of decimal places to display
for numeric summaries (default: |
show_data |
Logical; if |
show_code |
Logical; if |
code_object_name |
Character string giving the name that will be used
for the prior object in the displayed code (default: |
max_terms |
Integer scalar giving the maximum number of individual terms
to display before truncating the printed output (default: |
... |
Currently ignored. Included for method compatibility. |
Invisibly returns the input object x.
Print method for qbrms_prior_code objects
## S3 method for class 'qbrms_prior_code' print(x, ...)## S3 method for class 'qbrms_prior_code' print(x, ...)
x |
A qbrms_prior_code object |
... |
Additional arguments passed to cat |
Invisibly returns the input object x.
Print method for qbrms_prior_diagnostics objects
## S3 method for class 'qbrms_prior_diagnostics' print(x, digits = 3, ...)## S3 method for class 'qbrms_prior_diagnostics' print(x, digits = 3, ...)
x |
A qbrms_prior_diagnostics object |
digits |
Number of decimal places to display (default 3) # <– ADD THIS LINE |
... |
Additional arguments (unused) |
The input object, returned invisibly
Print Prior Distribution Objects
## S3 method for class 'qbrms_prior_dist' print(x, ...)## S3 method for class 'qbrms_prior_dist' print(x, ...)
x |
A qbrms_prior_dist object |
... |
Unused |
Invisibly returns x.
Print Prior List Objects
## S3 method for class 'qbrms_prior_list' print(x, ...)## S3 method for class 'qbrms_prior_list' print(x, ...)
x |
A qbrms_prior_list object |
... |
Unused |
Invisibly returns x.
Print Prior Specification Objects
## S3 method for class 'qbrms_prior_spec' print(x, ...)## S3 method for class 'qbrms_prior_spec' print(x, ...)
x |
A qbrms_prior_spec object |
... |
Unused |
Invisibly returns x.
Print method for qbrms formulas
## S3 method for class 'qbrmsformula' print(x, ...)## S3 method for class 'qbrmsformula' print(x, ...)
x |
A qbrmsformula object |
... |
Unused |
Invisibly returns the input object x.
Print Method for summary.qbrms_fit Objects
## S3 method for class 'summary.qbrms_fit' print(x, ...)## S3 method for class 'summary.qbrms_fit' print(x, ...)
x |
A |
... |
Additional arguments (currently unused). |
Invisibly returns the input object x.
Print Method for TMB Ordinal Fits
## S3 method for class 'tmb_ordinal_qbrms_fit' print(x, digits = 2, ...)## S3 method for class 'tmb_ordinal_qbrms_fit' print(x, digits = 2, ...)
x |
A tmb_ordinal_qbrms_fit object |
digits |
Number of decimal places for output |
... |
Additional arguments |
Invisibly returns the object
Specify Prior for Model Parameters
prior(prior, class = "b", coef = NULL, group = NULL)prior(prior, class = "b", coef = NULL, group = NULL)
prior |
A prior distribution object. |
class |
Parameter class ("Intercept", "b", "sd", etc.) |
coef |
Specific coefficient name (optional) |
group |
Specific group name for random effects (optional) |
A prior specification object
Build priors from elicited beliefs (GLM-aware)
prior_build_from_beliefs( formula, data, family = gaussian(), beliefs = list(), outcome_location = NULL, outcome_interval = NULL, outcome_level = 0.95, outcome_sd = NULL, standardise = TRUE, plausible_range = NULL, target_coverage = 0.8, tune = FALSE, seed = NULL )prior_build_from_beliefs( formula, data, family = gaussian(), beliefs = list(), outcome_location = NULL, outcome_interval = NULL, outcome_level = 0.95, outcome_sd = NULL, standardise = TRUE, plausible_range = NULL, target_coverage = 0.8, tune = FALSE, seed = NULL )
formula |
Model formula |
data |
Data frame |
family |
Model family |
beliefs |
List of beliefs about parameters |
outcome_location |
Expected outcome location |
outcome_interval |
Expected outcome interval |
outcome_level |
Confidence level for outcome interval |
outcome_sd |
Outcome standard deviation |
standardise |
Whether to standardise predictors |
plausible_range |
Plausible range for outcomes |
target_coverage |
Target coverage probability |
tune |
Whether to tune priors |
seed |
Random seed |
An object of class "qbrms_prior_build" containing:
priors: A list of prior specifications.
prior_code: Character string of R code to reproduce the priors.
formula: The (possibly modified) model formula.
data: The (possibly standardised) data.
diagnostics: Prior predictive diagnostic information.
Format priors as qbrms prior() code
prior_code(build, object_name = "priors", digits = 3, include_comments = TRUE)prior_code(build, object_name = "priors", digits = 3, include_comments = TRUE)
build |
A 'qbrms_prior_build' returned by prior_build_from_beliefs() |
object_name |
Name of the object on the left-hand side (default "priors") |
digits |
Number of decimal places to print |
include_comments |
Logical; if TRUE, prepend a short comment header |
A single character string containing formatted R code
Summarise prior predictive draws to check basic support, scale and shape, and (optionally) how simple statistics of the observed data compare with the prior-predictive distribution. Returns an object with a concise verdict.
prior_pp_diagnostics( object, level = 0.95, support = NULL, lower = NULL, upper = NULL, trials = NULL, plausible_lower = NULL, plausible_upper = NULL, include_observed = TRUE, seed = NULL )prior_pp_diagnostics( object, level = 0.95, support = NULL, lower = NULL, upper = NULL, trials = NULL, plausible_lower = NULL, plausible_upper = NULL, include_observed = TRUE, seed = NULL )
object |
A qbrms prior object: qbrms_prior_fit, qbrms_prior_only, or a qbrms_fit
that contains |
level |
Credible level for central intervals (default 0.95). Reserved. |
support |
Optional override of the implied support: one of "real",
"positive", "proportion", or "bounded". If |
lower, upper
|
Optional numeric bounds used when |
trials |
Optional integer vector for binomial data (bounds helper). |
plausible_lower, plausible_upper
|
Optional numeric bounds defining a user-declared
“plausible range” for the outcome on the response scale. When both are supplied,
the function reports the fraction of prior-predictive mass that falls in
|
include_observed |
Logical; if |
seed |
Optional seed for reproducibility. |
An object of class qbrms_prior_diagnostics.
A convenience wrapper mirroring pp_check's show_observed flag
prior_pp_summary( object, show_observed = FALSE, plausible_lower = NULL, plausible_upper = NULL, ... )prior_pp_summary( object, show_observed = FALSE, plausible_lower = NULL, plausible_upper = NULL, ... )
object |
A qbrms prior object. |
show_observed |
Logical; compare observed summaries when available. |
plausible_lower, plausible_upper
|
Optional plausible range bounds to score coverage. |
... |
Passed to |
The diagnostics object, invisibly, after printing a summary.
Generate predictions from the prior distribution to assess whether priors are reasonable before seeing the data.
prior_predictive_check(formula, data, family, prior, n_samples = 1000)prior_predictive_check(formula, data, family, prior, n_samples = 1000)
formula |
Model formula |
data |
Data frame (used for structure, not values) |
family |
Model family |
prior |
Prior specification |
n_samples |
Number of prior predictive samples (default: 1000) |
A ggplot object showing the prior predictive distribution
## Not run: prior_predictive_check( mpg ~ hp + wt, data = mtcars, family = gaussian(), prior = prior(normal(0, 10), class = "b") ) ## End(Not run)## Not run: prior_predictive_check( mpg ~ hp + wt, data = mtcars, family = gaussian(), prior = prior(normal(0, 10), class = "b") ) ## End(Not run)
Fit a model with priors sampled, then produce a comparison density plot that overlays posterior, prior, and observed distributions where available.
prior_to_posterior_workflow( formula, data, family = gaussian(), prior = NULL, verbose = TRUE, ... )prior_to_posterior_workflow( formula, data, family = gaussian(), prior = NULL, verbose = TRUE, ... )
formula |
Model formula. |
data |
Data frame. |
family |
Model family (default |
prior |
Prior specification (default |
verbose |
Logical; print progress messages. |
... |
Additional arguments forwarded to |
A list of class qbrms_workflow_result with elements fit and plot.
Functions to specify prior distributions for qbrms models
qbrms()
qbrm() is a shorter alias for qbrms() with identical functionality.
Enhanced interface to qbrms with all required parameters and built-in diagnostics.
qbrm( formula, data, family = gaussian(), prior = NULL, sample_prior = "no", verbose = TRUE, ... ) qbrm( formula, data, family = gaussian(), prior = NULL, sample_prior = "no", verbose = TRUE, ... )qbrm( formula, data, family = gaussian(), prior = NULL, sample_prior = "no", verbose = TRUE, ... ) qbrm( formula, data, family = gaussian(), prior = NULL, sample_prior = "no", verbose = TRUE, ... )
formula |
Model formula in lme4/brms style. |
data |
Data frame containing the variables in the model. |
family |
Model family (default: gaussian()). |
prior |
Prior specifications (default: NULL). |
sample_prior |
Whether to sample from priors ("no", "yes", "only"). Default: "no". |
verbose |
Logical; print diagnostic information (default: TRUE). |
... |
Additional arguments passed to qbrms(). |
An object of class "qbrms_fit", same as qbrms().
A qbrms_fit object with model results.
Fits a regularised binomial (or Bernoulli) mixed-effects model using INLA, with enhanced diagnostics, stability checks and strategy selection.
qbrmb( formula, data, family = "binomial", strategy = "auto", regularisation_strength = 0.1, use_data_augmentation = TRUE, min_group_size = 5, verbose = FALSE, diagnostics = FALSE, silent = FALSE, ... )qbrmb( formula, data, family = "binomial", strategy = "auto", regularisation_strength = 0.1, use_data_augmentation = TRUE, min_group_size = 5, verbose = FALSE, diagnostics = FALSE, silent = FALSE, ... )
formula |
Model formula with random effects in lme4-style syntax. |
data |
Data frame containing the variables in the model. |
family |
Model family (currently |
strategy |
Fitting strategy: |
regularisation_strength |
Regularisation strength in the interval
|
use_data_augmentation |
Logical; if |
min_group_size |
Minimum group size before triggering diagnostic warnings. |
verbose |
Logical; if |
diagnostics |
Logical; if |
silent |
Logical; if |
... |
Additional arguments passed to |
An object of class c("qbrmb_fit", "qbrms_fit", "list")
containing the fitted model, diagnostics and metadata.
Convenience wrapper around qbrmb using the "aggressive"
strategy with a higher default regularisation strength.
qbrmb_aggressive(formula, data, verbose = FALSE, ...)qbrmb_aggressive(formula, data, verbose = FALSE, ...)
formula |
Model formula with random effects (lme4-style). |
data |
Data frame containing the variables in the model. |
verbose |
Logical; if |
... |
Additional arguments passed to |
An object of class c("qbrmb_fit", "qbrms_fit", "list").
if (requireNamespace("INLA", quietly = TRUE)) { set.seed(123) data <- data.frame( y = rbinom(100, 1, 0.2), x = rnorm(100), group = factor(rep(1:10, each = 10)) ) # qbrmb_aggressive requires a mixed model with random intercepts fit <- qbrmb_aggressive(y ~ x + (1 | group), data = data, verbose = FALSE) }if (requireNamespace("INLA", quietly = TRUE)) { set.seed(123) data <- data.frame( y = rbinom(100, 1, 0.2), x = rnorm(100), group = factor(rep(1:10, each = 10)) ) # qbrmb_aggressive requires a mixed model with random intercepts fit <- qbrmb_aggressive(y ~ x + (1 | group), data = data, verbose = FALSE) }
Convenience wrapper around qbrmb using the "enhanced"
regularisation strategy and a stronger default regularisation strength.
qbrmb_regularised(formula, data, verbose = FALSE, ...)qbrmb_regularised(formula, data, verbose = FALSE, ...)
formula |
Model formula with random effects (lme4-style). |
data |
Data frame containing the variables in the model. |
verbose |
Logical; if |
... |
Additional arguments passed to |
An object of class c("qbrmb_fit", "qbrms_fit", "list").
Fits ordinal regression models using Template Model Builder (TMB) with Laplace approximation and adaptive threshold centering to match brms output.
qbrmO( formula, data, family = cumulative(), prior = NULL, verbose = FALSE, threshold_method = "quantile", control = list(), ... )qbrmO( formula, data, family = cumulative(), prior = NULL, verbose = FALSE, threshold_method = "quantile", control = list(), ... )
formula |
Model formula with ordinal response on the left-hand side. |
data |
Data frame containing the variables in the model. |
family |
Ordinal family specification. Currently supports cumulative(). |
prior |
Prior specifications using qbrms prior syntax. |
verbose |
Logical; print progress messages during fitting. |
threshold_method |
Method for threshold centering ("quantile" or "cumulative_mean"). |
control |
List of control parameters for TMB optimization. |
... |
Additional arguments passed to TMB functions. |
An object of class c("tmb_ordinal_qbrms_fit", "qbrms_fit")
Enhanced qbrms interface with automatic routing to specialised implementations. Supports ordinal regression via TMB, quantile regression, and all standard INLA families.
qbrms( formula, data, family = gaussian(), prior = NULL, sample_prior = "no", quantile = 0.5, control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE), verbose = getOption("qbrms.verbose", FALSE), ... )qbrms( formula, data, family = gaussian(), prior = NULL, sample_prior = "no", quantile = 0.5, control.compute = list(dic = TRUE, waic = TRUE, cpo = TRUE), verbose = getOption("qbrms.verbose", FALSE), ... )
formula |
Model formula in lme4/brms style |
data |
Data frame containing the variables in the model |
family |
Model family (default: gaussian()). Ordinal families automatically route to qbrmO() |
prior |
Prior specifications (default: NULL) |
sample_prior |
Whether to sample from priors ("no", "yes", "only"). Default: "no" |
quantile |
For asymmetric_laplace family, which quantile to estimate (default: 0.5) |
control.compute |
INLA control settings for model information criteria |
verbose |
Logical; print diagnostic information (default: getOption("qbrms.verbose", FALSE)) |
... |
Additional arguments passed to fitting functions |
An object of class "qbrms_fit" (or "qbrmO_fit" for ordinal models).
The object is a list containing:
fit: The internal model fit (INLA or TMB object).
model_type: String indicating the type of model fitted.
data: The data used for fitting.
original_formula: The formula used.
prior_samples: Prior predictive samples (if requested).
qbrmO for direct ordinal model fitting
Posterior analysis tools for qbrms models: Bayes factors, probability of direction, ROPE, HDI, and estimated marginal means.
Fits binomial mixed effects models with regularisation, with all parameters handled correctly.
qbrms_binomial_regularised( formula, data, regularise = TRUE, sample_prior = "no", verbose = TRUE, ... )qbrms_binomial_regularised( formula, data, regularise = TRUE, sample_prior = "no", verbose = TRUE, ... )
formula |
Model formula with mixed effects structure. |
data |
Data frame containing the variables. |
regularise |
Logical; if TRUE, apply regularisation techniques. |
sample_prior |
Whether to sample from priors ("no", "yes", "only"). Default: "no". |
verbose |
Logical; print progress information. |
... |
Additional arguments passed to qbrms(). |
A qbrms_fit object with additional regularisation metadata.
Compute estimated marginal means (least-squares means) for factor terms
and their combinations for a qbrms_fit, using a multivariate-normal
approximation to the posterior of the fixed effects.
qbrms_emmeans(object, specs, at = NULL, nsim = 1000, prob = 0.95, ...)qbrms_emmeans(object, specs, at = NULL, nsim = 1000, prob = 0.95, ...)
object |
A |
specs |
Character vector naming factor(s) for EMMs, or a string
containing a formula with a right-hand side (for example, |
at |
Optional named list giving values at which to hold other predictors. Numerics are fixed at their means if not supplied; factors at their modal level. |
nsim |
Number of posterior draws for uncertainty. |
prob |
Interval mass (default 0.95). |
... |
Additional arguments (currently not used). |
A data frame of class qbrms_emmeans.
Get captured fit log from a qbrms object (if available)
qbrms_fit_log(x)qbrms_fit_log(x)
x |
A qbrms_fit / qbrmO_fit object returned by qbrm()/qbrms() |
A character vector of captured console lines, or NULL if none
Splits an ordered response with K levels into K-1 binary problems (thresholds y > c_j) and fits a simple binomial GLM for each split.
qbrms_ordinal_binary(formula, data, verbose = FALSE, ...)qbrms_ordinal_binary(formula, data, verbose = FALSE, ...)
formula |
Model formula with an ordered response on the LHS. |
data |
Data frame. |
verbose |
Logical; print progress messages. |
... |
Ignored (compat). |
An object of class c("ordinal_binary_qbrms_fit","qbrms_fit") with:
binary_models: list of length K-1 of fitted glm objects
thresholds: character vector of thresholds used
response: response variable name
levels: factor levels of the ordered response
ordinal_levels: factor levels (for test compatibility)
Set qbrms verbosity for the current session
qbrms_set_verbosity(verbose = FALSE)qbrms_set_verbosity(verbose = FALSE)
verbose |
Logical. If TRUE, fitting prints progress; if FALSE, fitting is silent. |
Invisibly returns the previous value.
Compute approximate DIC, LOO and WAIC for qbrms model fits.
waic(object, ...) loo(object, ...) dic(object, ...) ## S3 method for class 'qbrms_fit' waic(object, ...) ## S3 method for class 'qbrms_fit' loo(object, ...) ## S3 method for class 'qbrms_fit' dic(object, ...)waic(object, ...) loo(object, ...) dic(object, ...) ## S3 method for class 'qbrms_fit' waic(object, ...) ## S3 method for class 'qbrms_fit' loo(object, ...) ## S3 method for class 'qbrms_fit' dic(object, ...)
object |
A |
... |
Additional arguments passed to internal methods or underlying tools. |
These functions provide generic interfaces (dic(), loo(), waic())
and S3 methods for qbrms_fit objects that extract the corresponding
criteria from the underlying INLA fit where available.
For dic(), loo() and waic() methods on
qbrms_fit objects, a list containing the corresponding criterion
(for example, list(dic = ...), list(looic = ..., elpd_loo = ...),
or list(waic = ...)). If the criterion cannot be computed, NA_real_
is returned.
Quick Density Comparison
quick_density_comparison(object, parameter = NULL, ...)quick_density_comparison(object, parameter = NULL, ...)
object |
A |
parameter |
Optional parameter name to focus the comparison. |
... |
Additional arguments forwarded to |
A ggplot2 object.
Random Walk Families
rw1(scale.model = "log", diagonal = 1e-06) rw2(scale.model = "log", diagonal = 1e-06)rw1(scale.model = "log", diagonal = 1e-06) rw2(scale.model = "log", diagonal = 1e-06)
scale.model |
Scaling model for precision |
diagonal |
Diagonal precision matrix structure |
A family object of class "family".
Extract residuals from qbrms models
## S3 method for class 'qbrms_fit' residuals(object, type = "response", ...)## S3 method for class 'qbrms_fit' residuals(object, type = "response", ...)
object |
A qbrms_fit object |
type |
Character string indicating type of residuals (default: "response") |
... |
Additional arguments (currently unused) |
Numeric vector of residuals
## Not run: fit <- qbrms(mpg ~ hp, data = mtcars, family = gaussian()) resid_values <- residuals(fit, type = "response") ## End(Not run)## Not run: fit <- qbrms(mpg ~ hp, data = mtcars, family = gaussian()) resid_values <- residuals(fit, type = "response") ## End(Not run)
Compute the posterior mass inside a Region Of Practical Equivalence (ROPE) for selected parameters.
rope_analysis(object, parameters = NULL, rope = c(-0.1, 0.1), nsim = 4000)rope_analysis(object, parameters = NULL, rope = c(-0.1, 0.1), nsim = 4000)
object |
A |
parameters |
Optional character vector of parameter names. If |
rope |
Numeric length-2 vector |
nsim |
Number of posterior draws to simulate. |
A data frame of class qbrms_rope.
Simplex Family for Compositional Data
simplex(link = "logit", link.precision = "log")simplex(link = "logit", link.precision = "log")
link |
Link function for the mean (default: "logit") |
link.precision |
Link function for precision parameter (default: "log") |
A family object of class "family".
Skew Normal Family
skew_normal()skew_normal()
An object of class "family" representing the Skew Normal distribution.
Student's t-distribution family for robust regression with heavier tails than Gaussian to handle outliers.
Functions that act as both family constructors (for qbrm) and prior
specifications (for prior), depending on arguments.
student_t( link_or_df = "identity", location = 0, scale = 1, link = NULL, link.sigma = "log", link.nu = "log", ... ) student() student_t( link_or_df = "identity", location = 0, scale = 1, link = NULL, link.sigma = "log", link.nu = "log", ... ) student_t_prior( link_or_df = 3, location = 0, scale = 1, link.sigma = "log", link.nu = "log" )student_t( link_or_df = "identity", location = 0, scale = 1, link = NULL, link.sigma = "log", link.nu = "log", ... ) student() student_t( link_or_df = "identity", location = 0, scale = 1, link = NULL, link.sigma = "log", link.nu = "log", ... ) student_t_prior( link_or_df = 3, location = 0, scale = 1, link.sigma = "log", link.nu = "log" )
link_or_df |
For family: link function (character). For prior: degrees of freedom (numeric). |
location |
Location parameter (prior only). |
scale |
Scale parameter (prior only). |
link |
Optional link function (if acting as family). |
link.sigma |
Link for sigma (family only). |
link.nu |
Link for nu (family only). |
... |
Additional arguments. |
An object of class "family" specifying the Student-t distribution.
An object of class "family" specifying the Student-t distribution.
A family object or prior object depending on inputs.
# Create a Student-t family object fam <- student_t() print(fam$family)# Create a Student-t family object fam <- student_t() print(fam$family)
Provides a detailed summary of a regularised binomial qbrms model.
## S3 method for class 'qbrmb_fit' summary(object, digits = 2, ...)## S3 method for class 'qbrmb_fit' summary(object, digits = 2, ...)
object |
A |
digits |
Number of decimal places for output (default: 2). |
... |
Additional arguments (currently unused). |
An object of class "summary.qbrmb_fit" containing model summary information.
Provides a detailed summary of a fitted qbrms model.
## S3 method for class 'qbrms_fit' summary(object, ..., digits = 2) ## S3 method for class 'qbrms_fit' summary(object, ..., digits = 2)## S3 method for class 'qbrms_fit' summary(object, ..., digits = 2) ## S3 method for class 'qbrms_fit' summary(object, ..., digits = 2)
object |
A qbrms_fit object |
... |
Additional arguments |
digits |
Number of digits for output (default 2) |
An object of class "summary.qbrms_fit" containing:
formula: The model formula.
family: The distribution family.
nobs: Number of observations.
fixed: Data frame of fixed effects estimates.
random: Random effects summary (if applicable).
if (requireNamespace("INLA", quietly = TRUE)) { fit <- qbrms(mpg ~ hp, data = mtcars, family = gaussian(), verbose = FALSE) summary(fit) }if (requireNamespace("INLA", quietly = TRUE)) { fit <- qbrms(mpg ~ hp, data = mtcars, family = gaussian(), verbose = FALSE) summary(fit) }
Print a readable summary of a qbrms_multinomial_fit, including its
reference category, the list of categories, and per-category fixed-effect
summaries when available.
## S3 method for class 'qbrms_multinomial_fit' summary(object, digits = 2, ...)## S3 method for class 'qbrms_multinomial_fit' summary(object, digits = 2, ...)
object |
A |
digits |
Integer; number of decimal places to display. |
... |
Unused. |
The input object, returned invisibly.
Provide a summary of probability of practical significance results.
## S3 method for class 'qbrms_p_significance' summary(object, ...) ## S3 method for class 'qbrms_p_significance' summary(object, ...)## S3 method for class 'qbrms_p_significance' summary(object, ...) ## S3 method for class 'qbrms_p_significance' summary(object, ...)
object |
A |
... |
Additional arguments (currently unused). |
Invisibly returns the input object.
Invisibly returns the input object.
Summary Method for TMB Ordinal Fits
## S3 method for class 'tmb_ordinal_qbrms_fit' summary(object, digits = 2, ...)## S3 method for class 'tmb_ordinal_qbrms_fit' summary(object, digits = 2, ...)
object |
A tmb_ordinal_qbrms_fit object |
digits |
Number of decimal places for output |
... |
Additional arguments |
Invisibly returns the object
Generate APA-style HTML tables for qbrms model outputs with customizable styling options.
tab_model( ..., show.ci = TRUE, ci.lvl = 0.95, show.rope = FALSE, rope = c(-0.1, 0.1), show.p_sig = FALSE, show.pd = FALSE, show.bf = FALSE, digits = 2, title = "Model Results", file = NULL, CSS = NULL, dv.labels = NULL, pred.labels = NULL, show.intercept = TRUE, show.r2 = FALSE, show.icc = FALSE, show.nobs = TRUE, bootstrap = TRUE, table.style = "default", font.family = "system-ui, -apple-system, sans-serif", font.size = "14px", header.bg = "#f8f9fa", stripe.bg = "#f9f9f9", verbose = FALSE )tab_model( ..., show.ci = TRUE, ci.lvl = 0.95, show.rope = FALSE, rope = c(-0.1, 0.1), show.p_sig = FALSE, show.pd = FALSE, show.bf = FALSE, digits = 2, title = "Model Results", file = NULL, CSS = NULL, dv.labels = NULL, pred.labels = NULL, show.intercept = TRUE, show.r2 = FALSE, show.icc = FALSE, show.nobs = TRUE, bootstrap = TRUE, table.style = "default", font.family = "system-ui, -apple-system, sans-serif", font.size = "14px", header.bg = "#f8f9fa", stripe.bg = "#f9f9f9", verbose = FALSE )
... |
One or more qbrms_fit objects to display in the table |
show.ci |
Logical; show credible intervals (default TRUE) |
ci.lvl |
Credible interval level (default 0.95) |
show.rope |
Logical; show ROPE analysis (default FALSE) |
rope |
Numeric vector c(lower, upper) for ROPE bounds |
show.p_sig |
Logical; show probability of practical significance (default FALSE) |
show.pd |
Logical; show probability of direction (default FALSE) |
show.bf |
Logical; show Bayes factors (default FALSE) |
digits |
Number of decimal places (default 2) |
title |
Character; table title |
file |
Character; file path to save HTML output (optional) |
CSS |
Character; custom CSS styling (optional) |
dv.labels |
Character vector of dependent variable labels |
pred.labels |
Named character vector for predictor labels |
show.intercept |
Logical; show intercept row (default TRUE) |
show.r2 |
Logical; show R-squared if available (default FALSE) |
show.icc |
Logical; show ICC for mixed models (default FALSE) |
show.nobs |
Logical; show number of observations (default TRUE) |
bootstrap |
Logical; use Bootstrap CSS framework (default TRUE) |
table.style |
Character; table style theme. Options: "default", "minimal", "academic", "modern" |
font.family |
Character; CSS font family (default "system-ui") |
font.size |
Character; base font size (default "14px") |
header.bg |
Character; header background colour (default "#f8f9fa") |
stripe.bg |
Character; striped row background colour (default "#f9f9f9") |
verbose |
Logical; print progress (default FALSE) |
An object of class "qbrms_html_table" containing the HTML code
Test the corrected implementation with a mixed-effects example
test_corrected_bayes_R2()test_corrected_bayes_R2()
## Not run: # Test with mixed-effects model library(qbrms) # Create sample data with strong group effects set.seed(123) n_groups <- 10 n_per_group <- 20 n_total <- n_groups * n_per_group data <- data.frame( group = factor(rep(1:n_groups, each = n_per_group)), x = rnorm(n_total), group_effect = rep(rnorm(n_groups, 0, 2), each = n_per_group) ) # Generate response with strong group effects data$y <- 2 + 0.5 * data$x + data$group_effect + rnorm(n_total, 0, 0.5) # Fit mixed-effects model fit_mixed <- qbrms(y ~ x + (1|group), data = data, family = gaussian()) # Compute Bayesian R-squared (should now match brms closely) r2_corrected <- bayes_R2(fit_mixed, verbose = TRUE) print(r2_corrected) # Should show high R-squared due to strong group effects ## End(Not run)## Not run: # Test with mixed-effects model library(qbrms) # Create sample data with strong group effects set.seed(123) n_groups <- 10 n_per_group <- 20 n_total <- n_groups * n_per_group data <- data.frame( group = factor(rep(1:n_groups, each = n_per_group)), x = rnorm(n_total), group_effect = rep(rnorm(n_groups, 0, 2), each = n_per_group) ) # Generate response with strong group effects data$y <- 2 + 0.5 * data$x + data$group_effect + rnorm(n_total, 0, 0.5) # Fit mixed-effects model fit_mixed <- qbrms(y ~ x + (1|group), data = data, family = gaussian()) # Compute Bayesian R-squared (should now match brms closely) r2_corrected <- bayes_R2(fit_mixed, verbose = TRUE) print(r2_corrected) # Should show high R-squared due to strong group effects ## End(Not run)
Specify Uniform Prior Distribution
uniform(min = -Inf, max = Inf)uniform(min = -Inf, max = Inf)
min |
Lower bound (default -Inf) |
max |
Upper bound (default Inf) |
A prior distribution object
Check if a family supports quantile regression with a given quantile value. Throws informative errors for invalid combinations.
validate_family_quantile(family_name, quantile)validate_family_quantile(family_name, quantile)
family_name |
Character string specifying the family name. |
quantile |
Numeric quantile value (or NULL). |
TRUE if the combination is valid (invisibly), throws error otherwise.
Extract Variance-Covariance Matrix from qbrms Models
## S3 method for class 'qbrms_fit' vcov(object, ...)## S3 method for class 'qbrms_fit' vcov(object, ...)
object |
A qbrms_fit object |
... |
Additional arguments (unused) |
Variance-covariance matrix
Variance-Covariance Matrix Method for TMB Ordinal Fits
## S3 method for class 'tmb_ordinal_qbrms_fit' vcov(object, ...)## S3 method for class 'tmb_ordinal_qbrms_fit' vcov(object, ...)
object |
A tmb_ordinal_qbrms_fit object |
... |
Additional arguments |
Variance-covariance matrix
Display HTML Table in Viewer
view_table(x)view_table(x)
x |
A |
Create visual representations of prior distributions to aid in prior specification and sensitivity analysis.
visualise_prior( prior, parameter = NULL, xlim = NULL, add_reference = TRUE, samples = 10000 )visualise_prior( prior, parameter = NULL, xlim = NULL, add_reference = TRUE, samples = 10000 )
prior |
Prior specification in qbrms format, or a list of prior specifications to compare |
parameter |
Character string specifying which parameter to visualise (e.g., "b", "sd", "sigma"). If NULL, visualises all priors. |
xlim |
Numeric vector of length 2 specifying x-axis limits. If NULL, automatically determined. |
add_reference |
Logical; if TRUE, adds reference distributions for comparison (default: TRUE) |
samples |
Number of samples to draw for visualisation (default: 10000) |
This function helps users:
Visualise the implications of their prior choices
Compare different prior specifications
Identify overly informative or vague priors
Understand prior-data conflict potential
Supported prior distributions include:
Normal: normal(mean, sd)
Student t: student_t(df, mean, scale)
Cauchy: cauchy(location, scale)
Exponential: exponential(rate)
Gamma: gamma(shape, rate)
Uniform: uniform(lower, upper)
A ggplot object showing the prior distribution(s)
## Not run: # Visualise a single prior prior <- prior(normal(0, 10), class = "b") visualise_prior(prior) # Compare different priors prior_list <- list( "Weak" = prior(normal(0, 10), class = "b"), "Medium" = prior(normal(0, 5), class = "b"), "Strong" = prior(normal(0, 1), class = "b") ) visualise_prior(prior_list) # Visualise with custom limits visualise_prior(prior, xlim = c(-20, 20)) ## End(Not run)## Not run: # Visualise a single prior prior <- prior(normal(0, 10), class = "b") visualise_prior(prior) # Compare different priors prior_list <- list( "Weak" = prior(normal(0, 10), class = "b"), "Medium" = prior(normal(0, 5), class = "b"), "Strong" = prior(normal(0, 1), class = "b") ) visualise_prior(prior_list) # Visualise with custom limits visualise_prior(prior, xlim = c(-20, 20)) ## End(Not run)
Weibull Survival Family
weibull(link = "log", link.shape = "log")weibull(link = "log", link.shape = "log")
link |
Link function for scale (default: "log") |
link.shape |
Link function for shape (default: "log") |
A family object of class "family".
Zero-Inflated Negative Binomial Family
zero_inflated_negbinomial(link = "log", link.zi = "logit") zinb(link = "log", link.zi = "logit")zero_inflated_negbinomial(link = "log", link.zi = "logit") zinb(link = "log", link.zi = "logit")
link |
Link function for mean (default: "log") |
link.zi |
Link function for zero-inflation (default: "logit") |
A family object of class "family".
Zero-Inflated Poisson Family
zero_inflated_poisson(link = "log", link.zi = "logit") zip()zero_inflated_poisson(link = "log", link.zi = "logit") zip()
link |
Link function for mean (default: "log") |
link.zi |
Link function for zero-inflation (default: "logit") |
A family object of class "family".