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

Symbols

  • NURBSBasis
  • QuantileEnvelope
  • QuantileEnvelopeRegion
  • QuantileRegressionFit
  • QuantileRegression
Quantile regression over weather time series
Introduction
Estimation of conditional density distributions
Quantile regression over heteroscedastic data
​
Introduction
In this notebook we show two primary use cases of for Quantile Regression (QR):
◼
  • Fitting regression quantiles over
    heteroscedastic data
  • ◼
  • Estimation of conditional density distributions
  • Quantile regression over heteroscedastic data
    Load the paclet
    In[242]:=
    Needs["AntonAntonov`QuantileRegression`"]
    Take temperature data
    In[243]:=
    tsTemp=WeatherData[{"Atlanta","Georgia"},"Temperature",{{2018,1,1},{2023,1,1},"Day"}]
    Out[243]=
    TimeSeries
    Time:
    01 Jan 2018
    GMT
    -4
    to
    01 Jan 2023
    GMT
    -4
    Data points: 1827
    
    Plot time series points
    In[244]:=
    opts={ImageSizeLarge,AspectRatio1/2,PlotTheme"Detailed",JoinedFalse};DateListPlot[tsTemp,opts]
    Out[244]=
    Data summary
    In[245]:=
    ResourceFunction["RecordsSummary"][tsTemp["Path"]]
    Out[245]=
    
    1 column 1
    Min
    3.72375×
    9
    10
    1st Qu
    3.76317×
    9
    10
    Mean
    3.80264×
    9
    10
    Median
    3.80264×
    9
    10
    3rd Qu
    3.8421×
    9
    10
    Max
    3.88152×
    9
    10
    ,
    2 column 2
    23.89
    °C
    16
    24.22
    °C
    16
    12.78
    °C
    14
    22.78
    °C
    12
    25
    °C
    12
    23.33
    °C
    11
    (Other)
    1746
    
    Find regression quantiles for 0.1, 0.5, 0.9
    In[246]:=
    AbsoluteTiming​​probs={0.1,0.5,0.9};​​qFuncs=
    QuantileRegression
    [QuantityMagnitude[tsTemp["Path"]],16,probs];​​
    Out[246]=
    {0.953409,Null}
    Plot time series points with fitted regression quantiles
    In[247]:=
    DateListPlot[{tsTemp["Path"],Map[Function[{f},{#,f[#]}&/@tsTemp["Times"]],qFuncs]},opts,Joined{False,True,True,True},PlotLegends{"data",Sequence@@probs}]
    Out[247]=
    Remark: It should be obvious from the plot above that the time series data is heteroscedastic.
    Count the number points under each surface
    In[248]:=
    sepPoints=Association@MapThread[Function[{p,f},pLength[Select[QuantityMagnitude[tsTemp["Path"]],#〚2〛<f[#〚1〛]&]]],{probs,qFuncs}]
    Out[248]=
    0.1182,0.5915,0.91647
    Show the corresponding fractions (should correspond to the probabilities)
    In[249]:=
    sepFractions=N[sepPoints/Length[tsTemp["Path"]]]
    Out[249]=
    0.10.0996169,0.50.500821,0.90.901478
    Estimation of conditional density distributions
    Find regression quantiles for a "comprehensive" set of probabilities
    In[250]:=
    AbsoluteTiming​​probs=Sort[Join[Range[0.1,0.9,0.1],{0.01,0.99}]];​​qFuncs=
    QuantileRegression
    [QuantityMagnitude[tsTemp["Path"]],16,probs];​​
    Out[250]=
    {2.37679,Null}
    Plot time series points with fitted regression quantiles
    In[251]:=
    DateListPlot[{tsTemp["Path"],Map[Function[{f},{#,f[#]}&/@tsTemp["Times"]],qFuncs]},opts,Joined{False,True,True,True},PlotLegends{"data",Sequence@@probs}]
    Out[251]=
    Reconstruct the CDF distribution at the focus point (January 1st, 2020)
    In[252]:=
    focusPoint=AbsoluteTime[{2020,1,1}];​​xs=Through[qFuncs[focusPoint]];​​cdfPairs=Transpose[{xs,probs}];
    Plot the empirical CDF
    In[255]:=
    ListLinePlotcdfPairs,
    
    Out[255]=
    In order to plot the corresponding PDF function define a CDF reconstruction function
    In[256]:=
    CDFEstimate[t0_]:=CDFEstimate[probs,qFuncs,t0];​​​​​​CDFEstimate[qs_,qFuncs_,t0_]:=Interpolation[Transpose[{Through[qFuncs[t0]],qs}],InterpolationOrder1];
    Plot empirical PDF

    © 2025 Wolfram. All rights reserved.

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