Solved – Estimation of quantile regression by hand

excelquantile regressionquantilesregressionregression coefficients

Let us suppose we have following data

x   y
1   5
2   4
3   5
4   4
5   7

I would like to do Quantile regression in excel, I have found following information about given method

enter image description here

based on this information let choose $q=75$ or 75% quantile, in excel I have done following structure, first create dummy variable based on indicator function and also choose arbitrary values of alpha and beta
$$\alpha=0.1 $$
$$\beta=0.2 $$
dummy variable has been filled using following method

enter image description here

initially all values are zero, now I have calculated one column for sum

enter image description here

and finally I have calculated sum of all those values, and then using solver I have estimated coefficients which minimizes sum, I have got following values and result

enter image description here

please tell me if I am wrong, and also statistically could you explain me please what does this mean? What does those coefficient describe in terms of quantile?

Best Answer

(A little bit more a long comment than an answer, but I'm missing the repetition to comment)

First, your calculation of the loss appears to be correct (this is R code):

y <- c(5, 4, 5, 4, 7)
x <- c(1, 2, 3, 4, 5)
a <- 0.217092
b <- 1.594303
tau <- 0.75
f <- function(par, y, x, tau) {
    sum((tau - (y  <= par[1] + par[2]*x)) * (y - (par[1] + par[2]*x)))  
}
f(par=c(a, b), y=y, x=x, tau=tau)
[1] 3.782908

Second, there seems to be a problem with the Excel solver. Using R's optimizer, we find:

optim(c(0.1, 0.2), f, y=y, x=x, tau=tau)
$par
[1] 4.4999998 0.4999998

$value
[1] 1.250001

$counts
function gradient 
 143       NA 

so the loss is lower using optim than using Excel's solver.

Third, note that your approach of estimating quantile regression is inferior to solving the corresponding linear program. Anyway, a comparison with Roger Koenker's quantregpackage yields:

library(quantreg)
rq(y ~ x, tau=tau)
Call:
rq(formula = y ~ x, tau = tau)

Coefficients:
(Intercept)           x 
        4.5         0.5 

Degrees of freedom: 5 total; 3 residual

which is very close to the solution of R's optim solver.

About your other question: could you elaborate what exactly you want to understand?

Related Question