MyNixOS website logo
Description

'parsnip' Engines and Wrappers for Ordinal Classification Models.

Bindings, methods, and tuners for using ordinal classification models with the 'parsnip' and 'dials' packages. These include the regularized elastic net ordinal regression of Wurm, Hanlon, and Rathouz (2021) <doi:10.18637/jss.v099.i06> in 'ordinalNet', the ordinal classification trees of Galimberti, Soffritti, and Di Maso (2012) <doi:10.18637/jss.v047.i10> in 'rpartScore', and the latent variable ordinal forests of Hornung (2020) <doi:10.1007/s00357-018-9302-x> in 'ordinalForest'.

ordered

Lifecycle:experimental CRANstatus R-CMD-check Codecov testcoverage

ordered is a parsnip extension to enable additional classification models for ordinal outcomes (e.g., “low”, “medium”, “high”). While there are several model/engine combinations in the parsnip package that can be used, this package adds:

  • cumulative link (cumulative logit) ordinal regression via MASS::polr()
  • generalized linear and generalized additive ordinal regression models of cumulative link, adjacent categories, continuation ratio, and stopping ratio families via VGAM::vglm() and VGAM::vgam() (Yee, 2015)
  • regularized elastic net ordinal regression models of cumulative link, adjacent categories, continuation ratio, and stopping ratio families via ordinalNet::ordinalNet() (Wurm, Hanlon, and Rathouz, 2021)
  • ordinal classification trees via rpartScore::rpartScore() (Galimberti, Soffritti, and Di Maso, 2012)
  • latent variable ordinal forests via ordinalForest::ordfor() (Hornung, 2020)

More will be added.

There are some existing features in tidymodels packages that are useful for ordinal outcomes:

  • The partykit engines for parsnip::decision_tree() and parsnip::rand_forest() use the ordered nature of the factors to train the model.
  • The yardstick package has yardstick::kap() for weighted and unweighted Kappa statistics (the former being of more interest). Also, yardstick::classification_cost() can utilize more complex cost structures and uses the class probabilities for estimation.

Installation

You can install the development version of ordered like so:

# install.packages("pak")
pak::pak("corybrunson/ordered", dependencies = FALSE)

Currently, ordered relies on engine registration in a parsnip fork and dial registration in the current development version:

pak::pak("corybrunson/parsnip@ordered", dependencies = FALSE)
pak::pak("tidymodels/dials", dependencies = FALSE)

Available models, engines, and prediction types

ordered provides new engines for several models, including all engines for ordinal_reg(), as summarized in the table. Currently only predictions of type = "class" and type = "prob" are supported.

modelengineclassprob
decision_treerpartScore
gen_additive_modvgam
ordinal_regpolr
ordinal_regordinalNet
ordinal_regvglm
rand_forestordinalForest

Example

Here is a simple example using computational chemistry data to predict the permeability of a molecule:

library(dplyr)
library(ordered)

data(caco, package = "QSARdata")

caco_dat <-
  inner_join(caco_Outcome, caco_Dragon, by = "Molecule") %>%
  as_tibble() %>%
  select(
    class = Class,
    mol_weight = QikProp_mol_MW,
    volume = QikProp_volume,
    ClogP
  )
caco_train <- caco_dat[-(1:10), ]
caco_test  <- caco_dat[ (1:10), ]

ord_rf_spec <- 
  # you should really use many more trees and score sets
  rand_forest(mtry = 2, trees = 100) %>%
  set_mode("classification") %>%
  set_engine("ordinalForest", nsets = 100)

set.seed(382)
ord_rf_fit <- ord_rf_spec %>% fit(class ~ ., data = caco_train)
augment(ord_rf_fit, new_data = caco_test)
#> # A tibble: 10 × 8
#>    .pred_class .pred_L .pred_M .pred_H class mol_weight volume  ClogP
#>    <ord>         <dbl>   <dbl>   <dbl> <ord>      <dbl>  <dbl>  <dbl>
#>  1 M            0.370    0.384  0.246  M           123.   445.  0.799
#>  2 M            0.250    0.533  0.217  L           290.   856.  0.534
#>  3 M            0.178    0.801  0.0212 M           519.  1576.  1.02 
#>  4 M            0.221    0.736  0.0431 M           533.  1606.  1.58 
#>  5 M            0.135    0.762  0.103  M           505.  1517.  1.71 
#>  6 M            0.0698   0.913  0.0176 M           519.  1547.  2.27 
#>  7 M            0.220    0.738  0.0417 M           517.  1600.  1.78 
#>  8 M            0.109    0.868  0.0229 M           531.  1631.  2.34 
#>  9 M            0.0307   0.952  0.0177 M           517.  1572.  2.81 
#> 10 L            0.603    0.394  0.003  L           588.  1799. -1.85

Code of Conduct

Please note that the ordered project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

To voice support for or volunteer to contribute additional engines, please comment on this issue.

Metadata

Version

0.1.0

License

Unknown

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows