This is an old version, view current version.

31.7 Adding group-level predictors

If there are group-level predictors, such as average income in a state, or vote share in a previous election, these may be used as predictors in the regression. They will not pose an obstacle to poststratification because they are at the group level. For example, suppose the average income level in the state is available as the data variable

array[50] real<lower=0> income;

then a regression coefficient psi can be added for the effect of average state income,

real psi;

with a fixed prior,

psi ~ normal(0, 2);

This prior assumes the income predictor has been standardized. Finally, a term is added to the regression for the fixed predictor,

y ~ bernoulli_logit(alpha + beta[age] + ... + delta[state]
                    + income[state] * psi);

And finally, the formula in the generated quantities block is also updated,

expect_pos
  += P[b, c, d]
     * inv_logit(alpha + beta[b] + gamma[c] + delta[d]
             + income[d] * psi);

Here d is the loop variable looping over states. This ensures that the poststratification formula matches the likelihood formula.