# Categorical latent parameter

I’ve got a problem with modeling a categorical latent parameter. My model is a variant of seven country quiz problem in Bayesian Cognitive Modeling. In the model, zj is a categorical parameter with 3 categories (0, 1, 2) and xi is a binary parameter. Theta depends on xi and zj. My code is as follow:

``````with pm.Model() as model:

alpha = pm.Uniform("alpha", lower=0., upper=1.)
beta = pm.Uniform("beta", lower=0., upper=alpha)
gamma = pm.Uniform("gamma", lower=0., upper=alpha)

xi = pm.Bernoulli("xi", p=np.array([1]+[0.5]*(Nx-1)).reshape(-1, 1), shape=(Nx, 1))
zj = pm.Categorical("zj", p=np.array([0.33, 0.33, 0.34]), shape=(1, Nz))
#Nx and Nz are the dimensions of xi and zj

theta = pm.Deterministic("theta", pt.switch(pt.eq(xi, zj), alpha, pt.switch(pt.eq(zj, 2), gamma, beta)))
kij = pm.Bernoulli("kij", p=theta, observed=data)
``````

However, the results of sampling shows that both xi and zj are continuous:

A mean sd hdi_3% hdi_97% mcse_mean mcse_sd ess_bulk ess_tail r_hat
xi[0, 0] 1.000 0.000 1.000 1.000 0.000 0.000 4000.0 4000.0 NaN
xi[1, 0] 0.824 0.381 0.000 1.000 0.024 0.017 257.0 257.0 1.01
xi[2, 0] 0.216 0.411 0.000 1.000 0.029 0.021 199.0 199.0 1.01
xi[3, 0] 0.213 0.409 0.000 1.000 0.031 0.022 173.0 173.0 1.01

I don’t know what’s happened, and I suppose maybe my usage of pm.Categorical is wrong. What should I do to get my model correct?
Thanks!

Why do you think they are continuous from these results?

Also in case you haven’t seen, there is an adaptation of the book to PyMC here: pymc-resources/BCM at main · pymc-devs/pymc-resources · GitHub

Thanks a lot! I will reread the book and code.

I recheck the result and find that they are truly discrete. I must have misunderstood the summarized result. Thanks for answering such a simple question

1 Like