R/get_predictions_mlogit.R

Defines functions get_predictions_mlogit

get_predictions_mlogit <- function(model, fitfram, ...) {
  # bind IDX to new data
  dat <- insight::get_data(model, source = "frame", verbose = FALSE)
  fitfram <- do.call(rbind, lapply(seq_along(levels(dat$idx$id2)), function(i) {
    fitfram$idx <- sprintf("%g:%s", i, levels(dat$idx$id2)[i])
    fitfram
  }))

  prdat <- stats::predict(
    model,
    newdata = fitfram,
    ...
  )

  # stack columns
  prdat <- utils::stack(as.data.frame(prdat))
  colnames(prdat) <- c("predicted", "response.level")
  cbind(fitfram, prdat)
}

Try the ggeffects package in your browser

Any scripts or data that you put into this service are public.

ggeffects documentation built on Sept. 12, 2024, 7:41 a.m.