Example usage 1

library(misc)
## Loading required package: MASS
## Loading required package: foreach
## Loading required package: doSNOW
## Loading required package: iterators
## Loading required package: snow
## 
## Attaching package: 'misc'
## The following object is masked from 'package:stats':
## 
##     integrate
# Strict decreasing with SCAM
x <- 1:5
y <- c(0.98, 0.99, 0.97, 0.975, 0.8)

# XGBoost with strict post-hoc enforcement
(result_xgb <- misc::monotonic_regression(x, y, method = "xgboost", monotonicity = -1, strict = TRUE))
## $fitted
## [1] 0.9841682 0.9841682 0.9725591 0.9725591 0.8007487
## 
## $model
## ##### xgb.Booster
## raw: 75.9 Kb 
## call:
##   xgboost::xgb.train(params = params, data = dtrain, nrounds = 100)
## params (as set within xgb.train):
##   objective = "reg:squarederror", monotone_constraints = "(-1)", eta = "0.1", max_depth = "3", validate_parameters = "TRUE"
## xgb.attributes:
##   niter
## callbacks:
##   cb.print.evaluation(period = print_every_n)
## niter: 100
## nfeatures : 1
# LightGBM with default approximate constraints
#(result_lgb <- misc::monotonic_regression(x, y, method = "lightgbm", monotonicity = -1, strict = FALSE))