Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

QuantileRegression

Guides

  • Quantile regression

Tech Notes

  • Quantile regression 3D examples
  • Quantile regression over weather time series
  • Unit tests

Symbols

  • NURBSBasis
  • QuantileEnvelope
  • QuantileEnvelopeRegion
  • QuantileRegressionFit
  • QuantileRegression
Quantile regression 3D examples
Preparation
Pyramid basis
Noisy arrow wave
Partial sombrero
Square sombrero
​
In this notebook we develop in detail Quantile Regression (QR) examples over 3D data. 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.
Preparation
Load the Quantile regression paclet
In[18]:=
Needs["AntonAntonov`QuantileRegression`"]
Set random seed
In[19]:=
SeedRandom[9903];
Define plot function
In[20]:=
QRPlot[data_List,funcs_Association,opts___]:=​​Show[​​ListPointPlot3D[data,FilterRules[{opts},{{BoxRatios{1,1,1/1.5}}}],{BoxRatios{1,1,1/1.5}},PlotStyleRed,PlotRangeAll],​​Plot3D[Evaluate@Through[Values[funcs][x,y]],{x,Min[data〚All,1〛],Max[data〚All,1〛]},{y,Min[data〚All,2〛],Max[data〚All,2〛]},​​opts,​​PlotRangeAll,PlotStyle{Opacity[0.7]},MeshTrue,PlotTheme"LightMesh",PerformanceGoal"Quality",PlotLegendsKeys[funcs]],ImageSizeMedium];
Define pure functions converter
In[21]:=
ToPureFunctions[funcs_,vars_List:{x,y}]:=​​Map[With[{f=#},f&]&,ReplaceAll[funcs,Thread[varsMap[Slot,Range[Length[vars]]]]]];
Noisy arrow wave
Generate random, "noisy wave" data
In[22]:=
{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[25]=
{1200,3}
3D list plot of the data
In[26]:=
ListPointPlot3D[data,PlotRangeAll,PlotLabel"Noisy wave data",BoxRatios{1,1,2/3},ImageSizeMedium]
Out[26]=
Data summary
In[27]:=
ResourceFunction["RecordsSummary"][data]
Out[27]=

1 column 1
Min
-5.97766
1st Qu
-2.90678
Median
-0.0115437
Mean
0.0790118
3rd Qu
3.2109
Max
5.99364
,
2 column 2
Min
-5.99067
1st Qu
-3.10103
Median
-0.0858424
Mean
-0.0158792
3rd Qu
3.04382
Max
5.99541
,
3 column 3
Min
-1.13656
1st Qu
1.51994
Mean
2.28272
Median
2.32303
3rd Qu
3.13985
Max
4.94725

Compute Quantile regression for probability 0.5 using a grid of
7×4
NURBS basis functions
In[28]:=
AbsoluteTiming​​funcs=
QuantileRegression
[data,{7,4},0.5];​​
Out[28]=
{0.354104,Null}
Plot the obtained function and data
In[29]:=
QRPlot[data,0.5First[funcs]]
Out[29]=
0.5
Quantile regression for probabilities 0.1 and 0.9
In[30]:=
probs={0.1,0.9};​​AbsoluteTiming​​funcs=AssociationThreadprobs,
QuantileRegression
[data,{7,4},probs];​​
Out[31]=
{0.60699,Null}
3D list plot of the data
In[32]:=
QRPlot[data,funcs]
Out[32]=
Count the number of points under each surface
In[33]:=
sepPoints=Map[Function[{f},Length@Select[data,#〚-1〛<First[Apply[f,Most[#]]]&]],funcs]
Out[33]=
0.1119,0.91080
Show the corresponding fractions (should correspond to the probabilities)
In[34]:=
sepFractions=N[sepPoints/Length[data]]
Out[34]=
0.10.0991667,0.90.9
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
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)

© 2025 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com