Skip to contents

The purpose of this vignette is to present the calculations for a peicewise quantile regression where for each time step there are multiple independent observations.

In the follow variables identified by Greek letters are considered unknown.

Quantile regression

Data belongs to group kk whose time stamps are the set tTkt \in T_{k} which have common regression parameters θk\theta_{k} and residual variance σk\sigma_{k} At time step tt the vector of iid observations 𝐲t={yt,1,,tt,nt}\mathbf{y}_{t}=\left\{y_{t,1},\ldots,t_{t,n_{t}}\right\} is explained by the design matrix 𝐗t\mathbf{X}_{t}.

For a given quantile τ\tau and using the check function ρ(u,τ)=u(τI(u<0))\rho\left(u,\tau\right) = u\left(\tau - I\left(u<0\right)\right) Koenker and Bassett (1978) show that an estimate of θ\theta in QR model can be obtained by solving the convex optimization problem minθ(i=1ntρ(𝐲t,i𝐗t,i(𝐦t+θk),τ)) \min_{\theta} \left( \sum_{i=1}^{n_{t}} \rho\left(\mathbf{y}_{t,i}- \mathbf{X}_{t,i}\left(\mathbf{m}_{t}+\theta_{k}\right),\tau\right) \right)

Solving this gives the maximum likelihood estimator of the asymmetric Laplace (AL) distributions (Geraci and Bottai, 2007 and Yu, Lu, and Stander, 2003) which has likelihood L(𝐲t|θk)=τnt(1τ)ntexp(t=1ntρ(𝐲t,i𝐗t,i(𝐦t+θk),τ)) L\left(\mathbf{y}_{t} \left| \theta_k\right.\right) = \tau^{n_{t}}\left(1-\tau\right)^{n_{t}}\exp\left(- \sum_{t=1}^{n_{t}} \rho\left(\mathbf{y}_{t,i}- \mathbf{X}_{t,i}\left(\mathbf{m}_{t}+\theta_{k}\right),\tau\right) \right)

With 𝐲̂t=𝐲t𝐗t𝐦t\hat{\mathbf{y}}_{t} = \mathbf{y}_{t} - \mathbf{X}_{t} \mathbf{m}_{t} the log likelihood is given by l(𝐲t|θk,σk)=njlog(τ(1τ))i=1ntρ(𝐲̂t,i𝐗t,iθk,τ) l\left(\mathbf{y}_{t} \left| \theta_k,\sigma_k \right.\right) = n_{j}\log \left(\tau \left(1-\tau\right)\right) - \sum_{i=1}^{n_{t}} \rho\left(\hat{\mathbf{y}}_{t,i} - \mathbf{X}_{t,i}\theta_{k},\tau\right)

The log-likelihood of 𝐲tTk\mathbf{y}_{t \in T_{k}} is with nk=tTkntn_{k}=\sum\limits_{t\in T_{k}} n_{t}l(𝐲tTk|θk,σk,𝐗t)=nklog(τ(1τ))tTki=1ntρ(𝐲̂t,i𝐗t,iθk,τ) l\left(\mathbf{y}_{t \in T_{k}} \left| \theta_k,\sigma_k,\mathbf{X}_{t}\right.\right) = n_{k}\log\left(\tau \left(1-\tau\right)\right) - \sum_{t \in T_{k}}\sum_{i=1}^{n_{t}} \rho\left(\hat{\mathbf{y}}_{t,i} - \mathbf{X}_{t,i}\theta_{k},\tau\right)

with the cost being twice the negative log likelihood plus a penalty β\beta giving

C(𝐲tTk|μt,mk,σk,sk)=tTki=1ntρ(𝐲̂t,i𝐗t,iθk,τ)2nklog(τ(1τ))+β C\left(\mathbf{y}_{t \in T_{k}} \left| \mu_t,m_k,\sigma_k,s_k\right.\right) = \sum_{t \in T_{k}}\sum_{i=1}^{n_{t}} \rho\left(\hat{\mathbf{y}}_{t,i} - \mathbf{X}_{t,i}\theta_{k},\tau\right) - 2n_{k}\log\left(\tau \left(1-\tau\right)\right) + \beta

Baseline: No Anomaly

Here θk=0\theta_{k}=0 and is no penalty so β=0\beta = 0

Collective anomaly

Estimate θk\theta_{k} using ??? and then with penalty β\betaC(𝐲tTk|μt,mk,σk,sk)=tTki=1ntρ(𝐲̂t,i𝐗t,iθ̂k,τ)2nklog(τ(1τ))+β C\left(\mathbf{y}_{t \in T_{k}} \left| \mu_t,m_k,\sigma_k,s_k\right.\right) = \sum_{t \in T_{k}}\sum_{i=1}^{n_{t}} \rho\left(\hat{\mathbf{y}}_{t,i} - \mathbf{X}_{t,i}\hat{\theta}_{k},\tau\right) - 2n_{k}\log\left(\tau \left(1-\tau\right)\right) + \beta

Point Anomaly

if nt>0n_t > 0 then could proceed like a collective anomaly. Otherwise select θ̂\hat{\theta} such that $\mathbf{y}}_{t,i} - \mathbf{X}_{t,i}\hat{\theta}_{k}= 0$