% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lrt_order_inad.R
\name{test_order_inad}
\alias{test_order_inad}
\title{Likelihood ratio test for antedependence order (INAD data)}
\usage{
test_order_inad(
  y,
  order_null = 0,
  order_alt = 1,
  thinning = "binom",
  innovation = "pois",
  blocks = NULL,
  use_chibar = TRUE,
  weights = NULL,
  fit_null = NULL,
  fit_alt = NULL,
  ...
)
}
\arguments{
\item{y}{Integer matrix with n_subjects rows and n_time columns.}

\item{order_null}{Order under null hypothesis (0 or 1).}

\item{order_alt}{Order under alternative hypothesis (1 or 2). Must be order_null + 1.}

\item{thinning}{Thinning operator: "binom", "pois", or "nbinom".}

\item{innovation}{Innovation distribution: "pois", "bell", or "nbinom".}

\item{blocks}{Optional integer vector for block effects.}

\item{use_chibar}{Logical; if TRUE, use chi-bar-square for boundary test.}

\item{weights}{Optional weights for chi-bar-square mixture.}

\item{fit_null}{Optional pre-computed null fit.}

\item{fit_alt}{Optional pre-computed alternative fit.}

\item{...}{Additional arguments passed to fit_inad.}
}
\value{
A list with class \code{"test_order_inad"} containing:
\describe{
\item{method}{Inference method used (\code{"lrt"}).}
\item{fit_null}{Fitted model under H0}
\item{fit_alt}{Fitted model under H1}
\item{statistic}{Test statistic value}
\item{lrt_stat}{Likelihood ratio test statistic}
\item{df}{Degrees of freedom}
\item{p_value}{Chi-square p-value}
\item{p_value_chibar}{Chi-bar-square p-value (if \code{use_chibar = TRUE})}
\item{bic_null}{BIC under H0}
\item{bic_alt}{BIC under H1}
\item{bic_selected}{Which model BIC prefers}
\item{table}{Two-row model comparison table}
\item{settings}{Input and derived settings for the test}
}
}
\description{
Performs a likelihood ratio test comparing INAD models of different orders.
}
\details{
The test compares nested INAD models of orders \code{order_null} and
\code{order_alt = order_null + 1} using:
\deqn{\lambda = 2(\ell_{alt} - \ell_{null})}
where \eqn{\ell_{null}} and \eqn{\ell_{alt}} are maximized log-likelihoods
under the null and alternative models.

The default p-value uses the chi-square approximation with degrees of freedom
matching the number of additional dependence parameters introduced under the
higher-order model. When \code{use_chibar = TRUE}, a chi-bar-square mixture
p-value is also reported for boundary-aware inference.

Missing-data inputs are supported through the same \code{na_action} options
available in \code{\link{fit_inad}}. If \code{y} has missing values and
\code{na_action} is not supplied via \code{...}, this function defaults to
\code{na_action = "marginalize"}.
}
\examples{
set.seed(1)
y <- simulate_inad(
  n_subjects = 40,
  n_time = 5,
  order = 1,
  thinning = "binom",
  innovation = "pois",
  alpha = 0.3,
  theta = 2
)
out <- test_order_inad(
  y,
  order_null = 0,
  order_alt = 1,
  thinning = "binom",
  innovation = "pois",
  max_iter = 20
)
out$statistic
}
\references{
Li, C. and Zimmerman, D.L. (2026). Integer-valued antedependence models for
longitudinal count data. \emph{Biostatistics}.
}
\seealso{
\code{\link{fit_inad}}, \code{\link{bic_order_inad}},
\code{\link{test_stationarity_inad}}
}
