This is part III of the quantile regression series. Part I and part II show the Bayesian quantile regression using the asymmetric Laplace distribution, augmented scheme, and score. In this post I’m going to show the multiple quantile regression given in Wu and Narisetty (2021), which is a follow up to part II.
Multiple quantile regression with score
The score method includes the regressors into the objective function as \[
s_\tau(\beta) = \sum_{i=1}^{n} x_i \psi_\tau(y_i - x_i^{\top}\beta).
\] where \(\psi_\tau(u) = \tau - I(u < 0)\).
Wu and Narisetty (2021) consider the following “working” likelihood \[
\mathcal{L}(y \mid x,\, \beta) = C \exp\bigg(-\frac{1}{2n} s_\tau(\beta)^{\top} W s_\tau(\beta) \bigg),
\] where \(W\) is a \(p \times p\) positive definite weight matrix, and C is a constant free of \(\beta\). The quadratic form and the given objective function implies that the quantile estimator is maximized at the typical quantile estimate.
The \(W\) matrix for multiple quantiles is given as
\[
W = (Q \otimes G )^{-1}, \text{ where } Q = (\min(\tau_i, \tau_j) - \tau_i \tau_j)_{ij}, \; G = \frac{1}{n}\sum_{i=1}^n x_i x_i^{\top}.
\]
A nice property of \(W\) is that it depends all on user input data so can be constructed outside of the MCMC iterations.
Score function
The following Stan model implements the multiple \(\tau\) code.
Show the code
functions{matrix kronecker(matrix A, matrix B) {matrix[rows(A) *rows(B), cols(A) *cols(B)] C;int m =rows(A);int n =cols(A);int p =rows(B);int q =cols(B);for (i in1:m) {for (j in1:n) {int row_start = (i -1) * p +1;int row_end = (i -1) * p + p;int col_start = (j -1) * q +1;int col_end = (j -1) * q + q; C[row_start:row_end, col_start:col_end] = A[i, j] * B; } }return C;}vector q_loss(real q, vector u){return (abs(u) + (2* q -1) * u); }vector score(vector q, vector y, matrix x, array[] vectorbeta) {int N =num_elements(y);int P =num_elements(beta[ , 1]);int K =num_elements(q);matrix[K, P] out;for (k in1:K) { out[k] = transpose(transpose(x) * q_loss(q[k], y - x *to_vector(beta[ ,k]))); }returnto_vector(out); }matrix make_w (matrix x, vector q) {int N =rows(x);int P =cols(x);int m =num_elements(q);matrix[m * P, m * P] out;matrix[m, m] Q;matrix[P, P] G =crossprod(x) ;// G[1:P, 1] /= log(N);// G[1, 2:P] = transpose(G[2:P, 1]);for (i in1:m) { Q[i, i] = q[i] * (1- q[i]);for (j in1:i -1) { Q[i, j] =min([q[i], q[j]]) - q[i] * q[j]; Q[j, i] = Q[i, j]; } }return kronecker(N *inverse(G), inverse(Q)); }}data {int N; // Number of observationint P; // Number of predictorsint K; // Number of quantilesvector[K] q;vector[N] y; matrix[N, P] x;}transformed data {matrix[K * P, K * P] W = make_w(x, q);}parameters {// can add ordered constraint herearray[P] vector[K] beta;real<lower=0> sigma;}model {vector[K * P] score_vec = score(q, y, x, beta) / sigma;for (i in1:K) beta[, i] ~ normal(0, 4); sigma ~ exponential(1);target+=-quad_form(W, score_vec) / (2* N * K) - K * N *log(sigma);}
Call: rq(formula = y ~ x + xsq, tau = 0.05, data = dat)
tau: [1] 0.05
Coefficients:
Value Std. Error t value Pr(>|t|)
(Intercept) 0.76514 0.30477 2.51058 0.01259
x 1.19143 0.24792 4.80577 0.00000
xsq -0.13371 0.04037 -3.31187 0.00104
Show the code
summary(out_freq_2, se ="iid")
Call: rq(formula = y ~ x + xsq, tau = 0.5, data = dat)
tau: [1] 0.5
Coefficients:
Value Std. Error t value Pr(>|t|)
(Intercept) 2.80112 0.59354 4.71936 0.00000
x 1.15865 0.48282 2.39976 0.01703
xsq -0.07523 0.07863 -0.95677 0.33947
Show the code
summary(out_freq_3, se ="iid")
Call: rq(formula = y ~ x + xsq, tau = 0.95, data = dat)
tau: [1] 0.95
Coefficients:
Value Std. Error t value Pr(>|t|)
(Intercept) 7.23563 0.67142 10.77659 0.00000
x -0.48165 0.54617 -0.88186 0.37857
xsq 0.24602 0.08895 2.76597 0.00603
References
Wu, Teng, and Naveen N. Narisetty. 2021. “Bayesian Multiple Quantile Regression for Linear Models Using a Score Likelihood.”Bayesian Analysis 16 (3): 875–903. https://doi.org/10.1214/20-BA1217.