Unknown joint distribution, known conditional marginals

Hi all, I’m a pymc3 newbie :slight_smile:

Suppose I have a univariate r.v. X and a bivariate r.v Y=(Y1,Y2)
X is unobserved, both Y1 and Y2 are observed.

Assume I know the conditional marginal distributions given X = x for both Y1 and Y2, let’s say these are

p(Y1 | X = x) = f(x, theta)
p(Y2 | X = x) = g(x)

Aim here is to estimate theta (assuming a prior for it)
How can I specify a model in pymc3 using these marginals?

This looks like a job for DensityDist.

def myfun_f(y, x, theta):
    ...  # p(y1 | x, theta)

def myfun_g(y, x):
    ... # p(y2 | x)

with pm.Model() as model:
    X = pm.Normal('X', 0., 1.)  # or whatever prior
    theta = pm.HalfNormal('theta', 2.)  # or whatever prior
    def logp_f(y_):
        return log(myfun_f(y_, X, theta))
    def logp_g(y_):
        return log(myfun_g(y_, X))
    Y1 = pm.DensityDist('Y1', logp_f, observed={'y_': y1})
    Y2 = pm.DensityDist('Y2', logp_g, observed={'y_': y2})

2 Likes

thanks :pray: