Skip to main content

Quantile Regression with Constrained B-Splines

Project description

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)

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.4.tar.gz (523.1 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.4-py3-none-any.whl (536.5 kB view details)

Uploaded Python 3

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

Hashes for bsplinequantregpy-1.0.4.tar.gz
Algorithm Hash digest
SHA256 d69014911913de028a6183c1d7701965c1382b09530cd26e020aa884cc3e26e2
MD5 24d9a7152dcd44c81c178347989ef178
BLAKE2b-256 1df9efcc4d5bfb4c6bc64c1d1acbc52c3594afa9f8fe9940a8468e02ad8f4b5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bsplinequantregpy-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 892a267c56cfabff57e655e6ddee835a622413ff46cdca1a452bc2c76ec604c7
MD5 02be8b0a7b952a42bc26c715a5ce87a3
BLAKE2b-256 936a471bd80a4a46e1209ca2a8bdcfa435d2e80f8c1a10b3add8e7a397b72935

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