Skip to contents

ordered provides engines for ordinal regression models for the parsnip package. The models may have cumulative, sequential, or adjacent-category structure, and in future these may be disaggregated into separate model types. A vignette will provide thorough illustrations of ordered functionality. See below for examples of fitting ordinal regression models with ordered.

Author

Maintainer: Jason Cory Brunson cornelioid@gmail.com (ORCID)

Authors:

Other contributors:

  • Posit Software PBC [copyright holder]

Examples

if (rlang::is_installed("MASS")) {

# Weighted sample

set.seed(561246)
house_sub <- MASS::housing %>%
  dplyr::sample_n(size = 120, replace = TRUE, weight = Freq) %>%
  subset(select = -Freq)
train_inds <- sample(120, 80)
house_train <- house_sub[train_inds, ]
house_test <- house_sub[-train_inds, ]

# Cumulative-link proportional-odds probit regression model

fit_cpop <- ordinal_reg() %>%
  set_engine("polr") %>%
  set_args(ordinal_link = "probit") %>%
  fit(Sat ~ Infl + Type + Cont, data = house_train)
predict(fit_cpop, house_test, type = "prob")

if (rlang::is_installed("ordinalForest")) {

# Ordinal forest

fit_orf <- rand_forest(mode = "classification") %>%
  set_engine("ordinalForest") %>%
  set_args(nsets = 50, trees = 100, perffunction = "probability") %>%
  fit(Sat ~ Infl + Type + Cont, data = house_train)
predict(fit_orf, house_test, type = "prob")

}
}
#> # A tibble: 40 × 3
#>    .pred_Low .pred_Medium .pred_High
#>        <dbl>        <dbl>      <dbl>
#>  1     0.141        0.345      0.514
#>  2     0.520        0.190      0.290
#>  3     0.423        0.315      0.262
#>  4     0.520        0.190      0.290
#>  5     0.233        0.282      0.486
#>  6     0.446        0.307      0.247
#>  7     0.165        0.398      0.437
#>  8     0.270        0.198      0.532
#>  9     0.446        0.307      0.247
#> 10     0.141        0.345      0.514
#> # ℹ 30 more rows