Any ideas how to vectorize this:
// function to return Asymmetric Laplace log-probability density
functions {
real asymmetric_laplace(real y, row_vector x, real b, vector w, real p) {
real mu = sum(x' .* w) + b;
return log(p) + log1m(p) - 2 * ((y < mu) ? (1 - p) * (mu - y) : p * (y - mu));
}
}
data {
int<lower=0> N;
int<lower=0> k; // number of predictors
real<lower=0, upper=1> p; // quantile of interest
matrix[N, k] x; // predictors
vector[N] y; // response
}
parameters {
real b; // intercept
vector[k] w; // slope(s)
}
model {
vector[N] ll; // log-likelihood
for (i in 1:N){
ll[i] = asymmetric_laplace(y[i], x[i], b, w, p);
target += ll[i];
}
}