Message Boards Message Boards

Add the ["BestFitParameters"] property to a function from a package?


I am building a MonteCarlo simulation to compare the performance of Least Squares and Quantile Regressions. To automate the notebook, I need to be able to extract the parameters from the regressions. For the Least Squares method, I can run a LinearModelFit and use the property ["BestFitParameters"]. For Quantile Regressions, I run the QuantileRegressionFit from the package below (written by Anton Antonov - Quantile regression Mathematica package, source code at GitHub, [MathematicaForPrediction][1], package QuantileRegression.m, (2013)). However, the function doesn't come with the same property, ["BestFitParameters"], so I don't know how to extract the parameters.

Can anyone help me with extracting the optimal parameters for the QuantileRegressionFit function?

Thanks in advance,

2 months ago

I contacted the author of this package (Anton Antonov) and not only did he reply in very short notice, he was kind to offer a solution, to which I post the code below. If you are interested in learning how the QuantileRegressionFit function works, check out Anton's GitHub.

Cheers, Thad

In[66]:= data = Array[Prime, 300];
data = Transpose[{Range[Length[data]], data}];

In[68]:= funcs = {1, x, Log[x]};

In[70]:= qres = QuantileRegressionFit[data, funcs, x, {0.5, 0.7}]

Out[70]= {3.16622*10^-10 + 6.14692 x + 1.9274*10^-10 Log[x], 
 4.9249*10^-12 + 6.34137 x + 8.47339*10^-13 Log[x]}

In[71]:= MapThread[Join, {Map[Cases[#, _?NumberQ] &, 
    qres] /. {} -> {0}, 
  Outer[Coefficient, qres, DeleteCases[funcs, _?NumberQ]]}]

Out[71]= {{3.16622*10^-10, 6.14692, 1.9274*10^-10}, {4.9249*10^-12, 
  6.34137, 8.47339*10^-13}}
2 months ago

Group Abstract Group Abstract