R/wrappers_doc.R

#' Common Features and Arguments of RTMB Wrapper Functions
#'
#' @description
#' The RTMB wrapper functions (`rtmb_lm`, `rtmb_glm`, `rtmb_glmer`, `rtmb_fa`, etc.)
#' share a unified interface designed to make Bayesian and Frequentist inference
#' accessible through familiar R formulas and standard model specifications.
#'
#' @details
#' All wrapper functions in this package are built upon the same core engine.
#' This ensures that regardless of the model type, the workflow for estimation,
#' summary, and expansion remains consistent.
#'
#' \strong{1. Unified Inference Methods:}
#' Every model object returned by a wrapper function provides the following methods:
#' \itemize{
#'   \item \code{$classic()}: Performs standard frequentist estimation (MLE/REML) using `prior_flat()`. Supports robust standard errors and Satterthwaite/Between-Within degrees of freedom approximations.
#'   \item \code{$optimize()}: Performs Maximum A Posteriori (MAP) estimation (Empirical Bayes).
#'   \item \code{$sample()}: Performs MCMC sampling (NUTS via tmbstan) for full Bayesian inference.
#'   \item \code{$variational()}: Performs Variational Inference (ADVI) for fast posterior approximation.
#' }
#'
#' \strong{2. Prior API and Regularization:}
#' You can specify the prior distribution using the `prior` argument:
#' \itemize{
#'   \item \code{prior_flat()}: No additional prior (default). Required for \code{classic()} inference.
#'   \item \code{prior_normal()}: Manual normal/exponential priors for parameters.
#'   \item \code{prior_weak()}: Weakly informative priors based on \code{y_range}.
#'   \item \code{prior_rhs()}: Regularized Horseshoe prior for continuous shrinkage.
#'   \item \code{prior_ssp()}: Spike-and-Slab prior for sparse variable selection.
#' }
#' \emph{Note: When using `prior_weak()`, `prior_rhs()`, or `prior_ssp()`, you must specify \code{y_range = c(min, max)}
#' to let the model set appropriate global scales for the priors.}
#'
#' \strong{3. Model Comparison and Bayes Factors:}
#' Model comparison is performed exclusively via Bridge Sampling. To compare a full model 
#' against a nested null model, use the \code{$bayes_factor(fixed = list(...))} method on an 
#' MCMC fit object. For example, \code{fit$bayes_factor(fixed = list(b = 0))} tests the 
#' hypothesis that the fixed effect \code{b} is exactly zero.
#'
#' \strong{4. Standard Errors and Degrees of Freedom:}
#' The \code{$classic()} and \code{$optimize()} methods provide advanced summary options:
#' \itemize{
#'   \item \code{se_method}: Calculate `"robust"` (Huber-White) or `"cluster-robust"` standard errors by providing a cluster variable.
#'   \item \code{df_method}: Use `"satterthwaite"` for mixed models or `"bw"` (Between-Within) for multilevel correlation models to obtain accurate p-values and confidence intervals.
#' }
#'
#' \strong{5. Fixed parameters:}
#' Use \code{fixed = list(...)} during model construction to fix model parameters to specified values.
#' For example, \code{fixed = list(delta = 0)} fixes the parameter \code{delta} to zero.
#' This same syntax is used in \code{$bayes_factor()} to define the restricted model.
#'
#' @name rtmb_wrappers
#' @family wrappers
NULL

Try the BayesRTMB package in your browser

Any scripts or data that you put into this service are public.

BayesRTMB documentation built on Nov. 24, 2026, 9:06 a.m.