R/predict_redda.R

Defines functions predict.redda

# Predict function to be used with redda output ------------------------

# Consistent with Conventions for R Modeling Packages
# https://tidymodels.github.io/model-implementation-principles/index.html

predict.redda <- function(object, new_data, ...){
    if (!inherits(object, "redda"))
      stop("object not of class \"redda\"")
    classLabel <- names(object$Best$parameters$pro)
    fite <- estep(
      modelName = object$Best$model_name,
      data = new_data,
      parameters = object$Best$parameters
    )
    z <- fite$z
    cl <-
      factor(sapply(mclust::map(z), function(i)
        classLabel[i]), levels = classLabel)
    out <- list(class = cl, prob = z)
    out
  }
AndreaCappozzo/rupclass documentation built on July 19, 2021, 5:36 a.m.