Anton Antonov
​MathematicaForPrediction at WordPress​
​MathematicaForPrediction at GitHub​
May 2023

Introduction

In this notebook we develop in detail Quantile Regression (QR) examples over 3D data via the functions of the paclet “AntonAntonov/QuantileRegression”, [AAp1].
The QR examples demonstrate using:
1
.
QuantileRegression
with "automatic", NURBS functions (created via
BSplineFunction
)
2
.
QuantileRegressionFit
with custom made basis functions
Remark: In order to get a better idea of the how the data looks like, use the 3D graphics interactivity feature rotation.
Remark: This notebook automatically installs the paclet “AntonAntonov/QuantileRegression", [AAp1] -- see the section “Preparation” below.
Remark: A version of this notebook is a technical note in the paclet "AntonAntonov/QuantileRegression", [AAp1].

First neat example

This section has a first neat example with data with triangular domain.
Generate noisy 3D data
In[]:=
Block{c=2,h=0.1},​​data=FlattenTablex,y,Exp-(
2
x
+
2
y
)4*(1+RandomReal[1.2]),{x,-c,c,h},{y,x,c,h},1;​​
Compute Quantile regression for probabilities
0.1
and
0.9
In[]:=
probs={0.1,0.9};​​AbsoluteTiming[​​funcs=AssociationThread[probs->QuantileRegression[data,4,probs]];​​]
Out[]=
{0.205853,Null}
Plot the data points and regression quantiles together
In[]:=
reg=ConvexHullRegion[Most/@data];​​QRPlot3D[data,funcs,RegionFunction->Function[{x,y},RegionMember[reg,{x,y}]]]​​
Out[]=
0.1
0.9

Noisy arrow wave

Generate random, "noisy wave" data
In[]:=
{b,c}={-6,6};​​data=RandomReal[{b,c},{1200,2}];​​data=Map[Append[#,Sqrt[#[[1]]-b]+Sin[#[[1]]+Abs[#〚2〛]]+RandomVariate[NormalDistribution[0,0.3]]]&,data];​​Dimensions[data]
Out[]=
{1200,3}
3D list plot of the data
In[]:=
ListPointPlot3D[data,PlotRange->All,PlotLabel->"Noisy wave data",BoxRatios->{1,1,2/3},ImageSize->Medium]
Out[]=
Data summary
In[]:=
ResourceFunction["RecordsSummary"][data]
Out[]=

1 column 1
Min
-5.99067
1st Qu
-2.96438
Mean
0.00865712
Median
0.0298711
3rd Qu
2.94166
Max
5.99499
,
2 column 2
Min
-5.97943
1st Qu
-2.93964
Median
-0.0077573
Mean
0.0514073
3rd Qu
3.18299
Max
5.99482
,
3 column 3
Min
-0.971604
1st Qu
1.54153
Mean
2.31497
Median
2.31907
3rd Qu
3.16361
Max
4.9233

Compute Quantile regression for probability 0.5 using a grid of
7×4
NURBS basis functions
In[]:=
AbsoluteTiming[​​funcs=QuantileRegression[data,{7,4},0.5];​​]
Out[]=
{0.379605,Null}
Plot the obtained function and data
In[]:=
QRPlot3D[data,<|0.5->First[funcs]|>]
Out[]=
0.5
Quantile regression for probabilities 0.1 and 0.9
3D list plot of the data
Count the number of points under each surface
Show the corresponding fractions (should correspond to the probabilities)

Square sombrero

Generate random, "square sombrero" data
3D list plot of the data
Data summary
Quantile regression for probability 0.9
Plot functions and data

Pyramid basis

In this section we demonstrate the use of custom made basis functions.
Define a pyramid basis function
Here is a plot of a basis function
Make a basis for the sombrero data
Find regression quantiles for probability 0.2
Plot data and regression quantiles together

Partial sombrero

Remark: For a more detailed discussion of how basis filtering is implemented and how it addresses “partial data occupation” problems see the section “Possible issues” of the function page for NURBSBasis.
Generate random, "partial sombrero" data
3D list plot of the data
Regression quantiles
Plot data and regression quantiles together
Create a region object for the convex hull of the data points
The plot data and regression quantiles over the region above
Count the number of points under each surface
Show the corresponding fractions (should correspond to the probabilities)

Preparation

Install the paclet
Load the Quantile regression paclet
Set random seed
Define plot function
Define pure functions converter

References

Articles

[Wk1] Wikipedia entry, Quantile regression .
[Wk2] Wikipedia entry, NURBS .
[AA1] Anton Antonov, "Quantile regression through linear programming" , (2013), MathematicaForPrediction at WordPress .
[AA2] Anton Antonov, "Quantile regression with B-splines" m (2014), MathematicaForPrediction at WordPress .

Books

Roger Koenker, (2005). Quantile Regression (Econometric Society Monographs). 2005. Cambridge: Cambridge University Press. doi:10.1017/CBO9780511754098

Functions, packages, paclets

[AAf1] Anton Antonov, QuantileRegression, (2019), Wolfram Function Repository.
[AAp1] Anton Antonov, QuantileRegression paclet, (2023), Wolfram Language Paclet Repository.
[AAp2] Anton Antonov, QuantileRegression Mathematica package, (2013-2023), MathematicaForPrediction at GitHub.

Videos

[AAv1] Anton Antonov, "Quantile Regression—Theory, Implementations, and Applications" , (2014), Wolfram channel at YouTube .

CITE THIS NOTEBOOK

Quantile regression 3D examples​
by Anton Antonov​
Wolfram Community, STAFF PICKS, May 17 2023
​https://community.wolfram.com/groups/-/m/t/2920790