The R package ‘BsplineQuantReg’ 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 Bassett (1978) for linear regression.
We describe here shortly where the documentation is, in addition to the examples given with functions.
n_points <- 50
xtab <- (0:n_points) / n_points
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)
cat(kn,' equidistant knots')
#> 8 equidistant knots
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), mar = c(4, 4, 3, 1))
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 = "Without constraint")
lines(x_eval, y_sans, lwd = 2)
plot(xtab, ytab, pch = 16, cex = 0.5, col = "black",
main = "Mixed monotone:\nglobal increasing constraints")
lines(x_eval, y_croiss, lwd = 2)
plot(xtab, ytab, pch = 16, cex = 0.5, col = "black",
main = "Mixed monotone:\nincreasing constraints\non the first half")
lines(x_eval, y_part_croiss, lwd = 2)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.
degrees_comparison — simultaneous
comparison of constraints across degrees 1, 2, 3, and 4.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.
demo_der3 — demonstration of
third-order derivative constraints.All B-spline and polynomial functions have been rewritten for consistency
The package provides an complete and original B-spline and polynomial with pp-form library for the main operations. Some tools are available to display the basis.
Bspline constructions are all based on De Boor’s theory.
bspline_basis_manipulationDifferentiation of B-splines can be performed either on the spline (polynomial differentiation) or on the basis.
Multiple interior knots allows handle singularities, including for constrained regression.
Demos
vignettes “bsline_basis_manipulation”
An interactive Shiny GUI is available:
The GUI lets you use most of the features of ‘BsplineQuentReg’ with a simple graphical interface.
An equivalent Python package is available at https://pypi.org/project/BsplineQuantRegpy/.