Skip to contents

Prior or posterior probabilities of the mixture components (latent classes). class_probs() is the same function under the latent-class name.

Usage

component_probs(
  object,
  newdata = NULL,
  conditioning = c("prior", "posterior", "history"),
  history = NULL
)

class_probs(object, ...)

Arguments

object

a model from countreg_mix() or countreg_lc().

newdata

optional data frame. Without it, the probabilities of the independent units of the training data are returned (one row per row, or per panel for panel models).

conditioning

"prior" (default): membership probabilities from the covariates; "posterior": conditional on the outcomes (each unit's own outcomes; a retrospective classification, not a prediction); "history": for panel models, conditional on earlier outcomes in history (see predict.countreg_mix()).

history

earlier rows of the panels, for conditioning = "history".

...

passed from class_probs().

Value

A matrix with one column per component (named by the component labels) and one row per unit (training data) or per row of newdata. These are probabilities of the components, not of counts (for count probabilities use predict(type = "prob")).

Details

The posterior probabilities give a descriptive classification (e.g. the most probable class of each unit), which is uncertain: units with probabilities near \(1/K\) are not well classified. The entropy in summary() summarizes that uncertainty.

Examples

set.seed(1)
d <- data.frame(y = c(rpois(300, 1), rpois(200, 6)))
m <- countreg_mix(y ~ 1, data = d, components = 2, n_starts = 3,
                  seed = 1)
head(component_probs(m, conditioning = "posterior"))
#>      Component1  Component2
#> [1,]  0.9960297 0.003970273
#> [2,]  0.9754798 0.024520217
#> [3,]  0.9754798 0.024520217
#> [4,]  0.8631757 0.136824277
#> [5,]  0.9960297 0.003970273
#> [6,]  0.8631757 0.136824277