Quantile Regression with Constrained B-Splines
Project description
Quantile Regression with Constrained Splines
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
- Python Repository: https://github.com/alexandreabbes/BsplineQuantRegpy
- R Repository: https://github.com/alexandreabbes/BsplineQuantReg
- R CRAN Package: https://cran.r-project.org/package=BsplineQuantReg
- DOI: 10.5281/zenodo.17427913
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 intemp.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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bsplinequantregpy-1.0.4.tar.gz.
File metadata
- Download URL: bsplinequantregpy-1.0.4.tar.gz
- Upload date:
- Size: 523.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d69014911913de028a6183c1d7701965c1382b09530cd26e020aa884cc3e26e2
|
|
| MD5 |
24d9a7152dcd44c81c178347989ef178
|
|
| BLAKE2b-256 |
1df9efcc4d5bfb4c6bc64c1d1acbc52c3594afa9f8fe9940a8468e02ad8f4b5a
|
File details
Details for the file bsplinequantregpy-1.0.4-py3-none-any.whl.
File metadata
- Download URL: bsplinequantregpy-1.0.4-py3-none-any.whl
- Upload date:
- Size: 536.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
892a267c56cfabff57e655e6ddee835a622413ff46cdca1a452bc2c76ec604c7
|
|
| MD5 |
02be8b0a7b952a42bc26c715a5ce87a3
|
|
| BLAKE2b-256 |
936a471bd80a4a46e1209ca2a8bdcfa435d2e80f8c1a10b3add8e7a397b72935
|