7.2 Dirichlet conjugada da multinomial

Se \[X_1,\ldots,X_k|\theta_1,\ldots,\theta_k \sim \mathcal{M}(n,\theta_1,\ldots,\theta_k)\] conforme Seção 5.5.2 e admite-se uma priori \[\theta_1,\ldots,\theta_k \sim Dir(\alpha_1,\ldots,\alpha_k)\] conforme Seção 5.6.2, então a posteriori é dada por \[\theta_1,\ldots,\theta_k|x_1,\ldots,x_k \sim Dir(\alpha_1+x_1,\ldots,\alpha_k+x_k)\] onde \(x_i\) é o número de casos observados da categoria \(i\) na amostra, \(i \in \{1,\ldots,k\}\), e \(n = \sum_{i=1}^k x_i\).

Exemplo 7.1 Em uma cidade há três times de futebol, \(T_1\), \(T_2\) e \(T_3\). As proporções de torcedores \(\theta_1\), \(\theta_2\) e \(\theta_3\) são desconhecidas, e deseja-se estimá-las pelo método bayesiano. Assim, observa-se uma amostra multinomial de \(n=1000\) moradores da cidade, dos quais \(x_1=130\), \(x_2=492\) e \(x_3=378\). Se for admitida a priori \[\theta_1,\theta_2,\theta_3 \sim Dir(1,1,1)\] a posteriori é dada por \[\theta_1,\theta_2,\theta_3|130,492,378 \sim Dir(1+130,1+492,1+378)\] Sua forma fucional é dada conforme Eq. (5.9), podendo ser expressa por \[\pi(\theta_1,\theta_2,\theta_k|131,493,379) = \frac{\Gamma(1003)}{\Gamma(131)\Gamma(493)\Gamma(379)} \theta_1^{130} \theta_2^{492} \theta_3^{378}\]

# Opção 1
library(gtools)
library(DirichletReg)

dat <- rdirichlet(10000, alpha = c(131,493,379))
plot(DR_data(dat), 
     a2d = list(colored = TRUE, 
                c.grid = FALSE, 
                col.scheme = c("entropy")))

# Opção 2
library(dirichlet)
library(dplyr)
library(ggplot2)
theme_set(theme_bw())

f <- function(v) ddirichlet(v, c(131,493,379))
mesh <- simplex_mesh(.0025) %>% as.data.frame %>% as_tibble
mesh$f <- mesh %>% apply(1, function(v) f(bary2simp(v)))
  
(p <- ggplot(mesh, aes(x, y)) +
  geom_raster(aes(fill = f)) +
  coord_equal(xlim = c(0,1), ylim = c(0, .85)))

library(desempateTecnico)
simplex3d(pa=.4, pb=.3, pc=.3, n=1000, alpha = 0.05)
bayes(c(.4,.3,.3), 1000)
##      cenario posteriori
## [1,] "A"     "0"       
## [2,] "B"     "0"       
## [3,] "C"     "0"       
## [4,] "AB"    "0.5004"  
## [5,] "AC"    "0.4996"  
## [6,] "BC"    "0"
bayes(c(.4160925601, .3316216347, .2522858052), 500)
##      cenario posteriori
## [1,] "A"     "0"       
## [2,] "B"     "0"       
## [3,] "C"     "0"       
## [4,] "AB"    "0.9899"  
## [5,] "AC"    "0.0101"  
## [6,] "BC"    "0"
simplex3d(.4160925601, .3316216347, .2522858052, 500)

Onde pode ser usado: Latent Dirichlet Allocation (LDA).

(Blei, Ng, and Jordan 2003)
https://www.tidytextmining.com/topicmodeling.html
https://bookdown.org/Maxine/tidy-text-mining/latent-dirichlet-allocation.html
https://towardsdatascience.com/beginners-guide-to-lda-topic-modelling-with-r-e57a5a8e7a25

Chap. 27 ‘Probabilistic grammars and hierarchical Dirichlet processes’, OHagan & West (2010) - The Oxford handbook of applied bayesian analysis pg. 776

Referências

Blei, David M, Andrew Y Ng, and Michael I Jordan. 2003. “Latent Dirichlet Allocation.” Journal of Machine Learning Research 3 (Jan): 993–1022. https://www.jmlr.org/papers/volume3/blei03a/blei03a.pdf.