Help figuring out simple categorical indexing

It may not be pretty or especially performant, but you could consider something like this:

code_list = [pm.MutableData(c, df[c].cat.codes) for c in cat_cols]

mu = alpha
for codes in code_list:
     mu = mu[codes]
mu = at.exp(mu)

Also, I’m attempting to guess your intentions here:

pm.Normal(“α”, 0, 1, dims=cat_cols)

but are you sure you want a RV with shape (n1, n2,...) as opposed to separate 1D arrays? The latter is more akin to a standard independent loglinear model whereas the former is including interactions between all the levels of c1, c2,… etc.

1 Like