I have not gone through all your code yet, but the main difference between how you would code a BUGS model and a PyMC model relevent to your model is that in PyMC is that you should vectorize your model. Instead of looping through your variables, you should create arrays of variables and give those as arguments to other parts of your model.
For example, instead of your second loop, you should do something like:
T = pymc.Categorical('T', p=p1,p2)
mu = pymc.Deterministic(eval=lambda t=T,lambda_0=lambdas[0], lambda_1=lambdas[1]: t < 0.5 & lambda_0 | lambda_1,
name='mu')
Y = pymc.Binomial('Y', n=mu, p=tau, value=y_data, observed=True)
(note that numpy arrays sadly do not work with the 'and' and 'or' operators. You must use & and | or use the functions.
PyMC *should* be able to deal with how you have written you model, but it is not how PyMC is meant to be used so it will be harder to debug your model. PyMC should also normally be able to deal with natural expressions of your variables to create deterministics, but I am not certain whether this works with the & and | operators. For example, you might try,
mu = T < .5 & (lambdas[0] | lambdas[1])
However, I am not 100% certain that will work (some of the operators might not be implemented).
I also notice you have the expression "tau
**(-1/2
)" in your program. Unfortunately Python does integer division for 1/2 so this will evaluate as -1 (this will be fixed soon), so use tau
**(-.5
) or just sigma = tau **-.5.
I am not certain what your specific error is due to.
John