1
|
4138 Views
|
|
2 Total Likes
View groups...
Share

# Use RLink to run the quantile regression function from R?

Posted 6 years ago
 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, Thad Set n, m and \[Tau] n = 1000; m = n; \[Tau] = 0.9; columns = 100; Generate data SeedRandom[1976]; 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"].
 This seems like a question for the R community...In Wolfram Language one can use: Repository function QuantileRegression Paclet "QuantileRegression" Paclet "MonadicQuantileRegression" The function pages of all three resources show how to get and visualize fit errors and/or weights for the basis functions.