I have tried to implement quantile regression for the Boston dataset.
library(MASS)
data(Boston)
attach(Boston)
qr_res_0.9 <- rq(medv ~ lstat + rm + crim + dis,
tau = 0.9,
data = Boston)
Now, results of model summary is shown below
summary(qr_res_0.9,se="boot")
##
## Call: rq(formula = medv ~ lstat + rm + crim + dis, tau = 0.9, data = Boston)
##
## tau: [1] 0.9
##
## Coefficients:
## Value Std. Error t value Pr(>|t|)
## (Intercept) -20.75975 13.81979 -1.50218 0.13368
## lstat -0.25857 0.22411 -1.15378 0.24914
## rm 9.01335 1.58000 5.70464 0.00000
## crim -0.04028 0.11367 -0.35440 0.72319
## dis -0.94489 0.29403 -3.21355 0.00140
This does not include Psuedo R-squared/McFadden R-squared value? How can I estimate this?
What I have tried?
Referring to the discussion in Extract R^2 from quantile regression / summary()
I have implemented the following
rho <- function(u,tau=.5)u*(tau - (u < 0))
V <- sum(rho(qr_res_0.9$resid, qr_res_0.9$tau))
V
## [1] 558.4133
The R-squared should be between 0 to 1?
Apparently, you are trying to calculate the Koenker and Machado R1:
https://stats.stackexchange.com/a/129246/11849
library(MASS)
library(quantreg)
data(Boston)
#don't use `attach`
qr_res_0.9 <- rq(medv ~ lstat + rm + crim + dis,
tau = 0.9,
data = Boston)
qr_res_0.9_0 <- rq(medv ~ 1,
tau = 0.9,
data = Boston)
rho <- function(u,tau=.5)u*(tau - (u < 0))
Vhat <- sum(rho(qr_res_0.9$resid, qr_res_0.9$tau))
V0 <- sum(rho(qr_res_0.9_0$resid, qr_res_0.9_0$tau))
R1 <- 1-Vhat/V0
#[1] 0.4659297
From the linked answer:
I don't think the concept of R^2 translates well to quantile regression. You can define various more-or-less analogous quantities, as here, but no matter what you choose, you won't have most of the properties real R^2 has in OLS regression.