Hierarchical model with a mixture of nested and non-nested levels


I’ve recently learnt how to implement an n-level hierarchical model in PyMC3 from this post. In this example, all levels are nested (Global -> Degree -> State -> County). However, I’m trying to solve a problem that requires a mixture or nested and non-nested levels. For example, I might have something like (Global ->State -> County) and (Global -> Degree) in parallel. Is there a tutorial where I can learn how to implement this in PyMC3?


1 Like

Did you find any information about this?

I am tackling the same problem… well, trying to.

My concept is that I have a product development happening, and:

  • there is a general Development process (’_d’ priors) guiding the design and manufacturing efforts
  • there are focused teams (’_t’ priors) developing the product (e.g., mechanical, electrical,…)
  • there is some testing at the individual design item level (’_i’)
  • there is some testing at the more integrated levels sub-function (’_sf’), and function (’_f’) levels
    – Note: some items will support multiple sub-functions/functions

The influence needs to flow from the test results back though to the design teams and over-all process.

I have a hard time trying to interpret results from a linear regression type approach on these problems.

So, I am trying indexing and stacking of tensors:

    try_theata_group = dict()
    one = tt.constant(1.0)
    for sf_id, sf in enumerate(subfunc_uniques):
            try_theata_group[sf_id] = one
            items_in_subfunc = grand_idx['item_idx'][grand_idx['subfunc_idx']==subfunc_uniques.get_loc(sf)][grand_idx['item_idx']!=-1].values
            for item_key in items_in_subfunc:
                try_theata_group[sf_id] = try_theata_group[sf_id] * theata_i[item_key]
    theata_sf_stack = tt.stack([v for _,v in try_theata_group.items() ])
    theata_sf = pm.Deterministic('theata_sf', theata_sf_stack, dims = 'subfunc')

I just started out, and the code is sampling slowly and poorly. But I am not sure if what it is due to… So, this stacking may work for you. I am considering looking at changing the combinations of tensors from multiplication to addition through a log transform.