Hi folks. I’m struggling to develop the following model, and would love any and all insight ! Here’s the rundown.
 every week, our salespeople sell a number of widgets
 we assume that their weekly sales number is binomial : they have a large number of negotiations
N
going on at any one time, and each week, there’s a probabilityp
of closing each deal  salespeople use productivity tools, and we assume that these tools may impact either the numbers of deals they’re negotiating at once (
N
) or the rate at which these deals get closed (p
)  each salesperson has their own
N
andp
 the
p
are drawn from a beta distribution  the
N
are drawn from a Poisson distribution
The setup is as follows.

closed
, an array ofn_weeks
rows andn_salespeople
columns, whereclosed[i, j]
is the integer number of widgets sold by salespersonj
in weeki

productivity
, an array of the same shape asclosed
; the valueproductivity[i, j]
is 1 if salespersonj
is using a productivity tool in weeki
, and 0 otherwise
Finally, our model :
n_weeks, n_salespeople = closed.shape
salespeople_shape = (1, n_salespeople)
with pm.Model() as model:
# Estimate N * p per salesperson
Np = closed.mean(0).reshape(salespeople_shape)
# p is betadistributed
p_ = pm.Beta("p", alpha=1.5, beta=20.0, shape=salespeople_shape, testval=0.05)
# N is based on Np and p
N_ = pm.Poisson("N", mu=Np / p_, shape=salespeople_shape, testval=Np / 0.05)
# Productivity tool effect
delta_ = pm.HalfNormal("delta", sd=0.5, testval=0.03)
gamma_ = pm.HalfNormal("gamma", sd=0.5, testval=0.03)
p_bonus = 1 + delta_ * productivity
N_bonus = 1 + gamma_ * productivity
# Observed
y = pm.Binomial("y", n=N_ * N_bonus, p=p_ * p_bonus, observed=closed)
This code is getting me what looks to be a broadcasting issue : TypeError: Cannot convert Type TensorType(int64, matrix) (of Variable N_shared__) into Type TensorType(int64, row). You can try to manually convert N_shared__ into a TensorType(int64, row).
I’m not able to figure out why this is occurring. I’m assuming broadcasting works as it does in numpy, and this looks like a broadcast error, but I’m not managing to find it. Any help much appreciated !
As a bonus question, I’d also love some advice on the best way to set priors on the alpha and beta variables of the p
above. I’ve set them to 1.5 and 20, as a vague estimate, but I’d love to put priors on these. What types of prior might be good here ?
Thanks so much for any help.
Quentin