0
$\begingroup$

I want to do predictions via generated quantities block in stan. I have two questions:

  1. Should the weights be applied again in the generated quantities block in addition to the likelihood in the model block? (a) or (b)?
  2. 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.

$\endgroup$
2
+50
$\begingroup$

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.

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ would adding the weights directly in the generated quantities block not be convenient for the calculations of quantities of the posterior predictive distribution (such as the mean, etc.)? Otherwise, you'd have to expand each of the draws or add the weights to each of them afterwards. $\endgroup$ – baruuum May 21 '19 at 0:15
  • $\begingroup$ @baruuum I see your point - if you calculate posterior mean etc. in generated quantities (which is IMHO rare), it could make sense. Will edit the answer. $\endgroup$ – Martin Modrák May 21 '19 at 6:05
  • $\begingroup$ Thanks, @MartinModrák for the answer. Very helpful insight. Truly appreciate for clarifying this. $\endgroup$ – Krantz May 21 '19 at 8:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.