R/mixture_model_data.R

Defines functions make_mixture_model

make_mixture_model <- function() {

  parsnip::set_new_model("mixture_model")

  parsnip::set_model_mode(model = "mixture_model",
                          mode = "regression")

  parsnip::set_model_engine("mixture_model",
                            mode = "regression",
                            eng = "flexmix")

  parsnip::set_dependency("mixture_model",
                          eng = "flexmix",
                          pkg = "flexmix")

  parsnip::set_model_arg(
    model = "mixture_model",
    eng = "flexmix",
    parsnip = "components",
    original = "k",
    func = list(pkg = "dials", fun = "num_comp"),
    has_submodel = FALSE
  )

  parsnip::set_fit(
    model = "mixture_model",
    eng = "flexmix",
    mode = "regression",
    value = list(
      interface = "formula",
      protect = c("formula", "data"),
      func = c(pkg = "flexmix", fun = "flexmix"),
      defaults = list()
    )
  )

  parsnip::set_pred(
    model = "mixture_model",
    eng = "flexmix",
    mode = "regression",
    type = "numeric",
    value = list(
      pre = NULL,
      post = function(results, object) {
        unlist(results)
      },
      func = c(pkg = "flexmix", fun = "predict"),
      args =
        list(
          object = quote(object$fit),
          newdata = quote(new_data),
          type = "response",
          aggregate = TRUE
        )
    )
  )

}
hfrick/beetroot documentation built on April 13, 2020, 12:39 a.m.