% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/loglik_cat.R
\name{logL_cat}
\alias{logL_cat}
\title{Log-likelihood for categorical AD models (with missing data support)}
\usage{
logL_cat(
  y,
  order,
  marginal,
  transition = NULL,
  blocks = NULL,
  homogeneous = TRUE,
  n_categories = NULL,
  na_action = c("fail", "complete", "marginalize")
)
}
\arguments{
\item{y}{Integer matrix with n_subjects rows and n_time columns. Each entry
should be a category code from 1 to c.}

\item{order}{Antedependence order p. Must be 0, 1, or 2.}

\item{marginal}{List of marginal/joint probabilities for initial time points.
Structure depends on order (see Details).}

\item{transition}{List of transition probability arrays for time points
k = p+1 to n. Each element should be an array of dimension c^p x c where
the last dimension corresponds to the current time point.}

\item{blocks}{Optional integer vector of length n_subjects specifying group
membership. Required if homogeneous = FALSE.}

\item{homogeneous}{Logical. If TRUE (default), same parameters used for all
subjects. If FALSE, marginal and transition should be lists indexed by block.}

\item{n_categories}{Number of categories. If NULL, inferred from data.}

\item{na_action}{Handling of missing values in \code{y}. One of
\code{"fail"} (default, error if any missing), \code{"complete"}
(drop subjects with any missing values), or \code{"marginalize"}
(integrate over missing categorical outcomes under the AD model).}
}
\value{
Scalar log-likelihood value.
}
\description{
Evaluates the log-likelihood of an AD(p) model for categorical longitudinal
data at given parameter values.
}
\details{
The log-likelihood for AD(p) decomposes into contributions from initial
time points and transition time points.

For order 0 (independence), the log-likelihood is the sum of log marginal
probabilities at each time point.

Parameter structure for marginal:
\itemize{
\item Order 0: List with elements t1, t2, ..., tn, each a vector of length c
\item Order 1: List with element t1 (vector of length c)
\item Order 2: List with t1 (vector), t2_given_1to1 (c x c matrix)
}

Parameter structure for transition:
\itemize{
\item Order 0: Not used (NULL or empty list)
\item Order 1: List with elements t2, t3, ..., tn, each c x c matrix
\item Order 2: List with elements t3, t4, ..., tn, each c x c x c array
}
}
\examples{
set.seed(1)
y <- simulate_cat(n_subjects = 40, n_time = 5, order = 1, n_categories = 3)
fit <- fit_cat(y, order = 1, n_categories = 3)
logL_cat(
  y = y,
  order = 1,
  marginal = fit$marginal,
  transition = fit$transition,
  n_categories = 3
)

}
\references{
Xie, Y. and Zimmerman, D. L. (2013). Antedependence models for nonstationary
categorical longitudinal data with ignorable missingness: likelihood-based
inference. \emph{Statistics in Medicine}, 32, 3274-3289.
}
