Introduction

library(BsplineQuantReg)

The R-package “Quantile regression with B-splines under shape constraints” is intended to perform quantile regression with polynomial splines. It follows the method described in Abbes(2025) doi:10.5281/zenodo.17427913, and initiated by He and Shi (1998) for quadratic splines, on the original idea of Koenker and Basset for linear regression.

Simple example



 n_points <- 50
  xtab = ((0:(n_points)) / (n_points))

  # simple pscillating data
  #ytab<- -3 * xtab +sin(3*2*xtab*3.14)+ 0.2 * rnorm(n_points+1)
  #ytab= <- 2* xtab + 0.5 * sin(6 * pi * xtab) + 0.1 * rnorm(n_points+1)
  ytab <- xtab * (1 - xtab) + 0.1 * rnorm(n_points + 1)
  kn <- 8

  n = 7

  monot1 = c(rep(1, n), rep(0, (12 - n)))
  monot2 = rep(1,12)
  knot <- ((0:(kn + 5)) / (kn + 5))
  
  res <- quantile_spline(
    xtab = xtab,
    ytab = ytab,
    knot,
    tau = 0.5,
    monot = 0,
    degree = 3,
    verbose = FALSE
  )
 res_part_croissant <- quantile_spline(
    xtab = xtab,
    ytab = ytab,
    knot = knot,
    tau = 0.5,
    degree = 3,
    monot = monot1,
    convcons = 0,
    verbose = FALSE
  )
#> Not enough monotonicity constraints, completing with 0
 
 res_croissant <- quantile_spline(
    xtab = xtab,
    ytab = ytab,
    knot = knot,
    tau = 0.5,
    degree = 3,
    monot = 1,
    convcons = 0,
    verbose = FALSE
  )
 
 
par(mfrow = c(1, 3))
x_eval=(0:200)/200
  y_sans = spline_eval(res, x_eval)
  y_part_croiss = spline_eval(res_part_croissant, x_eval)
  y_croiss = spline_eval(res_croissant, x_eval)
  
    plot(
    xtab,
    ytab,
    pch = 16,
    cex = 0.5,
    col = "black",
    main = c("Without constraint")
    )
    lines(x_eval, y_sans, lwd = 2)  
    
  plot(
    xtab,
    ytab,
    pch = 16,
    cex = 0.5,
    col = "black",
    main = c("Mixed mootone :\n global increasing constraints
                "
    )
  )
  lines(x_eval, y_croiss, lwd = 2)  

    
    plot(
    xtab,
    ytab,
    pch = 16,
    cex = 0.5,
    col = "black",
    main = c("Mixed mootone :\n increasing constraints
                \n on the first inter-knots"
    )
  )
  lines(x_eval, y_part_croiss, lwd = 2)  

Core content

The initial version with cubic splines is now augmented with splines of degree 0 to 4 for constrained regression, and any degree for regression without monotone constraints.

Constraints for degree 3 (monotone), degree 4 (monotone and convex) and degree 5 (convex) use the Karlin–Studden SOCP characterization.

Third-derivative constraints are supported for degrees 3 and 4.

B-spline library

All B-spline and polynomial functions have been rewritten for consistency. The package provides an original B-spline library for:

all based on De Boor’s theory.

Differentiation of B-splines can be performed either on the spline (polynomial differentiation) or on the basis.

The library also extends to multiple knots to handle singularities, robustly, including for constrained regression.

Graphical user interface

An interactive Shiny GUI is available:

# From CRAN:
# install.packages("BsplineQuantRegGui")

# Or from GitHub:
# install.packages("remotes")
# remotes::install_github("<user>/BsplineQuantRegGUI")

# Launch:
# BsplineQuantRegGui::run_app()

The GUI lets you:

Python port

An equivalent Python package is available at https://pypi.org/project/BsplineQuantRegpy/.