% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/RTMB_Model.R
\name{RTMB_Model-class}
\alias{RTMB_Model-class}
\alias{RTMB_Model}
\title{RTMB model object}
\description{
An R6 class representing a Bayesian model built with RTMB.
This class stores model components and provides methods for
building the automatic differentiation object, optimizing the
posterior, and drawing posterior samples.
}
\section{Public fields}{
\if{html}{\out{<div class="r6-fields">}}
\describe{
\item{\code{data}}{Named list containing observation data.}

\item{\code{par_list}}{Evaluated list of parameter definitions.}

\item{\code{log_prob}}{Executable function for likelihood and prior calculations.}

\item{\code{transform}}{Function for calculating transformed parameters.}

\item{\code{generate}}{Function for calculating generated quantities.}

\item{\code{par_names}}{List of variable names corresponding to parameter dimensions.}

\item{\code{pl_full}}{Complete parameter list with expanded constraints and dimension information used internally.}

\item{\code{formula}}{Formula used for model generation (if created via a wrapper function).}

\item{\code{requested_contrasts}}{Character; user-requested contrast setting (e.g. "treatment").}

\item{\code{contrasts}}{Character; internal contrast setting used for fitting (e.g. "sum").}

\item{\code{raw_data}}{Data frame; the original data used for the model.}

\item{\code{family}}{Character string of the distribution family (if created via a wrapper function).}

\item{\code{init}}{List or numeric vector of initial values.}

\item{\code{view}}{Character vector of variable names to prioritize in summary.}

\item{\code{code}}{Original model AST generated by `rtmb_code()`.}

\item{\code{map}}{A list specifying parameter mappings for fixing values (e.g., via \code{fixed_model()}).}

\item{\code{prior_correction}}{Numeric value for legacy or low-level marginal-likelihood correction.
Fixed-parameter prior removal is handled during AD objective construction.}

\item{\code{fixed_prior_specs}}{Internal specification for removing fixed-parameter prior contributions during AD evaluation.}

\item{\code{type}}{Character; the type of the model (e.g. 'lmer', 'glm', 'table', 'ttest', 'corr', 'mediation').}

\item{\code{extra}}{List; used to store auxiliary data (like term assignments, factors, test results) needed by methods such as classic().}
}
\if{html}{\out{</div>}}
}
\section{Methods}{
\subsection{Public methods}{
\itemize{
\item \href{#method-RTMB_Model-new}{\code{RTMB_Model$new()}}
\item \href{#method-RTMB_Model-prepare_init}{\code{RTMB_Model$prepare_init()}}
\item \href{#method-RTMB_Model-get_par_list}{\code{RTMB_Model$get_par_list()}}
\item \href{#method-RTMB_Model-get_ad_obj}{\code{RTMB_Model$get_ad_obj()}}
\item \href{#method-RTMB_Model-to_unconstrained}{\code{RTMB_Model$to_unconstrained()}}
\item \href{#method-RTMB_Model-to_constrained}{\code{RTMB_Model$to_constrained()}}
\item \href{#method-RTMB_Model-unconstrained_vector_to_list}{\code{RTMB_Model$unconstrained_vector_to_list()}}
\item \href{#method-RTMB_Model-constrained_vector_to_list}{\code{RTMB_Model$constrained_vector_to_list()}}
\item \href{#method-RTMB_Model-calculate_satterthwaite_df}{\code{RTMB_Model$calculate_satterthwaite_df()}}
\item \href{#method-RTMB_Model-calculate_reml_satterthwaite_df}{\code{RTMB_Model$calculate_reml_satterthwaite_df()}}
\item \href{#method-RTMB_Model-build_ad_obj}{\code{RTMB_Model$build_ad_obj()}}
\item \href{#method-RTMB_Model-optimize}{\code{RTMB_Model$optimize()}}
\item \href{#method-RTMB_Model-classic}{\code{RTMB_Model$classic()}}
\item \href{#method-RTMB_Model-sample}{\code{RTMB_Model$sample()}}
\item \href{#method-RTMB_Model-variational}{\code{RTMB_Model$variational()}}
\item \href{#method-RTMB_Model-print_code}{\code{RTMB_Model$print_code()}}
\item \href{#method-RTMB_Model-print_log_prob}{\code{RTMB_Model$print_log_prob()}}
\item \href{#method-RTMB_Model-print_transform}{\code{RTMB_Model$print_transform()}}
\item \href{#method-RTMB_Model-print_generate}{\code{RTMB_Model$print_generate()}}
\item \href{#method-RTMB_Model-get_n_obs}{\code{RTMB_Model$get_n_obs()}}
\item \href{#method-RTMB_Model-fixed_model}{\code{RTMB_Model$fixed_model()}}
\item \href{#method-RTMB_Model-clone}{\code{RTMB_Model$clone()}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-new"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-new}{}}}
\subsection{Method \code{new()}}{
Create a new `RTMB_Model` object.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$new(
  data,
  par_list,
  log_prob,
  transform = NULL,
  generate = NULL,
  par_names = NULL,
  init = NULL,
  view = NULL,
  code = NULL
)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{data}}{Named list containing observation data.}

\item{\code{par_list}}{Evaluated list of parameter definitions.}

\item{\code{log_prob}}{Executable function for likelihood and prior calculations.}

\item{\code{transform}}{Function for calculating transformed parameters (optional).}

\item{\code{generate}}{Function for calculating generated quantities (optional).}

\item{\code{par_names}}{List of variable names corresponding to parameter dimensions.}

\item{\code{init}}{List or numeric vector of initial values.}

\item{\code{view}}{Character vector of variable names to prioritize in summary.}

\item{\code{code}}{Original model AST generated by `rtmb_code()`.}
}
\if{html}{\out{</div>}}
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-prepare_init"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-prepare_init}{}}}
\subsection{Method \code{prepare_init()}}{
Prepare and format initial values for the model parameters.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$prepare_init(init_arg)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{init_arg}}{Optional list or numeric vector of initial values. If NULL, defaults to `self$init` or random generation.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A flat numeric vector of constrained initial values.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-get_par_list"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-get_par_list}{}}}
\subsection{Method \code{get_par_list()}}{
Get the current parameters as a named list.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$get_par_list(init = NULL)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{init}}{Optional numeric vector or list of initial values. If NULL, uses the model's current initial values.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A named list of constrained parameters.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-get_ad_obj"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-get_ad_obj}{}}}
\subsection{Method \code{get_ad_obj()}}{
Get the RTMB automatic differentiation object.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$get_ad_obj(...)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{...}}{Arguments passed to \code{build_ad_obj}.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A TMB objective object (ad_obj).
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-to_unconstrained"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-to_unconstrained}{}}}
\subsection{Method \code{to_unconstrained()}}{
Convert a list of constrained parameters to unconstrained space.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$to_unconstrained(par_list_constrained)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{par_list_constrained}}{A named list of parameters in their natural space.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A named list of parameters in unconstrained space.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-to_constrained"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-to_constrained}{}}}
\subsection{Method \code{to_constrained()}}{
Convert a list of unconstrained parameters to constrained (natural) space.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$to_constrained(par_list_unconstrained)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{par_list_unconstrained}}{A named list of parameters in unconstrained space.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A named list of parameters in constrained space.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-unconstrained_vector_to_list"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-unconstrained_vector_to_list}{}}}
\subsection{Method \code{unconstrained_vector_to_list()}}{
Convert a flat unconstrained vector to a named list.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$unconstrained_vector_to_list(vec)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{vec}}{A numeric vector in unconstrained space.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A named list of unconstrained parameters.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-constrained_vector_to_list"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-constrained_vector_to_list}{}}}
\subsection{Method \code{constrained_vector_to_list()}}{
Convert a flat constrained vector to a named list.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$constrained_vector_to_list(vec)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{vec}}{A numeric vector in constrained space.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A named list of constrained parameters.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-calculate_satterthwaite_df"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-calculate_satterthwaite_df}{}}}
\subsection{Method \code{calculate_satterthwaite_df()}}{
Calculate Satterthwaite degrees of freedom for parameters.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$calculate_satterthwaite_df(
  ad_obj,
  idx_fix_active = NULL,
  L_u_total = NULL,
  opt_par = NULL,
  max_df = NULL,
  silent = FALSE,
  return_sensitivities = FALSE
)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{ad_obj}}{An RTMB objective object at the optimum.}

\item{\code{idx_fix_active}}{Integer vector; indices of active fixed parameters in the full unconstrained vector.}

\item{\code{L_u_total}}{Integer; total length of the full unconstrained parameter vector.}

\item{\code{opt_par}}{Optional numeric vector of optimized parameters.}

\item{\code{max_df}}{Numeric; maximum allowed degrees of freedom. Default is NULL.}

\item{\code{silent}}{Logical; whether to suppress informational messages. Default is FALSE.}

\item{\code{return_sensitivities}}{Logical; if TRUE, returns Hessian sensitivities and V for delta method.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A numeric vector of estimated degrees of freedom (length = L_u_total). Inf for random effects.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-calculate_reml_satterthwaite_df"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-calculate_reml_satterthwaite_df}{}}}
\subsection{Method \code{calculate_reml_satterthwaite_df()}}{
Calculate Satterthwaite degrees of freedom for integrated fixed effects (REML).
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$calculate_reml_satterthwaite_df(
  ad_obj,
  opt_par,
  beta_idx,
  max_df = NULL,
  silent = FALSE,
  return_sensitivities = FALSE
)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{ad_obj}}{An RTMB objective object.}

\item{\code{opt_par}}{Numeric vector of optimized variance components.}

\item{\code{beta_idx}}{Integer vector; indices of fixed effects within the random effects vector.}

\item{\code{max_df}}{Numeric; maximum allowed degrees of freedom. Default is NULL.}

\item{\code{silent}}{Logical; whether to suppress informational messages. Default is FALSE.}

\item{\code{return_sensitivities}}{Logical; if TRUE, returns Hessian sensitivities and delta-method components.}

\item{\code{...}}{Additional arguments.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A numeric vector of estimated degrees of freedom for the fixed effects.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-build_ad_obj"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-build_ad_obj}{}}}
\subsection{Method \code{build_ad_obj()}}{
Build the RTMB automatic differentiation object.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$build_ad_obj(
  init = NULL,
  laplace = FALSE,
  jacobian_target = "none",
  map = NULL,
  .marginal_vars = NULL
)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{init}}{Optional numeric vector or list of initial values for the parameters. Default is NULL.}

\item{\code{laplace}}{Logical; whether to use Laplace approximation to marginalize random effects. Default is FALSE.}

\item{\code{jacobian_target}}{Character string specifying which parameters to apply Jacobian adjustments to:
\itemize{
  \item \code{"all"}: Apply to all parameters (standard for Bayesian MCMC).
  \item \code{"random"}: Apply only to parameters with \code{random = TRUE} (standard for Laplace approximation/REML).
  \item \code{"none"}: No Jacobian adjustment (standard for Maximum Likelihood estimation).
}
Default is "none".}

\item{\code{map}}{Optional list specifying parameters to fix. Passed directly to MakeADFun. Default is NULL.}

\item{\code{.marginal_vars}}{Internal use for profiling marginalized parameters.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
An RTMB objective object (ad_obj).
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-optimize"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-optimize}{}}}
\subsection{Method \code{optimize()}}{
Perform Maximum Likelihood or Maximum A Posteriori (MAP) estimation.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$optimize(
  laplace = TRUE,
  init = NULL,
  num_estimate = 1,
  control = list(),
  optimizer = "nlminb",
  method = "BFGS",
  map = NULL,
  fixed = NULL,
  se_method = c("wald", "sampling", "none"),
  num_samples = 1000,
  seed = 123,
  marginal = "none",
  df_method = "auto",
  view = NULL,
  ...
)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{laplace}}{Logical; whether to use Laplace approximation for random effects. Default is TRUE.}

\item{\code{init}}{Optional initial values for parameters (numeric vector or list).}

\item{\code{num_estimate}}{Integer; Number of multi-start optimization runs. Default is 1.}

\item{\code{control}}{A list of control settings passed to the optimizer.}

\item{\code{optimizer}}{Character; The optimizer to use: "nlminb" (default) or "optim".}

\item{\code{method}}{Character; The method for "optim" (e.g., "BFGS", "L-BFGS-B").}

\item{\code{map}}{Optional list specifying parameters to fix (factors).}

\item{\code{fixed}}{Optional list specifying parameter values to fix.}

\item{\code{se_method}}{Character; method for uncertainty estimation.
\itemize{
  \item \code{"wald"}: Wald standard errors and Wald confidence intervals.
  \item \code{"sampling"}: Simulation-based error propagation.
  \item \code{"none"}: Do not compute standard errors, confidence intervals, or degrees of freedom.
}}

\item{\code{num_samples}}{Integer; number of samples to draw when se_method is "sampling". Default is 1000.}

\item{\code{seed}}{Integer; random seed for sampling.}

\item{\code{marginal}}{Character vector or "auto" or "none"; specifies which parameters to marginalize out via Laplace approximation.
\itemize{
  \item \code{"none"} (default): No additional marginalization.
  \item \code{"auto"}: Uses variables specified by the model wrapper (e.g., fixed effects in lmer).
  \item \code{"all"}: Marginalize all parameters (advanced use).
  \item \code{character vector}: Specific parameter names to marginalize.
}}

\item{\code{df_method}}{Character or numeric; method for finite degrees-of-freedom approximation.
Used only when `marginal` resolves to one or more parameters and `se_method != "none"`.
\itemize{
  \item \code{"auto"}: Uses Satterthwaite approximation when marginalization is active.
  \item \code{"satterthwaite"}: Satterthwaite approximation.
  \item \code{"inf"} or \code{"none"}: Use infinite degrees of freedom.
  \item numeric: Use the supplied fixed degrees of freedom.
}}

\item{\code{view}}{Character vector of parameter names to prioritize in summary display.}

\item{\code{...}}{Additional arguments.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A fitted `MAP_Fit` object.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-classic"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-classic}{}}}
\subsection{Method \code{classic()}}{
Perform frequentist inference (REML/ML) with model-appropriate degrees of freedom.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$classic(
  df_method = "auto",
  se_method = c("wald", "sampling"),
  num_samples = 1000,
  seed = 123,
  view = NULL,
  map = NULL,
  fixed = NULL,
  ...
)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{df_method}}{Character; Method for calculating degrees of freedom. Default is "auto".
\itemize{
  \item \code{"auto"}: Determined based on model type (e.g., Satterthwaite for mixed models).
  \item \code{"residual"}: Residual degrees of freedom.
  \item \code{"satterthwaite"}: Satterthwaite approximation (robust for mixed models).
  \item \code{"inf"}: Use z-distribution (infinite degrees of freedom).
}}

\item{\code{se_method}}{Character; The method for CI estimation: "wald" (default) or "sampling".}

\item{\code{num_samples}}{Integer; number of samples to draw when se_method is "sampling". Default is 1000.}

\item{\code{seed}}{Integer; random seed for sampling.}

\item{\code{view}}{Character vector of parameters to prioritize in the summary output.}

\item{\code{map}}{Optional list specifying parameters to fix.}

\item{\code{fixed}}{Optional list specifying parameter values to fix.}

\item{\code{...}}{Additional arguments.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A `Classic_Fit` object.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-sample"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-sample}{}}}
\subsection{Method \code{sample()}}{
Draw posterior samples from the model.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$sample(
  sampling = 1000,
  warmup = 1000,
  chains = 4,
  thin = 1,
  seed = sample.int(1e+06, 1),
  delta = 0.8,
  max_treedepth = 10,
  parallel = FALSE,
  laplace = FALSE,
  init = NULL,
  init_jitter = 0.1,
  save_csv = NULL,
  map = NULL,
  fixed = NULL
)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{sampling}}{Number of sampling iterations. Default is 1000.}

\item{\code{warmup}}{Number of warmup iterations. Default is 1000.}

\item{\code{chains}}{Number of MCMC chains. Default is 4.}

\item{\code{thin}}{Thinning interval. Default is 1.}

\item{\code{seed}}{Random seed.}

\item{\code{delta}}{Target acceptance rate for HMC/NUTS. Default is 0.8.}

\item{\code{max_treedepth}}{Maximum tree depth for HMC/NUTS. Default is 10.}

\item{\code{parallel}}{Logical; whether to run chains in parallel. Default is FALSE.}

\item{\code{laplace}}{Logical; whether to use Laplace approximation. Default is FALSE.}

\item{\code{init}}{Optional initial values for parameters.}

\item{\code{init_jitter}}{sd of randomize initial values for parameters.}

\item{\code{save_csv}}{Optional list for saving MCMC results. e.g., list(name = "model", dir = "BayesRTMB_mcmc").}

\item{\code{map}}{Optional list specifying parameters to fix (factors).}

\item{\code{fixed}}{Optional list specifying parameter values to fix.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A fitted `MCMC_Fit` object.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-variational"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-variational}{}}}
\subsection{Method \code{variational()}}{
Run Automatic Differentiation Variational Inference (ADVI).
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$variational(
  iter = 3000,
  tol_rel_obj = 0.005,
  window_size = 100,
  num_samples = 1000,
  num_estimate = 4,
  alpha = 0.01,
  laplace = FALSE,
  print_freq = 1000,
  method = c("meanfield", "fullrank", "hybrid"),
  parallel = FALSE,
  seed = sample.int(1e+06, 1),
  init = NULL,
  save_csv = NULL,
  map = NULL,
  fixed = NULL
)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{iter}}{Integer; fixed number of iterations for the optimization. Default is 3000.}

\item{\code{tol_rel_obj}}{Numeric; relative tolerance for the ELBO change to determine convergence. Default is 0.005.}

\item{\code{window_size}}{Integer; window size for median smoothing in the convergence check. Default is 100.}

\item{\code{num_samples}}{Integer; number of posterior samples to generate from the fitted variational distribution. Default is 1000.}

\item{\code{num_estimate}}{Integer; number of times to run the VB estimation (treated as chains). Default is 4.}

\item{\code{alpha}}{Numeric; learning rate for the Adam optimizer. Default is 0.01.}

\item{\code{laplace}}{Logical; whether to use Laplace approximation to marginalize random effects. Default is FALSE.}

\item{\code{print_freq}}{Integer; iterations interval for progress output. Set to 0 to disable. Default is 1000.}

\item{\code{method}}{Character; method of Variational Inference. Default is "meanfield".}

\item{\code{parallel}}{Logical; whether to run estimations in parallel. Default is FALSE.}

\item{\code{seed}}{Integer; random seed for reproducibility.}

\item{\code{init}}{Optional numeric vector or list for initial parameter values. Default is NULL.}

\item{\code{save_csv}}{Optional list for saving VB results. e.g., list(name = "model", dir = "BayesRTMB_vb").}

\item{\code{map}}{Optional list specifying parameters to fix (factors).}

\item{\code{fixed}}{Optional list specifying parameter values to fix.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A fitted `VB_Fit` object containing posterior samples and diagnostic information.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-print_code"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-print_code}{}}}
\subsection{Method \code{print_code()}}{
Print model code or model structure.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$print_code()}\if{html}{\out{</div>}}
}

\subsection{Returns}{
The object itself, invisibly.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-print_log_prob"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-print_log_prob}{}}}
\subsection{Method \code{print_log_prob()}}{
Print the internal log-probability function.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$print_log_prob()}\if{html}{\out{</div>}}
}

\subsection{Returns}{
The object itself, invisibly.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-print_transform"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-print_transform}{}}}
\subsection{Method \code{print_transform()}}{
Print the internal transformation function.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$print_transform()}\if{html}{\out{</div>}}
}

\subsection{Returns}{
The object itself, invisibly.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-print_generate"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-print_generate}{}}}
\subsection{Method \code{print_generate()}}{
Print the internal generation function.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$print_generate()}\if{html}{\out{</div>}}
}

\subsection{Returns}{
The object itself, invisibly.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-get_n_obs"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-get_n_obs}{}}}
\subsection{Method \code{get_n_obs()}}{
Automatically detect and count the number of independent data points (observations).
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$get_n_obs()}\if{html}{\out{</div>}}
}

\subsection{Returns}{
Integer; total number of observations, or NULL if model code is missing.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-fixed_model"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-fixed_model}{}}}
\subsection{Method \code{fixed_model()}}{
Create a model with fixed parameters.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$fixed_model(fixed = list(), silent = FALSE)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{fixed}}{A named list of parameter values to fix.}

\item{\code{silent}}{Logical; whether to suppress informational messages. Default is FALSE.}
}
\if{html}{\out{</div>}}
}
\subsection{Returns}{
A new RTMB_Model object.
}
}
\if{html}{\out{<hr>}}
\if{html}{\out{<a id="method-RTMB_Model-clone"></a>}}
\if{latex}{\out{\hypertarget{method-RTMB_Model-clone}{}}}
\subsection{Method \code{clone()}}{
The objects of this class are cloneable with this method.
\subsection{Usage}{
\if{html}{\out{<div class="r">}}\preformatted{RTMB_Model$clone(deep = FALSE)}\if{html}{\out{</div>}}
}

\subsection{Arguments}{
\if{html}{\out{<div class="arguments">}}
\describe{
\item{\code{deep}}{Whether to make a deep clone.}
}
\if{html}{\out{</div>}}
}
}
}
