Panel model fitting issue

Hi Jesse,

Yes, thank you very much for replying - that is exactly what I needed!

  • To future people dealing with the same issue, look at the way that the long-format df that Jesse made has two indexes one for people (in this example) and one for time. My initial df had only one and I think that was the source of my error when I was trying to factorize it.

My final model looks like

with pm.Model() as panel_model:
#Hyperpriors
common_mu = pm.Normal(‘common_mu’, mu=0., sd=2)
common_sd = pm.Exponential(“common_sd”, 1.0)
s = pm.Exponential(“s”, 1.0)
b = pm.Normal(‘b’, mu = 0, sd = 1, shape=len(set(time_idxs)))
#Priors
beta = pm.Normal(“beta”, mu=common_mu, sigma=common_sd, shape=(4))

#mu
mu = pm.math.dot(data[['X1', 'X2', 'X3', 'X4']].values, beta)

r_1 = pm.Deterministic('r_1', s*b)

#link func        
p = T.nnet.softmax(mu + r_1[[time_idxs]])
                                          
y = pm.Categorical('y', p=p, observed=data['Y'].values)

Thanks again for the help!

1 Like