% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lrt_homogeneity_cat.R
\name{test_timeinvariance_cat}
\alias{test_timeinvariance_cat}
\title{Likelihood ratio test for time-invariance (categorical data)}
\usage{
test_timeinvariance_cat(
  y,
  order = 1,
  blocks = NULL,
  homogeneous = TRUE,
  n_categories = NULL,
  test = c("lrt", "score", "mlrt")
)
}
\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. Default is 1.}

\item{blocks}{Optional integer vector of length n_subjects specifying group
membership.}

\item{homogeneous}{Logical. If TRUE (default), parameters are shared across
all groups.}

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

\item{test}{Type of test statistic. One of \code{"lrt"} (default),
\code{"score"}, or \code{"mlrt"}.}
}
\value{
A list of class \code{"cat_lrt"} containing:
\describe{
\item{method}{Inference method used: one of \code{"lrt"}, \code{"score"},
\code{"mlrt"}, or \code{"wald"}.}
\item{lrt_stat}{Likelihood ratio test statistic}
\item{df}{Degrees of freedom}
\item{p_value}{P-value from chi-square distribution}
\item{fit_null}{Fitted time-invariant model (H0)}
\item{fit_alt}{Fitted time-varying model (H1)}
\item{table}{Summary data frame}
}
}
\description{
Tests whether transition probabilities are constant over time in a
categorical antedependence model.
}
\details{
The null hypothesis is that all transition probabilities (for k > p) are
equal across time:
\deqn{H_0: \pi_{y_k | y_{k-p}, \ldots, y_{k-1}} \text{ is constant for } k = p+1, \ldots, n}

This reduces (n-p) separate transition matrices/arrays to a single one.

The degrees of freedom are:
\deqn{df = (c-1) \times c^p \times (n - p - 1)}

This function currently supports complete data only. If \code{y} contains
missing values, use model-fitting functions (for example \code{fit_cat})
directly with missing-data handling instead of this test wrapper.
}
\examples{
\donttest{
# Simulate data with time-invariant transitions
set.seed(123)
y <- simulate_cat(200, 6, order = 1, n_categories = 2)

# Test time-invariance
test <- test_timeinvariance_cat(y, order = 1)
print(test)
}

}
\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.
}
\seealso{
\code{\link{fit_cat}}, \code{\link{test_order_cat}}
}
