predict.latents_mixture_regression: Predict from a mixture-of-regressions fit

View source: R/mixture-regression-predict.R

predict.latents_mixture_regressionR Documentation

Predict from a mixture-of-regressions fit

Description

Predict from a mixture-of-regressions fit

Usage

## S3 method for class 'latents_mixture_regression'
predict(
  object,
  newdata = NULL,
  type = c("response", "class_response", "posterior", "probabilities"),
  ...
)

Arguments

object

A fit from mixture_regression().

newdata

NULL for the fitted rows, or a data frame with the predictors (and the membership covariates and id the model uses).

type

"response": the mean outcome averaged over the classes with their prior probabilities (the covariates, but not the outcome, inform them). "class_response": the mean outcome under every class, one row per row and class. "posterior": the posterior class probabilities given the outcome, which newdata must then contain. "probabilities" (ordinal family only): the probability of every category under every class. For the ordinal family the "mean outcome" is the expected category score, the categories scored 1 to C in order.

...

Unused.

Value

A base data.frame. For "response": row and fitted. For "class_response": row, class, prior and fitted, one row per data row and class. For "posterior": the same columns as get_results(fit, "assignments"). For "probabilities": row, class, category, prior and probability, one row per data row, class and category. Raises latents_bad_argument for "probabilities" with another family.

Examples

fit <- mixture_regression(score ~ hours, data = study_hours, n_classes = 2,
                          n_starts = 3, seed = 1)
new_students <- data.frame(hours = c(2, 10))
predict(fit, new_students, type = "class_response")

latents documentation built on Oct. 16, 2026, 5:09 p.m.