R/mixture_model.R

Defines functions mixture_model

Documented in mixture_model

#' General Interface for Mixture Models
#'
#' @param mode A single character string for the type of model.
#'  The only possible value for this model is "regression".
#' @param components The number of components of the mixture model.
#'
#' @export
#'
#' @examples
#' data(faithful)
#' \dontrun{
#' mixture_model(components = 2) %>%
#'   set_engine("flexmix") %>%
#'   fit(eruptions ~ waiting, data = faithful, engine = "flexmix") %>%
#'   predict(new_data = faithful, type = "numeric")
#' }
mixture_model <- function(mode = "regression",  components = NULL) {
  # Check for correct mode
  if (mode  != "regression") {
    stop("`mode` should be 'regression'", call. = FALSE)
  }

  # Capture the arguments in quosures
  args <- list(components = rlang::enquo(components))

  # Save some empty slots for future parts of the specification
  out <- list(args = args, eng_args = NULL,
              mode = mode, method = NULL, engine = NULL)

  # set classes in the correct order
  class(out) <- parsnip::make_classes("mixture_model")
  out
}
hfrick/beetroot documentation built on April 13, 2020, 12:39 a.m.