2.3 Multiparameter problems

If there is more than one parameter, the previous discussion applies without any major changes. What might complicate things is if we wish to do inference on just one of the parameters. Then we need to calculate the marginal posterior distribution of the parameter, which may not be practical. One remedy is to simply draw samples from the joint posterior distribution and from the samples pick the parameters that are of interest.

Let us consider the example of comparing two binomials. The data generating model is \[\begin{align} X_1 &\sim \mathsf{Bin}(n_1,\theta_1),\\ X_2 &\sim \mathsf{Bin}(n_2,\theta_2). \end{align}\] The parameter that we are interested in is \(\tau:=\theta_2-\theta_1\). If we assume a flat prior on \(\theta_1\) and \(\theta_2\) the posterior becomes, \[ p(\theta_1,\theta_2\mid x) \propto L(\theta_1,\theta_2) \propto \theta_1^{x_1}(1-\theta_1)^{n_1-x_1}\theta_2^{x_2}(1-\theta_2)^{n_2-x_2}. \] Note that \(\theta_1\mid x_1\sim \mathsf{Beta}(x_1+1,n_1-x_1+1)\) is independent of \(\theta_2\mid x_2\sim \mathsf{Beta}(x_2+1,n_2-x_2+1).\) Therefore we can simulate from \(\tau\mid x\) by drawing \(\theta_1^\star\) and \(\theta_2^\star\) from the respective distribution and setting \(\tau^\star = \theta_2^\star - \theta_1^\star\).

library(ggplot2)
library(latex2exp)

n1 <- 10
n2 <- 10
theta1 <- 0.5
theta2 <- 0.3
nPost <- 2000

set.seed(42)

#Generate data
x1 <- rbinom(n = 1, size = n1, prob = theta1)
x2 <- rbinom(n = 1, size = n2, prob = theta2)

#Posterior for theta
theta1.post <- rbeta(n = nPost, shape1 = x1+1, shape2 = n1-x1+1)
theta2.post <- rbeta(n = nPost, shape1 = x2+1, shape2 = n2-x2+1)

tau.post <- theta2.post - theta1.post

ggplot(data.frame(tau.post), aes(x=tau.post)) + 
 geom_histogram(aes(y=..density..), colour="black", fill="white")+
 geom_density(alpha=.2, fill="black") +
  theme_minimal() +
  xlab(TeX("$\\tau$"))
Posterior distribution

Figure 2.3: Posterior distribution