% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/wrapper_loglinear.R
\name{rtmb_loglinear}
\alias{rtmb_loglinear}
\title{RTMB-based Log-linear analysis (Poisson regression)}
\usage{
rtmb_loglinear(
  formula,
  data,
  prior = prior_flat(),
  fixed = NULL,
  WAIC = FALSE,
  ...
)
}
\arguments{
\item{formula}{A formula (e.g., `~ A + B + A:B`) or a contingency table.}

\item{data}{A data frame (required if `formula` is used).}

\item{prior}{An object of class "rtmb_prior" specifying the prior distribution.}

\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_glm()`.}
}
\value{
An `RTMB_Model` object.
}
\description{
Performs Bayesian or Frequentist log-linear analysis (Poisson regression)
on a contingency table or raw data.
}
\examples{

  # Create a contingency table
  tab <- matrix(c(10, 20, 30, 40), nrow = 2)
  dimnames(tab) <- list(A = c("A1", "A2"), B = c("B1", "B2"))
  
  # Fit a log-linear model (independence model: ~ A + B)
  fit_log <- rtmb_loglinear(~ A + B, data = tab)
  
  # MAP estimation
  map_log <- fit_log$optimize()
  map_log$summary()
}
