Skip to content

allow OrderedProbit and OrderedLogit to take vector inputs #5216

@drbenvincent

Description

@drbenvincent

At the moment, as far as I can tell, OrderedProbit and OrderedLogit break if you try to provide vector inputs for eta and sigma parameters.

For example, if you have data like this
Screenshot 2021-11-21 at 13 21 51
where your data is encoded as a vector of y values alongside a vector of grp_idx, then it looks like you cannot do this...

Approach 1 - better but doesn't work

with pm.Model() as model1:
    theta = constrainedUniform(K)
    mu = pm.Normal("mu", mu=K/2, sigma=K, shape=2)
    sigma = pm.HalfNormal("sigma", 1, shape=2)
    pm.OrderedProbit("y_obs", 
                     cutpoints=theta, 
                     eta=mu[grp_idx], 
                     sigma=sigma[grp_idx], 
                     observed=y)

We have a common set of cutpoints theta, but each of the groups has different eta and sigma. We try to pass in a vector of eta and sigma values using advanced indexing. But this does not work 🙁

Approach 2 - split into separate likelihood terms

If we cannot pass in vectors to eta or sigma, then the solution that works is to encode the data differently so that you now have observations from one group as y1 and observations from another group as y2

with pm.Model() as model2:
    theta = constrainedUniform(K)
    mu = pm.Normal("mu", mu=K/2, sigma=K, shape=2)
    sigma = pm.HalfNormal("sigma", 1, shape=2)
    pm.OrderedProbit("y1_obs", 
                     cutpoints=theta, 
                     eta=mu[0], 
                     sigma=sigma[0], 
                     observed=y1)
    pm.OrderedProbit("y2_obs", 
                     cutpoints=theta, 
                     eta=mu[1], 
                     sigma=sigma[1], 
                     observed=y2)

This approach does work, but makes model specification cumbersome, and doesn't scale well with more groups.

Not crucial for this issue, but the constrainedUniform is a proposed new distribution, outlined in pymc-devs/pymc-extras#32.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions