In Stan we’ve been adding vectorized glms for common models, and if you use them, you will get the distinction between the intercept and the slope terms. Here are a few examples:
The naming convention here is <distribution>_<link function>_glm - I’m not sure we have a comprehensive list of all the _glm distributions anywhere, nor is this mentioned in the Stan User’s Guide and it should be (will file an issue on this).
Here’s an example of how to set this up for simple linear regression with 2 predictors - this is the non-hierarchical version of the model for the radon dataset from Gelman and Hill 2007, chapter 12.
data {
int<lower=1> N; // observations
int<lower=1> J; // counties
array[N] int<lower=1, upper=J> county;
vector[N] y; // radon
vector[N] x; // floor
vector[N] u; // uranium
}
transformed data {
matrix[N, 2] xs = [x', u']';
}
parameters {
vector[J] alpha;
vector[2] beta;
real<lower=0> sigma;
}
transformed parameters {
vector[N] alphas = alpha[county];
}
model {
y ~ normal_id_glm(xs, alphas, beta, sigma);
alpha ~ normal(0, 2.5);
beta ~ normal(0, 2.5);
sigma ~ normal(0, 5);
}
BRMS is manipulating the generated stanfit object and renaming the parameters for you. cf brms/rename_pars.R at 811d68a447823c29c9af9dc8fd6cfbebe39cb249 · paul-buerkner/brms · GitHub
(update: filed an issue on the docs for this: give examples and cross-reference vectorized glms in SUG · Issue #593 · stan-dev/docs · GitHub)