You can do this but I’m not sure why you would. And they are going to generate a lot of output if N * K is large. If you’re not going to use them in the model, it’s much more efficient to define them in generated quantities as follows.
generated quantities {
matrix[N, K] pseudo_counts;
for (n in 1:N) {
pseudo_counts[n] = alpha + x[n];
}
}
The bigger issue in this model is the centered hierarchical model for alpha. I would think the following would be more effective, because you probably want multiplicative errors in the alph:
parameters {
real mu; // no lower bound!!!
real<lower=0> sigma;
vector<offset=mu, multiplier=sigma>[K] alpha_raw;
...
transformed parameters {
vector[K] alpha = exp(alpha_raw);
...
model {
mu ~ normal(...);
sigma ~ lognormal(...);
alpha_raw ~ normal(mu, sigma);
Even in your original model, there’s no reason to constrain mu > 0. It’s too bad the dirichlet_multinomial isn’t vectorized yet in Stan or you could make this faster that way.
That may still be a challenge because the gamma(1/K, 1) has a mean of 1/K, which means that the mass is concentrated into the corners (i.e., alpha < 1) and will generate near-zero values for the components with alpha[k] < 1. It also has a mode at alpha = 0, which can be problematic. What kind of posterior estimates are you getting for alpha in this model?