Introduction
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
.2
. 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
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=FlattenTablex,y,Exp-(+)4*(1+RandomReal[1.2]),{x,-c,c,h},{y,x,c,h},1;
2
x
2
y
Compute Quantile regression for probabilities and
0.1
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[]=
Noisy arrow wave
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 | ||||||||||||
|
2 column 2 | ||||||||||||
|
3 column 3 | ||||||||||||
|
Compute Quantile regression for probability 0.5 using a grid of NURBS basis functions
7×4
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[]=
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
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
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
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
Preparation
Install the paclet
Load the Quantile regression paclet
Set random seed
Define plot function
Define pure functions converter
References
References
Articles
Articles
[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
Books
Roger Koenker, (2005). Quantile Regression (Econometric Society Monographs). 2005. Cambridge: Cambridge University Press. doi:10.1017/CBO9780511754098
Functions, packages, paclets
Functions, packages, paclets
[AAp2] Anton Antonov, QuantileRegression Mathematica package, (2013-2023), MathematicaForPrediction at GitHub.
Videos
Videos
[AAv1] Anton Antonov, "Quantile Regression—Theory, Implementations, and Applications" , (2014), Wolfram channel at YouTube .
CITE THIS NOTEBOOK
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
by Anton Antonov
Wolfram Community, STAFF PICKS, May 17 2023
https://community.wolfram.com/groups/-/m/t/2920790