View source: R/lrt_homogeneity_cat.R
| test_homogeneity_cat | R Documentation |
Tests whether multiple groups share the same transition probability parameters in a categorical antedependence model.
test_homogeneity_cat(
y = NULL,
blocks = NULL,
order = 1,
n_categories = NULL,
fit_null = NULL,
fit_alt = 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. Can be NULL if both fit_null and fit_alt are provided. |
blocks |
Integer vector of length n_subjects specifying group membership. Required unless pre-fitted models are provided. |
order |
Antedependence order p. Default is 1. |
n_categories |
Number of categories. If NULL, inferred from data. |
fit_null |
Optional pre-fitted homogeneous model (class "cat_fit" with homogeneous = TRUE). If provided, y is not required for fitting under H0. |
fit_alt |
Optional pre-fitted heterogeneous model (class "cat_fit" with homogeneous = FALSE). If provided, y is not required for fitting under H1. |
test |
Type of test statistic. One of |
The null hypothesis is that all G groups share the same transition probability parameters:
H_0: \pi^{(1)} = \pi^{(2)} = \ldots = \pi^{(G)}
The alternative hypothesis allows each group to have its own parameters.
The degrees of freedom are:
df = (G-1) \times k
where G is the number of groups and k is the number of free parameters per population.
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 homogeneous model (H0)
Fitted heterogeneous model (H1)
Number of groups
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 different transition probabilities for two groups
set.seed(123)
marg1 <- list(t1 = c(0.7, 0.3))
marg2 <- list(t1 = c(0.4, 0.6))
trans1 <- list(t2 = matrix(c(0.9, 0.1, 0.2, 0.8), 2, byrow = TRUE),
t3 = matrix(c(0.9, 0.1, 0.2, 0.8), 2, byrow = TRUE))
trans2 <- list(t2 = matrix(c(0.5, 0.5, 0.5, 0.5), 2, byrow = TRUE),
t3 = matrix(c(0.5, 0.5, 0.5, 0.5), 2, byrow = TRUE))
y1 <- simulate_cat(100, 3, order = 1, n_categories = 2,
marginal = marg1, transition = trans1)
y2 <- simulate_cat(100, 3, order = 1, n_categories = 2,
marginal = marg2, transition = trans2)
y <- rbind(y1, y2)
blocks <- c(rep(1, 100), rep(2, 100))
# Test homogeneity
test <- test_homogeneity_cat(y, blocks, order = 1)
print(test)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.