---
title: "Introduction"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{introduction}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup_core_intro2}
library(BsplineQuantReg)
```
## Introduction
The R package **'BsplineQuantReg'** is intended to perform quantile
regression with polynomial splines. It follows the method described in
Abbes (2025) , 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.
## Simple example
```{r simple example, fig.width=10, fig.height=4, out.width="100%"}
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')
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
)
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)
```
## Core content
### Degrees
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.
- **Demo** `degrees_comparison` — simultaneous comparison of constraints
across degrees 1, 2, 3, and 4.
### Usual Constraints
Constraints for degree 3 (monotone), degree 4 (monotone and convex) and
degree 5 (convex) use the **Karlin–Studden SOCP** characterization.
- **Vignettes** "theoretical_background", "shape_constraints"
- **Demos**:
\tiny
- comprehensive Comprehensive test of various constraints on an oscillating function
- monotonicity_basic Monotonicity constraints demo
- convexity Convexity and concavity constraints demo
- derivative2 Demontration for the coherence of the derivative functions
- demo_der3 Demonstration of third-order derivative constraints
- temperature Temperature anomaly analysis: uniform increasing vs mixed constraints (decreasing 1956-1973 only)
- temperature2 Temperature anomaly analysis with alternative constraint configurations
- logistic Quantile regression test on a logistic function
### Third-derivative constraints
**Third-derivative constraints** are supported for degrees 3 and 4.
- **Demo** `demo_der3` — demonstration of third-order derivative
constraints.
### B-spline library
**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.
- **Vignettes** "polynomial_library",
- demo `bspline_basis_manipulation`
**Differentiation of B-splines** can be performed either on the spline
(polynomial differentiation) or on the basis.
- **Demo** "derivative2" — coherence of the derivative functions.
### The library also extends to **multiple knots**
Multiple interior knots allows handle singularities, including for constrained regression.
**Demos**
- "shock" — regression with discontinuity and derivability
singularity
- "shock_basis" — same as "shock", with singular B-spline basis
display
**vignettes** "bsline_basis_manipulation"
## Graphical user interface
An interactive Shiny GUI is available:
- CRAN:
- GitHub:
The GUI lets you use most of the features of 'BsplineQuentReg' with a simple graphical interface.
## Python port
An equivalent Python package is available at
.