% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lrt_order_gau.R
\name{test_order_gau}
\alias{test_order_gau}
\title{Likelihood ratio test for antedependence order (Gaussian AD data)}
\usage{
test_order_gau(
  y,
  p = 0L,
  q = 1L,
  mu = NULL,
  use_modified = TRUE,
  order_null = NULL,
  order_alt = NULL
)
}
\arguments{
\item{y}{Numeric matrix with n_subjects rows and n_time columns.}

\item{p}{Order under the null hypothesis (default 0). This is the same
antedependence order parameter named \code{order} in \code{\link{fit_gau}}.}

\item{q}{Order increment under the alternative (default 1, so alternative is AD(p+q)).}

\item{mu}{Optional mean vector. If NULL, the saturated mean (sample means) is used.}

\item{use_modified}{Logical. If TRUE (default), use the modified test statistic
(formula 6.9) which has better small-sample properties.}

\item{order_null}{Optional alias for \code{p} (null order).}

\item{order_alt}{Optional absolute order under the alternative. When supplied,
\code{q} is computed as \code{order_alt - p}.}
}
\value{
A list with class \code{gau_order_test} containing:
\describe{
\item{method}{Inference method used (\code{"lrt"}).}
\item{p}{Order under null hypothesis}
\item{q}{Order increment}
\item{statistic}{Test statistic value}
\item{statistic_modified}{Modified test statistic (if use_modified = TRUE)}
\item{df}{Degrees of freedom}
\item{p_value}{P-value from chi-square distribution}
\item{p_value_modified}{P-value from modified test (if use_modified = TRUE)}
\item{n_subjects}{Number of subjects}
\item{n_time}{Number of time points}
}
}
\description{
Tests the null hypothesis that the data follow an AD(p) model against the
alternative that they follow an AD(p+q) model, using the likelihood ratio
test described in Theorem 6.4 and 6.5 of Zimmerman & Núñez-Antón (2009).
}
\details{
The test is based on the intervenor-adjusted sample partial correlations.
Under the null hypothesis AD(p), the partial correlations r_(i,i-k|(i-k+1:i-1))
should be zero for k > p.

The likelihood ratio test statistic (Theorem 6.4) is:
\deqn{-N \sum_{j=1}^{q} \sum_{i=p+j+1}^{n} \log(1 - r^2_{i,i-p-j\cdot(i-p-j+1:i-1)})}

which is asymptotically chi-square with (2n - 2p - q - 1)(q/2) degrees of freedom.

The modified test (formula 6.9) adjusts for small-sample bias using Kenward's
(1987) correction.
}
\examples{
\donttest{
# Simulate AD(1) data
y <- simulate_gau(n_subjects = 50, n_time = 6, order = 1, phi = 0.5)

# Test AD(0) vs AD(1)
test01 <- test_order_gau(y, p = 0, q = 1)
print(test01)

# Test AD(1) vs AD(2)
test12 <- test_order_gau(y, p = 1, q = 1)
print(test12)
}

}
\references{
Zimmerman, D.L. and Núñez-Antón, V. (2009). Antedependence Models for
Longitudinal Data. Chapman & Hall/CRC. Chapter 6.

Kenward, M.G. (1987). A method for comparing profiles of repeated measurements.
Applied Statistics, 36, 296-308.
}
\seealso{
\code{\link{test_one_sample_gau}}, \code{\link{test_homogeneity_gau}}
}
