View source: R/lrt_homogeneity_cat.R
| test_timeinvariance_cat | R Documentation |
Tests whether transition probabilities are constant over time in a categorical antedependence model.
test_timeinvariance_cat(
y,
order = 1,
blocks = NULL,
homogeneous = TRUE,
n_categories = NULL,
test = c("lrt", "score", "mlrt")
)
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 |
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.
A list of class "cat_lrt" containing:
Inference method used: one of "lrt", "score",
"mlrt", or "wald".
Likelihood ratio test statistic
Degrees of freedom
P-value from chi-square distribution
Fitted time-invariant model (H0)
Fitted time-varying model (H1)
Summary data frame
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.
fit_cat, test_order_cat
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.