Should weights be applied in generated quantities block in stan? I want to do predictions via generated quantities block in stan. I have two questions:


*

*Should the weights be applied again in the generated quantities 
block in addition to the likelihood in the model block? (a) or (b)?

*What values of the variable weights should I use in the predictions (i.e., in generated quantities block)?


(a)
model{
      ...
      target +=  weights[i] * binomial_lpmf(...);
      ...
      }

generated quantities{
      ...
      y_pred[i] = weights[i] * inv_logit(...);
      ...
      }

(b)
 model{
        ...
        target +=  weights[i] * binomial_lpmf(...);
        ...
        }

 generated quantities{
        ...
        y_pred[i] = inv_logit(...);
        ...
        }

Thanks in advance for any help. Also, see here and here.
 A: If I understand it correctly, you are trying to use weights the same way brms does (as discussed e.g. here: https://discourse.mc-stan.org/t/weights-in-brm/4278/5). In this use case, weighting just means you treat an observation with weight 2 acts exactly as having the same observation twice in the dataset.
In this case, it doesn't make much sense to use the weights in posterior predictions - if you added the observation multiple times into your dataset, it wouldn't change the way you make predictions.
EDIT: (thx to @baruuum for pointing this out)
Weights could possibly enter the picture when you compute functions of the predictions (e.g. posterior mean). Then it could make sense to weigh the predictions (e.g. compute weighted mean). The weighted predictions themselves are still IMHO meaningless: if the unweighted prediction is that probability of success is 0.8 and the weight is 2, it doesn't make sense to say that the weighted probability is 1.6.
Also keep in mind that the posterior unweighted mean answers the question "What responses would I expect, if I got a new dataset with the same predictors?" while the weighted mean answers "What responses would I expect, if I got a new dataset with the same predictors and the same weights?" Which question is more interesting depends on what your weights actually represent and your research question.
