% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/wrapper_mixture.R
\name{rtmb_mixture}
\alias{rtmb_mixture}
\title{Mixture Model Wrapper for RTMB}
\usage{
rtmb_mixture(
  formula,
  k = 2,
  data = NULL,
  covariance = c("diagonal", "diagonal_equal", "full", "full_equal", "full_equal_corr"),
  prior = prior_flat(),
  y_range = NULL,
  fixed = NULL,
  WAIC = FALSE,
  ...
)
}
\arguments{
\item{formula}{A formula specifying the response variable(s). For multivariate, use \code{cbind(y1, y2) ~ 1}.}

\item{k}{Number of mixture components.}

\item{data}{A data frame containing the variables in the model.}

\item{covariance}{Covariance structure: "diagonal" (default), "diagonal_equal", "full", "full_equal", or "full_equal_corr".}

\item{prior}{Prior configuration: `prior_flat()`, `prior_normal()`,
`prior_weak()`, `prior_rhs()`, or `prior_ssp()`. Default is
`prior_flat()`. If `y_range` is supplied with the default flat prior,
the wrapper automatically switches to `prior_weak()`.}

\item{y_range}{Optional numeric vector or matrix defining the theoretical range (min, max) of response variables.
Specifying this automatically enables weakly informative priors if `prior` is `prior_flat()`.}

\item{fixed}{Optional named list of fixed values for specific parameters.}

\item{WAIC}{Logical; if TRUE, add pointwise `log_lik` to the generate block for WAIC.}

\item{...}{Additional arguments passed to `rtmb_model`.}
}
\value{
A \code{RTMB_Model} object.
}
\description{
Provides a user-friendly interface for fitting Gaussian mixture models
with optional covariates on class membership probabilities and various
covariance structures.
}
\examples{

  # Simulate 1D mixture data (2 components)
  set.seed(123)
  N <- 100
  group <- rbinom(N, 1, 0.4)
  y <- ifelse(group == 1, rnorm(N, 5, 1), rnorm(N, 0, 1))
  dat <- data.frame(y)

  # Fit a 1D Gaussian mixture model with 2 components
  fit_mix <- rtmb_mixture(y ~ 1, k = 2, data = dat)
  
  # MAP estimation
  map_mix <- fit_mix$optimize()
  map_mix$summary()
}
