latent_class_diagnostics: Diagnose latent-class occupancy and membership

View source: R/posterior.R

latent_class_diagnosticsR Documentation

Diagnose latent-class occupancy and membership

Description

Computes label-invariant posterior summaries of a fitted mixture model: the distribution of the occupied class count and the posterior probability that every pair of deciders belongs to the same class. It also returns the probability of every decider belonging to each relabeled class.

Usage

latent_class_diagnostics(object)

Arguments

object

[RprobitB_fit]
Fitted model with at least two finite classes, a sparse finite mixture, a Dirichlet-process mixture, or a weight-based heuristic fit.

Value

A list with three elements:

  • occupancy: a data.frame with the columns n_classes and probability. It gives the share of draws in which exactly n_classes classes contain at least one decider, so it answers how many classes the data support. For a fixed mixture, the number of classes is fixed, and the table shows how often one of them stays empty.

  • co_clustering: a square matrix with one row and one column per decider. Entry ⁠[i, j]⁠ is the share of draws in which deciders i and j are in the same class, so it answers whether two deciders behave alike. It does not depend on how the classes are labeled.

  • membership: a matrix with one row per decider and one column per class, class_1 to ⁠class_<maximum>⁠. Entry ⁠[i, k]⁠ is the share of draws in which decider i is in class k after relabeling, so it answers which class a decider most likely belongs to.

References

\insertRef

Dahl2006RprobitB

\insertRef

Papastamoulis2010RprobitB

\insertRef

Stephens2000RprobitB

Examples

set.seed(1)
model <- fit(
  choice ~ x | 0, random_effects = "x", latent_class_effects = "x",
  classes = 2, class_update = "dirichlet_process",
  dgp_parameters = list(
    beta = list(c(x = -1), c(x = 2)),
    Omega = list(matrix(0.2), matrix(0.2)),
    weights = c(0.6, 0.4)
  ),
  n_occasions = 5,
  chains = 1
)
diagnostics <- latent_class_diagnostics(model)
diagnostics$occupancy
diagnostics$co_clustering[1:5, 1:5]
head(diagnostics$membership)

RprobitB documentation built on Sept. 20, 2026, 9:07 a.m.