Quantile Regression - Plot is odd

2 views (last 30 days)
LM_BU
LM_BU on 5 Feb 2019
Edited: LM_BU on 5 Feb 2019
Hello,
I am applying (experimentally, for now) quantile regression on my data, as they have violated both normality of residuals and homogeneity of variances with Levene's tests using linear regression.
Following the example from the documentation, I am unable to retrieve a proper line. Please fine the code below, as well as the plot and compare with the plot given in the documentation page.
rng(1);
QRMdl = TreeBagger(100,X,Y,'Method','regression');
qrPred = quantilePredict(QRMdl,X);
LSMdl = fitlm(X,Y);
figure;
plot(X,Y,'o');
h = gca;
xlim = h.XLim';
hl = legend('Data');
title('Quantile Regression')
hold on;
plot(xlim,[ones(2,1) xlim]*LSMdl.Coefficients.Estimate,'LineWidth',2);
hl.String{2} = 'Linear Regression';
hold on;
plot(X,qrPred,'LineWidth',1);
hl.String{3} = 'Quantile Line';
hold off;
I also wanted to ask, if you want to add an independent variable (group) in the above method (X is a covariate, Y are the data). How would I add the independent variable to X? As an extra column, by multiplying it by X or by using a different approach? Essentially, I am interested in the interaction between the group and the covariate.
Any help would be appreciated.

Answers (0)

Products


Release

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!