Hi,
I’m trying to set up what I think should be a simple negative binomial model.
If weekly_reservations ~ B( total_reservations , reservation_rate ), I’m trying to recover total_reservations
given a level of weekly_reservations
for a given week.
I’ve set up this model so far, but the values for the posterior reservation_rate
don’t match the expected values, and it seems like I’m missing a transform somewhere.
I have been unlucky trying to find any specific examples for something like this. Any ideas much appreciated!
Data:
weekly_reservations = np.array([ 14, 41, 41, 44, 74, 104, 162, 205,
274, 329, 372, 473, 534, 666, 788, 927,
1147, 1399, 1673, 2007, 2476, 3003, 3674, 4344,
5237, 6306, 8026, 9895, 12125, 14792, 18071, 21929,
26690, 32855, 39759, 48684, 59371, 71765, 86179, 102734,
121958, 142976, 166365, 191495, 218210, 245875, 272319, 298141,
323690, 349570, 375785, 405290, 430483, 433995])
total_reservations = np.array([434001, 434001, 434001, 434001, 434001, 434001, 434001, 434001,
434001, 434001, 434001, 434001, 434001, 434001, 434001, 434001,
434001, 434001, 434001, 434001, 434001, 434001, 434001, 434001,
434001, 434001, 434001, 434001, 434001, 434001, 434001, 434001,
434001, 434001, 434001, 434001, 434001, 434001, 434001, 434001,
434001, 434001, 434001, 434001, 434001, 434001, 434001, 434001,
434001, 434001, 434001, 434001, 434001, 434001])
My model so far:
n_weeks = len(total_reservations)
with pm.Model() as simple_model:
alpha = pm.HalfNormal("alpha", sd=1)
sd_a = pm.HalfNormal("sd_a", sd=1)
sd_b = pm.HalfNormal("sd_b", sd=1)
a = pm.HalfNormal("a", sd=sd_a)
b = pm.HalfNormal("b", sd=sd_b)
reservation_rate = pm.Beta("reservation_rate", alpha=a, beta=b, shape=n_weeks)
est_total = pm.Deterministic('est_total', weekly_reservations / reservation_rate)
N = pm.NegativeBinomial('N', mu=est_total, alpha=alpha, observed=total_reservations)
However, rate reservation_rate
doesn’t quite match what I’m expecting:
(Note: updated to better reflect the business use case)