Comparing Parameters

Suppose we have a model like

y ~ normal(b[1] + b[2]*x1 + b[3]*x2,sigma)

I would like to make posterior probability statements of the form P(b[2] > b[3] | data).

Can I get that from (using matlabstan)
z2 = fit.extract(‘permuted’,true).b(:,2));
z3 = fit.extract(‘permuted’,true).b(:,3));

sum(z2 > z3)/length(z2)


Yes. Although you shouldn’t get in the habit of permuting in the extract call. It doesn’t affect anything here but it’s bad practice.

Thanks very much!

You can also get them by adding the following to generted quantities:

generated quantities {
  int<lower=0, upper=1> z2_gt_z3 = z2 > z3;

and then the posterior mean of z2_gt_z3 is the probability you’re after. That’s because event probabilities are just expectations of indicator functions.