Skip to contents

Evaluates the log-likelihood of an AD(p) model for categorical longitudinal data at given parameter values.

Usage

logL_cat(
  y,
  order,
  marginal,
  transition = NULL,
  blocks = NULL,
  homogeneous = TRUE,
  n_categories = NULL,
  na_action = c("fail", "complete", "marginalize")
)

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. Must be 0, 1, or 2.

marginal

List of marginal/joint probabilities for initial time points. Structure depends on order (see Details).

transition

List of transition probability arrays for time points k = p+1 to n. Each element should be an array of dimension c^p x c where the last dimension corresponds to the current time point.

blocks

Optional integer vector of length n_subjects specifying group membership. Required if homogeneous = FALSE.

homogeneous

Logical. If TRUE (default), same parameters used for all subjects. If FALSE, marginal and transition should be lists indexed by block.

n_categories

Number of categories. If NULL, inferred from data.

na_action

Handling of missing values in y. One of "fail" (default, error if any missing), "complete" (drop subjects with any missing values), or "marginalize" (integrate over missing categorical outcomes under the AD model).

Value

Scalar log-likelihood value.

Details

The log-likelihood for AD(p) decomposes into contributions from initial time points and transition time points.

For order 0 (independence), the log-likelihood is the sum of log marginal probabilities at each time point.

Parameter structure for marginal:

  • Order 0: List with elements t1, t2, ..., tn, each a vector of length c

  • Order 1: List with element t1 (vector of length c)

  • Order 2: List with t1 (vector), t2_given_1to1 (c x c matrix)

Parameter structure for transition:

  • Order 0: Not used (NULL or empty list)

  • Order 1: List with elements t2, t3, ..., tn, each c x c matrix

  • Order 2: List with elements t3, t4, ..., tn, each c x c x c array

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

set.seed(1)
y <- simulate_cat(n_subjects = 40, n_time = 5, order = 1, n_categories = 3)
fit <- fit_cat(y, order = 1, n_categories = 3)
logL_cat(
  y = y,
  order = 1,
  marginal = fit$marginal,
  transition = fit$transition,
  n_categories = 3
)
#> [1] -205.8751