3.5

3.5 | 2 ratings Rate this file 82 Downloads (last 30 days) File Size: 2.67 KB File ID: #32115
image thumbnail

quantreg.m - quantile regression

by

 

07 Jul 2011 (Updated )

Quantile regression with bootstrapping confidence intervals

| Watch this File

File Information
Description

Quantile Regression

  USAGE: [p,stats]=quantreg(x,y,tau[,order,nboot]);
  
  INPUTS:
    x,y: data that is fitted. (x and y should be columns)
         Note: that if x is a matrix with several columns then multiple
         linear regression is used and the "order" argument is not used.
    tau: quantile used in regression.
    order: polynomial order. (default=1)
    nboot: number of bootstrap surrogates used in statistical inference.(default=200)
 
  stats is a structure with the following fields:
       .pse: standard error on p. (not independent)
       .pboot: the bootstrapped polynomial coefficients.
       .yfitci: 95% confidence interval on polyval(p,x)
 
 
  Note: uses bootstrap on residuals for statistical inference. (see help bootstrp)
  check also: http://www.econ.uiuc.edu/~roger/research/intro/rq.pdf
 
  EXAMPLE:
  x=(1:1000)';
  y=randn(size(x)).*(1+x/300)+(x/300).^2;
  [p,stats]=quantreg(x,y,.9,2);
  plot(x,y,x,polyval(p,x),x,stats.yfitci,'k:')
  legend('data','2nd order 90th percentile fit','95% confidence interval','location','best')
  
  For references on the method check e.g. and refs therein:
  http://www.econ.uiuc.edu/~roger/research/rq/QRJEP.pdf
 
   Copyright (C) 2008, Aslak Grinsted

Required Products Statistics Toolbox
MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
22 Jan 2014 Antony

Hi, first of all, thank you very much for the code.

When I run the code I get the following message:

"Exiting: Maximum number of function evaluations has been exceeded
- increase MaxFunEvals option.
Current function value: 3183.464509 "

I get this message a number of times with just the current function value changing.
While it is not an error message and I still obtain the estimations I need, I was wondering if this had any influence on the validity of my results.

Thank you in advance for anyone who can help me out here.

21 Aug 2012 Wolfgang Schwanghart

Excellent. Well written help and code! Runs as advertised!

17 Apr 2012 Satis

If X and y have some missing observations, then

[p,stats]=quantreg(X,y,.9); does not work. I got error message.

Could you please suggest me how to resolve this problem??

08 Aug 2011 Aslak Grinsted

@mohammad: The code does do MLR. Here's an example with multiple predictors:

X=randn(100,4);
y=X*[4 2 4 1]'+randn(100,1)*.2;
[p,stats]=quantreg(X,y,.9);

07 Aug 2011 Mohammad

In fact I wanted to run this M-file for multi column X, but I got error, so it is not implement for MLR? if it is , could you please put an example? because when I do not mention Order , I get error when i mention it is not MLR

08 Jul 2011 Aslak Grinsted

Thanks for the comment, and suggestions for improvement. I've just uploaded a new version (it should be online shortly).

07 Jul 2011 AS

One unexpected thing with this code. Suppose I have a Y vector and want to regress it on one explanatory variable, but also include a constant in my regression. Then my X matrix has 2 columns, the first column is just ones, the second is the explanatory variable. It should still be possible to plot this along with the results from the regression.

Currently, however, if you run:
quantreg([ones(length(x),1) x], y,.5)
You get an error because it tries to plot it, but order has been set (line 44) to [], so things get messed up.

Additionally, the plots that do get produced look odd because the default is to draw lines between all of the points, which usually isn't what you want. For example, this doesn't look like what it should:
x=randn(1000,1);
y=1+5*x+randn(1000,1);
quantreg(x,y,0.5)

Finally, there's a problem with the error checking of inputs (lines 41-47) because it's all one big if-else statement. If you only put in three inputs, then line 44 runs and order gets set to [], but then the program exits the if-else statement and so Nboot never gets set correctly. You should split these up into separate if statements because if there are only 3 inputs then you need to set both order and Nboot.

Updates
08 Jul 2011

Fixed a few issues with input parameter parsing.

08 Jul 2011

Fixed another small bug.

Contact us