Skip to main content

Quantile Regression with Constrained Splines

Python 3.9+ PyPI version DOI License: GPL v3 Documentation Documentation EN

Code style: black Python R

Python implementation of quantile regression with constrained splines (degrees 1-4). Degrees 1-3 are based on the article "Quantile regression with cubic splines under shape constraints" by Alexandre Abbes, while degree 4 is a natural consequence of the cited references.

Associated packages

Package Langage Description Lien
BsplineQuantReg R Splines cubiques contraintes, self-contained CRAN
cobs R Constrained B-Splines (linéaires et quadratiques) CRAN
quantreg R Quantile Regression CRAN
quantreg Python Quantile Regression statmodels or PyPI
Ce package Python Splines de degrés 1 à 4 contraintes GitHub

Comparison of packages

Fonctionnality cobs (R) BsplineQuantReg (R) BsplineQuantRegpy (Python)
Linear Splines
Quadratic Splines
Cubic Splines
Quartic Splines
Contraints at knots
Over the whole interval
Region constraints
Third derivative
Gui
Self-contained for Bsplines ❌ (utilise SciPy)

## Features

-  Quantile regression with splines of degree 1 to 4
-  Constraints on derivatives (monotonicity, convexity, third derivative)
-  Constraints valid over the entire interval or selected regions
-  Graphical interface for interactive testing (Tkinter)
-  Multiple solvers support (CLARABEL, ECOS, SCS, MOSEK)

##  Installation

### Python

```bash
# From PyPI
pip install BsplineQuantRegpy

# Or from source
git clone https://github.com/alexandreabbes/BsplineQuantRegpy.git
cd BsplineQuantRegpy
pip install -e .

R

# From CRAN
install.packages("BsplineQuantReg")

Links

File Structure

Graphical Interface

  • Quantr_eg_tk.py - Tkinter GUI for interactive parameter testing (spline degree, knots, derivative constraints)

Main Algorithms

File Description
SplineCubicQuant.py Cubic splines with constraints on 1st, 2nd, and 3rd derivatives
SplineQuarticQuant.py Quartic splines with exact constraints over the entire interval
SplineQuadraticQuant.py Quadratic splines with constraints on 1st and 2nd derivatives
SplineLinearQuant.py Linear splines with constraints on 1st derivative '
quantile_spline.py Unified function for regresion with any degree 1-4 and constraints

Examples and Data

  • example_temerature.py - Replication of the test on global warming (temperatures , data in temp.xls)
  • examples/ - Additional usage examples

Quick Start

from splinequantreg import SplineCubicQuantile
import numpy as np
Quickstart
Quickstart2

# Or
# Generate data
x = np.linspace(0, 1, 100)
y = 3*x + 0.2*np.sin(10*np.pi*x) + 0.1*np.random.randn(100)
knots = np.quantile(x, np.linspace(0, 1, 11))

# Fit with monotonicity constraint
result = SplineCubicQuantile(x, y, knots, tau=0.5, monot=1)

# Evaluate
x_eval = np.linspace(0, 1, 200)
y_eval = result(x_eval)

Or launch the GUI:

from splinequantreg import run_gui
run_gui()

Prerequisites

Python

pip install numpy scipy pandas matplotlib cvxpy

``

Citation

If you use this code in your research, please cite:

@article{abbes2025quantile,
  title={Quantile regression with cubic polynomial splines under shape constraints with applications},
  author={Abbes, Alexandre},
  year={2025},
  doi={10.5281/zenodo.17427913}
}


## Contributions

Contributions are welcome! Feel free to:

- Open an [issue](https://github.com/alexandreabbes/BsplineQuantRegpy/issues)
- Submit a [pull request](https://github.com/alexandreabbes/BsplineQuantRegpy/pulls)
- Suggest improvements

## License

This project is licensed under the GPL-v3 License - see the [LICENSE](LICENSE) file for details.

## AI Assistance

This project was carried out with the assistance of **DeepSeek** ([https://deepseek.com/](https://deepseek.com/)), which helped the developer with:
- Implementing constrained spline algorithms from MATLAB to Python
- Translating mathematical concepts into Python code
- Structuring programs and documentation

DeepSeek is a language model developed by 深度求索 [1].

[1] DeepSeek-AI. (2024). DeepSeek-V3 Technical Report. arXiv:2412.19437.

## References

- Abbes, A. (2025). Quantile regression with cubic polynomial splines
under shape constraints with applications. doi:10.5281/zenodo.17427913
- He, X., & Shi, P. (1998). Monotone B-spline smoothing. *Journal of the American Statistical Association*, 93(442), 643-650.
- Karlin, S., & Studden, W.J. (1966). *Tchebycheff Systems: With Applications in Analysis and Statistics*. Interscience Publishers.
- Papp, D., & Alizadeh, F. (2014). Shape-Constrained Estimation Using Nonnegative Splines. *Journal of Computational and Graphical Statistics*, 23(1), 211-231.


## Contact

**Author**: Alexandre Abbes
**Email**: alexandre.abbes@proton.me
**GitHub**: [alexandreabbes](https://github.com/alexandreabbes)

Release files for BsplineQuantRegpy 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BsplineQuantRegpy 1.0.4
File Size Uploaded
bsplinequantregpy-1.0.4.tar.gz 523.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for BsplineQuantRegpy 1.0.4
File Interpreter ABI Platform
bsplinequantregpy-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 1.1 MB

Release files / bsplinequantregpy-1.0.4.tar.gz

Download URL bsplinequantregpy-1.0.4.tar.gz
Size 523.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d69014911913de028a6183c1d7701965c1382b09530cd26e020aa884cc3e26e2
BLAKE2b-256 checksum
How to use checksums
1df9efcc4d5bfb4c6bc64c1d1acbc52c3594afa9f8fe9940a8468e02ad8f4b5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / bsplinequantregpy-1.0.4-py3-none-any.whl

Download URL bsplinequantregpy-1.0.4-py3-none-any.whl
Size 536.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
892a267c56cfabff57e655e6ddee835a622413ff46cdca1a452bc2c76ec604c7
BLAKE2b-256 checksum
How to use checksums
936a471bd80a4a46e1209ca2a8bdcfa435d2e80f8c1a10b3add8e7a397b72935
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page