R/model_categorical_glm.R

Defines functions model_categorical_glm

Documented in model_categorical_glm

#' @title model_categorical_glm
#' @concept model_categorical
#' @param y categorical outcome to predict
#' @param x features/predictors used in prediction of outcome
#'
#' @return
#' @export
#' @import dplyr nnet
#' @examples
model_categorical_glm <- function(x, y) {
  x <- as.matrix(x)
  y <- as.matrix(y)
  n_y <- unique(y) %>% length()
  if (n_y == 2) {
    glm(y ~ x, family = "binomial")
  } else if (n_y > 2) {
    multinom(y ~ x)
  } else {
    stop("number of factors of y must be greater than 2")
  }
}
epongpipat/eepR documentation built on June 5, 2024, 10:03 a.m.