Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

R Programming/Quantile Regression

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Quantile regression is a very old method which has become popular only in the last years thanks to computing progress. One of the main researcher in this area is also a R practitioner and has developed a specific package for quantile regressions (quantreg)Roger Koenker (2010). quantreg: Quantile Regression. R package version 4.50. http://CRAN.R-project.org/package=quantregRoger Koenker's personal webpage. In theory, Quantile regression are also linear and thus could have been included in the Linear regression page. However, this is a very specific topic and we think that it is worth writing a specific page for this topic. Simple quantile model We simulate from a simple quantile model. We first generate a uniform error term u and a covariate x. N <- 10^3 u <- runif(N) x <- 1 + rnorm(N) y <- qnorm(u, mean = 0, sd = 2) + qnorm(u, mean = 1, sd = 1) * x We estimate the quantile model for some values of tau (the quantile) and plot the coefficients : q1 <- rq(y ~ x, tau = seq(.1,.9,.1)) summary(q1) plot(q1) We then plot the scatterplot, the predicted values using a standard linear model and the predicted values using a quantile linear model : plot(x,y, col = "grey") m1 <- lm(y ~ x) abline(m1, col = "red") taus <- seq(.1,.9,.1) for (i in 1:length(taus)){ abline(rq(y ~ x, tau = taus[i]), col = "blue") } grid() We can also estimate the model for all quantiles at the same time : q2 <- rq(y ~ x, tau = -1) plot(q2, nrow = 2, ncol = 1) Computing time For large data sets it is better to use the "fn" or "pfn" method. > N <- 10^5 > u <- runif(N) > x <- 1 + rnorm(N) > y <- qnorm(u, mean = 0, sd = 2) + qnorm(u, mean = 1, sd = 1) * x > system.time(rq(y ~ x, tau = .5, method = "br")) user system elapsed 1.48 0.00 1.48 > system.time(rq(y ~ x, tau = .5, method = "fn")) user system elapsed 0.60 0.00 0.61 > system.time(rq(y ~ x, tau = .5, method = "pfn")) user system elapsed 0.30 0.00 0.29 Resources Koenker, Roger (2005) Quantile Regression, Cambridge University Press. 0-521-60827-9 References Nonparametric Methods Binomial Models