Skip to contents

Tests whether transition probabilities are constant over time in a categorical antedependence model.

Usage

test_timeinvariance_cat(
  y,
  order = 1,
  blocks = NULL,
  homogeneous = TRUE,
  n_categories = NULL,
  test = c("lrt", "score", "mlrt")
)

Arguments

y

Integer matrix with n_subjects rows and n_time columns. Each entry should be a category code from 1 to c.

order

Antedependence order p. Default is 1.

blocks

Optional integer vector of length n_subjects specifying group membership.

homogeneous

Logical. If TRUE (default), parameters are shared across all groups.

n_categories

Number of categories. If NULL, inferred from data.

test

Type of test statistic. One of "lrt" (default), "score", or "mlrt".

Value

A list of class "cat_lrt" containing:

method

Inference method used: one of "lrt", "score", "mlrt", or "wald".

lrt_stat

Likelihood ratio test statistic

df

Degrees of freedom

p_value

P-value from chi-square distribution

fit_null

Fitted time-invariant model (H0)

fit_alt

Fitted time-varying model (H1)

table

Summary data frame

Details

The null hypothesis is that all transition probabilities (for k > p) are equal across time: $$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: $$df = (c-1) \times c^p \times (n - p - 1)$$

This function currently supports complete data only. If y contains missing values, use model-fitting functions (for example fit_cat) directly with missing-data handling instead of this test wrapper.

References

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

Examples

if (FALSE) { # \dontrun{
# 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)
} # }