Monotonic Regression using XGBoost, LightGBM, or SCAM

monotonic_regression(
  x,
  y,
  method = c("xgboost", "lightgbm", "scam"),
  monotonicity = 1,
  prediction = TRUE,
  strict = FALSE,
  ...
)

Arguments

x

Numeric vector or matrix of predictor variables

y

Numeric vector of response variable

method

Either "xgboost", "lightgbm", or "scam"

monotonicity

1 for non-decreasing, -1 for non-increasing

prediction

A boolean; obtain predictions on training set (TRUE) or return model object

strict

If TRUE, enforces strict monotonicity (for xgboost/lightgbm only; scam is always strict)

...

Additional parameters passed to the underlying algorithm

Value

A list with fitted values and model object

Examples

# Strict decreasing example with xgboost
x <- 1:5
y <- c(0.98, 0.99, 0.97, 0.95, 0.8)
result <- monotonic_regression(x, y, method = "xgboost", monotonicity = -1)
print(result$fitted)
#> [1] 0.9841873 0.9841873 0.9699466 0.9500497 0.8007391