Message Boards Message Boards


Use RLink to run the quantile regression function from R?

Posted 3 months ago
0 Replies
1 Total Likes

I am running a Monte Carlo simulation to compare errors from least squares method and quantile regression.

I have generated the data as per below (y = x Beta + error), for three different beta's. (\[Tau] is my quantile level)

The data is ready for LinearModelFit. But how can I apply the rq function in R from the quantreg library to my data?

I appreciate your help. This community is awesome.

Thanks in advance,


Set n, m and \[Tau]

n = 1000;
m = n;
\[Tau] = 0.9;
columns = 100;

Generate data


xdata = Table[RandomVariate[NormalDistribution[], n], columns];

\[Epsilon]data = Table[RandomVariate[NormalDistribution[], n], columns];

\[Beta]data = {1/3, 1, 3};

num\[Beta] = Length[\[Beta]data];

ydata = Table[xdata \[Beta]data[[k]] + \[Epsilon]data, {k, num\[Beta]}];

data = Table[
   Transpose[{xdata[[k]],ydata[[q, k]]}], {q, num\[Beta]}, {k, columns}];

Run Least Squares

lsFunc = Table[LinearModelFit[#, x, x] & /@ data[[q]], {q, num\[Beta]}];

Moreover, I need the ability to extract the parameters from the quantile regression results, like I can do with LinearModelFit["BestFitParameters"] and ["FitResiduals"].

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract