While there are barely any difference between the confidence interval from Wald’s and Wilson’s method, in order to have a guardrail against a small sample with a small rate, we will be choosing Wilson’s as Wald’s would produce a misleading result under those conditions.
Now, there are orders that have multiple products with multiple categories. A bulkier item may affect the delivery time of the smaller items. Hence, we will see whether the interval change if we exclude the orders that carries multiple categories.
ci_single = (df[df['is_single_category'] ==True].assign(negative=df.review_score <=2) .groupby('delay_bin', observed=True) .agg(n_orders=('order_id', 'count'), n_negatives=('negative', 'sum')) .reset_index())ci_single['rate'] = ci_single.n_negatives / ci_single.n_ordersci_single[['wald_lo', 'wald_hi']] = pd.DataFrame( [proportion_confint(k, n, method='normal') for k, n inzip(ci_single.n_negatives, ci_single.n_orders)], index=ci_single.index)ci_single[['wilson_lo', 'wilson_hi']] = pd.DataFrame( [proportion_confint(k, n, method='wilson') for k, n inzip(ci_single.n_negatives, ci_single.n_orders)], index=ci_single.index)ci_single['single_category_orders'] =Trueci_single
delay_bin
n_orders
n_negatives
rate
wald_lo
wald_hi
wilson_lo
wilson_hi
single_category_orders
0
early
87413
7819
0.089449
0.087557
0.091341
0.087575
0.091359
True
1
on time
1273
156
0.122545
0.104532
0.140559
0.105659
0.141703
True
2
1-3
1846
593
0.321235
0.299934
0.342536
0.300324
0.342889
True
3
4-7
1742
1179
0.676808
0.654846
0.698771
0.654477
0.698361
True
4
8-14
1443
1156
0.801109
0.780513
0.821704
0.779726
0.820893
True
5
15+
1333
1044
0.783196
0.761075
0.805317
0.760278
0.804486
True
There are barely any changes, probably due to the fact that orders with multiple categories are not common in this dataset. However, it is good to still have the option to look both for the future.