# Condition on function of parameter

Hi All,

Suppose I want to further condition a posterior distribution p(\theta | X) on a function or predicate of the parameter. For example, suppose parameter \theta \in \mathbb{R}^2 and I want to sample from

p(\theta | X, \theta_1 < \theta_2)

my question: If \theta has some marginal/prior distribution such that I can’t write down the distribution p(\theta | \theta_1 < \theta_2), would that indicate that I couldn’t sample from such a distribution in Stan?

That is, do I need to be able to write down some sampling expression for \theta using ~ and a normalized distribution for \theta in the model block? Or would there be an alternate solution, perhaps by explicitly modifying the expression proportional to the log-posterior density with an indicator of this \theta_1 < \theta_2 predicate?

I’m curious if it’s possible to express this in Stan, even though I understand it would in general be hard to sample from.

Apologies if this is a duplicate! I saw some discussion with constraints in transformed parameters, but that seems different from what I’m asking.

very best,
mark

Well this isn’t a direct answer to your question, but Stan handles sampling in constrained spaces by sampling in unconstrained spaces and doing a change of variables into the constrained space.

Stan’s underlying sample is always working in an unconstrained space, so you can build all sorts of weird constraints on top of this, but at the lowest level it’s unconstrained and it’s a bunch of change of parameters.

The different constraints and how they work are documented there: Stan Reference Manual

Sometimes you can sample another distribution and get the distribution you want via a transform, like “Reparameterizing the Cauchy” here: Stan User’s Guide