Restaurant ordering methods
Topic: Categorical data and the Dirichlet distribution · more questions on this topic
‹ Dirichlet updating Q22 ›
A restaurant observed the following numbers of orders yesterday:
| Dine-in | Take-away | Pick-up | Delivery | |
|---|---|---|---|---|
| Count | 63 | 19 | 3 | 38 |
Let {\boldsymbol{p}}=(p_1,p_2,p_3,p_4) be the corresponding population proportions.
With {\boldsymbol{x}}\mid{\boldsymbol{p}}\sim\operatorname{Multinomial}(123,{\boldsymbol{p}}) and {\boldsymbol{p}}\sim\operatorname{Dirichlet}(\alpha_1,\ldots,\alpha_4), identify the posterior.
Last week’s percentages were 44.79\%, 27.60\%, 7.36\%, and 20.25\%. Explain how to use these proportions to choose the direction of {\boldsymbol{\alpha}}, and how a chosen total concentration records the weight given to last week.
Using a prior equivalent, for posterior-mean purposes, to last week’s proportions plus one baseline count in each category, report posterior means and equal-tailed 95\% credible intervals for p_1, p_4, p_1+p_2+p_3, and p_1-p_4.
Question. A restaurant observed the following numbers of orders yesterday:
| Dine-in | Take-away | Pick-up | Delivery | |
|---|---|---|---|---|
| Count | 63 | 19 | 3 | 38 |
Let {\boldsymbol{p}}=(p_1,p_2,p_3,p_4) be the corresponding population proportions.
With {\boldsymbol{x}}\mid{\boldsymbol{p}}\sim\operatorname{Multinomial}(123,{\boldsymbol{p}}) and {\boldsymbol{p}}\sim\operatorname{Dirichlet}(\alpha_1,\ldots,\alpha_4), identify the posterior.
Last week’s percentages were 44.79\%, 27.60\%, 7.36\%, and 20.25\%. Explain how to use these proportions to choose the direction of {\boldsymbol{\alpha}}, and how a chosen total concentration records the weight given to last week.
Using a prior equivalent, for posterior-mean purposes, to last week’s proportions plus one baseline count in each category, report posterior means and equal-tailed 95\% credible intervals for p_1, p_4, p_1+p_2+p_3, and p_1-p_4.
Solution.
The Dirichlet–Multinomial update adds the observed cell counts to the corresponding concentration parameters. Since 63+19+3+38=123, \begin{align*} {\boldsymbol{p}}&\sim\operatorname{Dirichlet}(\alpha_1,\alpha_2,\alpha_3,\alpha_4),\\ {\boldsymbol{x}}\mid{\boldsymbol{p}}&\sim\operatorname{Multinomial}(123,{\boldsymbol{p}}),\\ &\boxed{{\boldsymbol{p}}\mid{\boldsymbol{x}} \sim\operatorname{Dirichlet}(63+\alpha_1,19+\alpha_2,3+\alpha_3,38+\alpha_4)}. \end{align*}
Write last week’s proportions as
{\boldsymbol{q}}=(0.4479,0.2760,0.0736,0.2025).
A Dirichlet prior centred exactly at {\boldsymbol{q}} can be written {\boldsymbol{\alpha}}=\kappa{\boldsymbol{q}}, where \kappa>0 is the total prior concentration. Increasing \kappa preserves the prior mean but increases the weight assigned to last week.
The construction used here instead combines 100 fractional counts with one baseline count in each category:
{\boldsymbol{\alpha}} =(44.79,27.60,7.36,20.25)+(1,1,1,1) =(45.79,28.60,8.36,21.25).
Its concentration is 104 and its mean is {\boldsymbol{\alpha}}/104, which is slightly closer to (1/4,1/4,1/4,1/4) than {\boldsymbol{q}}. Thus the direction and concentration should both be reported; percentages alone determine only the direction.
- The posterior parameters are \begin{align*} {\boldsymbol{\alpha}}^\ast &=(63,19,3,38)+(45.79,28.60,8.36,21.25)\\ &=\boxed{(108.79,47.60,11.36,59.25)}, \end{align*} with total concentration \alpha_0^\ast=108.79+47.60+11.36+59.25=227. Thus
\mathbb{E}(P_1\mid{\boldsymbol{x}})=\frac{108.79}{227}=0.4793, \qquad \mathbb{E}(P_4\mid{\boldsymbol{x}})=\frac{59.25}{227}=0.2610.
Also,
\mathbb{E}(P_1+P_2+P_3\mid{\boldsymbol{x}})=1-\mathbb{E}(P_4\mid{\boldsymbol{x}})=0.7390
and
\mathbb{E}(P_1-P_4\mid{\boldsymbol{x}}) =\frac{108.79-59.25}{227}=0.2182.
The Dirichlet marginal results give \begin{align*} P_1\mid{\boldsymbol{x}}&\sim\operatorname{Beta}(108.79,118.21),\\ P_4\mid{\boldsymbol{x}}&\sim\operatorname{Beta}(59.25,167.75),\\ P_1+P_2+P_3\mid{\boldsymbol{x}}&\sim\operatorname{Beta}(167.75,59.25). \end{align*} Their intervals can therefore be obtained with Beta quantiles. The difference P_1-P_4 has no such Beta form, so simulation handles all four quantities uniformly:
rdirichlet_base <- function(n, alpha) {
z <- sapply(alpha, function(a) rgamma(n, shape = a, rate = 1))
z / rowSums(z)
}
set.seed(3500)
alpha_post <- c(108.79, 47.60, 11.36, 59.25)
p <- rdirichlet_base(100000, alpha_post)
summaries <- cbind(
p1 = p[, 1],
p4 = p[, 4],
p123 = rowSums(p[, 1:3]),
difference = p[, 1] - p[, 4]
)
rbind(
mean = colMeans(summaries),
lower = apply(summaries, 2, quantile, 0.025),
upper = apply(summaries, 2, quantile, 0.975)
)For the displayed seed, rounding to three decimals gives
| Quantity | Posterior mean | 2.5% | 97.5% |
|---|---|---|---|
| p_1 | 0.479 | 0.415 | 0.544 |
| p_4 | 0.261 | 0.206 | 0.320 |
| p_1+p_2+p_3 | 0.739 | 0.680 | 0.794 |
| p_1-p_4 | 0.218 | 0.109 | 0.325 |
The first three intervals agree, apart from Monte Carlo rounding, with the corresponding exact Beta quantiles.