I am trying to implement M-quantile regression in Stan. I am aware that the optimization problem for quantile regression is equivalent to using the asymmetric Laplace distribution (skewed double exponential). I see that this distribution is not available in Stan. I have found this forum Implement Asymmetric Laplace Distribution · Issue #2312 · stan-dev/stan · GitHub, but can’t get the proposed model to be syntactically correct. The original user function defined by @bob-carpenter is below.
real skew_double_exponential_lpdf(real y, real mu, real sigma, real tau) {
return log(tau) + log1m(tau)
- log(sigma)
- 2 * ((y < mu) ? (1 - tau) * (mu - y) : tau * (y - mu)) / sigma;
}
However, I am confused by the “?” and “:” marks in it? Looking at the formula myself I made some edits and tried to get rstan to check the model for syntax errors. I can’t get it working using the code below.
functions{
real skew_double_exponential_lpdf(real y, real mu, real sigma, real tau) {
return log(tau) + log1m(tau)
- log(sigma)
- 2 * ((y < mu) * (1 - tau) * (mu - y) + tau * (y - mu)) / sigma;
}
}
data {
int<lower=0> N; //cannot be less than 0
vector[N] y;
int<lower=0, upper=1> tau;
}
parameters {
real mu;
real<lower=0> sigma; //cannot be less than 0
}
model {
y ~ skew_double_exponential(mu, sigma, tau);
}
The error message I get is:
> rstan:::rstudio_stanc("C:/Users/n9401849/Downloads/t.stan")
Error in stanc(filename, allow_undefined = TRUE) : 0
Semantic error in 'string', line 18, column 0 to column 44:
Ill-typed arguments to '~' statement. No distribution 'skew_double_exponential' was found with the correct signature.
In addition: Warning message:
In readLines(file, warn = TRUE) :
incomplete final line found on 'C:/Users/n9401849/Downloads/t.stan'
To prove my understanding I wanted to model normally distributed data with the asymmetric Laplace distribution. Not a great idea I know, but this was more for understanding of the syntax required.
I am also aware of this, Implement skew double exponential distribution by dirmeier · Pull Request #2271 · stan-dev/math · GitHub, but am unclear how to get this on my machine.
Any help would be very appreciated.