One row per subject, one column per latent class, rows summing to
one: the probability that a subject belongs to each class given its
observed item responses and its gating covariates. This is poLCA's
$posterior.
Arguments
- fit
A
frmtmb_fitwith anlca()family.
Details
The relative entropy of the classification is attached as the
entropy attribute: 1 - sum(-p log p) / (n log K), which is 1
for a partition with no ambiguity and 0 when every subject is
equally likely to be in any class. Values above about 0.8 are the
usual rule of thumb for classes worth naming.
This is mixture_probs() under an LCA-specific name and check; the
two return the same matrix for an lca() fit.
Examples
set.seed(3)
n <- 200
cl <- rbinom(n, 1, 0.5) + 1
pr <- rbind(c(0.9, 0.85, 0.8, 0.9), c(0.1, 0.15, 0.2, 0.1))
Y <- matrix(0L, n, 4)
for (j in 1:4) Y[, j] <- 1L + rbinom(n, 1, pr[cl, j])
dd <- data.frame(row = seq_len(n))
dd$Y <- Y
fit <- frm(bf(Y ~ 1), family = lca(K = 2), data = dd)
p <- lca_probs(fit)
head(p)
#> class1 class2
#> [1,] 0.050257364 0.9497426357
#> [2,] 0.999644964 0.0003550359
#> [3,] 0.001387834 0.9986121658
#> [4,] 0.041477823 0.9585221775
#> [5,] 0.991678284 0.0083217163
#> [6,] 0.986657236 0.0133427645
attr(p, "entropy") # classification quality, 0 to 1
#> [1] 0.8561932
table(max.col(p), truth = cl) # the modal assignment, up to relabeling
#> truth
#> 1 2
#> 1 11 95
#> 2 93 1