1 Posterior distribution

If \(y_i\mid G \stackrel{\text{iid}}{\sim}G\), for \(i=1,\ldots,n\), with \(G\sim\textsf{DP}(\alpha,G_0)\), then the posterior distribution of \(G\) is a \(\textsf{DP}(\alpha^*,G_0^*)\) with \[ \alpha^* = \alpha + n \qquad\text{and}\qquad G_0^*(\cdot) = \frac{\alpha}{\alpha + n}G_0(\cdot) + \frac{n}{\alpha + n}G_n(\cdot) \] where \(G_n(\cdot)\) is the empirical distribution function of the data. Recall that this function is a step function that jumps up by \(1/n\) at each one of the \(n\) data points \(y_1,\ldots,y_n\). Its value at any specified value is the fraction of observations that are less than or equal to the specified value, i.e., \[ G_n(\cdot) = \frac{1}{n}\sum_{i=1}^n 1_{[y_i,\infty)}(\cdot)\,, \] where \(1_A\) is the indicator function of a set \(A\).

This result shows that the DP is a conjugate prior.

2 Posterior mean

The posterior mean estimate for \(G(x)\) is given by \[ \textsf{E}(G(x)\mid\mathbf{y}) = \frac{\alpha}{\alpha + n}G_0(x) + \frac{n}{\alpha + n}G_n(x)\,, \] where \(\mathbf{y}=(y_1,\ldots,y_n)\).

3 Example

Generate \(n=10\) observations \(\mathbf{y}=(y_1,\ldots,y_n)\) from a Cauchy distribution with location parameter \(\mu = 0\) and scale parameter \(\gamma = 1\). Assume that \(y_i\mid G \stackrel{\text{iid}}{\sim}G\), for \(i=1,\ldots,n\), with \(G\sim\textsf{DP}(5,\textsf{N}(0,1))\). Compute the empirical distribution function of the data \(G_n(\cdot)\) and the posterior mean \(\textsf{E}(G(\cdot)\mid\mathbf{y})\).

# random sample from a Cauchy distribution
n <- 10
set.seed(1)
y <- rcauchy(n = n, location = 0, scale = 1)
# prior
alpha <- 5
G0 <- function(x) pnorm(x)
# empirical distribution function 
Gn <- ecdf(x = y)
# posterior mean
Gp <- function(x) (alpha*G0(x) + n*Gn(x))/(alpha + n)
# evaluation and plotting
x <- seq(from = -5, to = 5, len = 1000)
par(mfrow = c(1,1), mar = c(3,3,1.4,1.4), mgp = c(1.75,0.75,0))
curve(expr = pcauchy(x, location = 0, scale = 1), from = -5, to = 5, n = 1000, col = 1, ylab = "Distribution", ylim = c(0,1))
curve(expr = G0(x), n = 1000, add = TRUE, col = "gray")
lines(x = x, y = Gn(x), type = "l", lty = 2, col = 3)
lines(x = x, y = Gp(x), type = "l", lty = 3, col = 4)
legend("topleft", legend = c("Truth","G0","Gn","E(G | y)"), col = c(1,"gray",3,4), lty = c(1,1,3,4), bty = "n")

4 References