Skip to main content

Quantile regression with B-splines under shape constraints

Project description

Quantile Regression with Constrained Splines

License: MIT Python 3.9+ PyPI version DOI

Python implementation of quantile regression with constrained splines (degrees 1-3). 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.

Python R

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

Comparaison of packages

Fonctionnality cobs (R) BsplineQuantReg (R) BsplineQuantRegpy (Python)
Linear Splines
Quadratic Splines
Cubic Splines
Quartic Splines
Contraints at nœuds
Over the whole interval
Third derivative
Gui
Region constraints
Self-contained ❌ (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)
-  Standalone code with built-in tests

##  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

  • Quant_reg_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

  • Test_temp.py - Replication of the test on global 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 MIT 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bsplinequantregpy-1.0.1.tar.gz (512.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bsplinequantregpy-1.0.1-py3-none-any.whl (527.3 kB view details)

Uploaded Python 3

File details

Details for the file bsplinequantregpy-1.0.1.tar.gz.

File metadata

  • Download URL: bsplinequantregpy-1.0.1.tar.gz
  • Upload date:
  • Size: 512.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for bsplinequantregpy-1.0.1.tar.gz
Algorithm Hash digest
SHA256 94fb9cfc48fbd32bf06581a9fa2cc512f8318cd049ce4b774e32a67da64e632a
MD5 9fe7578e77bb6cbf9c9321652833f234
BLAKE2b-256 ec9cb182d7d985ac3630be5721d9fa6a841d19d10d323c1dac7195c7ce10adb6

See more details on using hashes here.

File details

Details for the file bsplinequantregpy-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bsplinequantregpy-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6059de41a9dcc7fefb3798c6a8e6a303ba355912c0b1f555a8461d26dc0ac54a
MD5 5e817a4d9153f4573bd5f9bbdcdb52a6
BLAKE2b-256 80c575e371e27b2570aca391ca219ff91ce3859342718020b654b46dc175fafe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page