4  Bayesian Estimation

In the null hypothesis schema we are trying only to nullify something: “The null hypothesis is never proved or established but is possibly disproved in the course of experimentation.” But ordinarily evidence does not take this form. With the corpus delicti in front of you, you do not say, “Here is evidence against the hypothesis that no one is dead.” You say, “Evidently someone has been murdered.” (Berkson 1942)1

In Bayesian inference, probability distributions are used to summarize our knowledge about the possible values of an unknown parameter \(\theta_\true\). The distribution of possible values of \(\theta_\true\) before we have seen our data is called the prior distribution, and the distribution of possible values of \(\theta_\true\) after we see the data is called the posterior distribution. Most parameters we are interested in estimating (such as probabilities) are continuous, so they have a probability density function (PDF) instead of a probability mass function (PMF). The posterior PDF is proportional to the prior PDF times the likelihood function, and the posterior distribution can be used to get point and interval estimates of an unknown parameter. The interval estimates are called credible intervals, and they have important advantages over confidence intervals. The Bayesian approach to statistics is more logically consistent and more intuitive than the frequentist approach, but it can be more computationally complex. While large-sample theory can be useful in Bayesian inference, it does not rely on asymptotic normality to the same degree that maximum likelihood estimation does.

4.1 Prior and posterior distributions

The value of a PDF is not a probability (it can be greater than one), but PDFs can be handled like probabilities in terms of the addition rule and the multiplication of conditional probabilities Boos and Stefanski (2013). Let \(\pi(\theta)\) be the prior PDF of \(\theta\). Before we see our data, we believe that \(\theta_\true \in [a, b]\) with probability \[ \Pr(a \leq \theta \leq b) = \int_a^b \pi(\theta) \,\dif \theta. \] This integral is the area under the graph of \(\pi(\theta)\) between \(\theta = a\) and \(\theta = b\). For a given value of \(\theta\), the likelihood of our data is \(L(\theta) = \pi(\data \given{} \theta)\). By Bayes’ rule, the posterior PDF is \[ \pi(\theta \given{} \data) = \frac{L(\theta) \pi(\theta)}{\pi(\data)} \propto L(\theta) \pi(\theta). \] where \(\propto\) denotes “proportional to.” Calculating \(\pi(\data)\) is difficult and almost always unnecessary. As long as we can calculate \(\pi(\theta \given{} \data)\) up to a constant of proportionality, we can normalize it to ensure that we have a posterior PDF whose integral over \(\mathbb{R}\) equals one. After we see our data, we believe that \(\theta_\true \in [a, b]\) with probability \[ \Pr(a \leq \theta \leq b \given{} \data) = \int_a^b \pi(\theta \given{} \data) \,\dif \theta. \] Bayesian point and interval estimates of \(\theta_\true\) are based on the posterior PDF.

Bayesian methods are often simpler, easier to interpret, and more robust to small sample sizes than frequentist methods like maximum likelihood estimation. In the limit of a large sample size, Bayesian and frequentist methods almost always give equivalent results. The Bayesian approach is also valuable because it emphasizes estimation and the accumulation of knowledge rather than binary decisions (Tukey 1960). However, the adoption of Bayesian methods has been impeded by a historical lack of the computational power needed to use them and by the widespread hesitation to specify prior distributions among epidemiologists, statisticians, and other scientists. The first problem is largely solved, but the latter problem remains with us today.

A common approach to specifying a prior distribution is to use a noninformative prior that places few or no restrictions on the value of \(\theta\). This lets the data “speak for itself” at the price of ignoring existing knowledge about the underlying scientific question. The ability to incorporate an informative prior distribution in the Bayesian approach to statistical inference should be viewed as a feature, not a bug (Greenland 2006; Greenland and Poole 2013).

4.1.1 Posterior point and interval estimation

The mean, median, or mode of the posterior distribution of \(\theta\) can be used as a point estimate of \(\theta_\true\). We will use \(\bar{\theta}\) to denote the posterior mean and \(\tilde{\theta}\) to denote the posterior median. In large samples, the posterior distribution converges to a normal distribution with mean \(\theta_\true\) and variance \(I(\theta_\true)^{-1}\) (Le Cam 1953; Gelman et al. 2014),2 which is the same as the limiting normal distribution of the MLE \(\hat{\theta}\). In this limit, the posterior mean, median, and mode are all equal to \(\hat{\theta}\).

A \(1 - \alpha\) credible interval is an interval \([a, b]\) such that \[ \Pr(a \leq \theta \leq b \given{} \data) = \int_a^b \pi(\theta \given{} \data) \,\dif \theta = 1 - \alpha. \] Given our data, we believe that \(\theta_\true \in [a, b]\) with probability \(1 - \alpha\). There are many different ways that a credible interval can be defined. The one that is conceptually closest to a confidence interval is the central posterior interval or equal-tailed interval, where \[ \Pr(\theta < a \given{} \data) = \Pr(\theta > b \given{} \data) = \frac{\alpha}{2}. \] Thus, the \(1 - \alpha\) confidence limits are the \(\alpha / 2\) and \(1 - \alpha / 2\) quantiles of the posterior distribution of \(\theta_\true\). Unlike confidence intervals, credible intervals can accurately be interpreted as containing \(\theta_\true\) with probability \(1 - \alpha\). Like confidence intervals, credible intervals are only reliable if the likelihood is approximately correct. An equal-tailed credible interval is guaranteed to contain the posterior median \(\tilde{\theta}\). It will usually contain the posterior mean \(\bar{\theta}\), but this is not guaranteed in small samples.

4.1.2 Bayesian interpretation of confidence intervals

Bayesian credible intervals actually have the properties that people intuitively but naively expect of frequentist confidence intervals. In finite samples, a \(1 - \alpha\) equal-tailed credible interval and a \(1 - \alpha\) confidence interval will be similar when the posterior density \(\pi(\theta \given{} \data)\) is proportional to the likelihood \(L(\theta) = \pi(\theta \given{} \data)\). This occurs when \(\pi(\theta)\) is constant, as in some uninformative priors. In the limit of a large sample, the credible interval and the confidence interval are nearly identical. In general, a frequentist confidence interval can be interpreted as an approximation to a Bayesian credible interval when there is a large sample and a prior distribution that is flat across the range of the confidence interval (Pratt 1965; Greenland and Poole 2013). However, credible intervals do not rely on large-sample approximations, and they are able to incorporate prior knowledge about the possible values of \(\theta_\true\).

4.1.3 Posterior probability of \(H_0\) and p-values

The idea of prior and posterior probabilities from Bayesian inference gives us a useful perspective on the interpretation of p-values, which is a source of much confusion in epidemiology (Diamond and Forrester 1983; Greenland et al. 2016; Baduashvili, Evans, and Cutler 2020). The most common error is to interpret the p-value as the posterior probability that \(H_0\) is true. By Bayes’ rule, \[ \Pr(H_0 \ \true \given{} \data) = \frac{\Pr(\data \given{} H_0 \ \true) \Pr(H_0 \ \true)}{\Pr(\data)}. \] The p-value is analogous to \(\Pr(\data \given{} H_0 \ \true)\), but the posterior probability \(\Pr(H_0 \text{ true} \given{} \ \data)\) depends on its prior probability \(\Pr(H_0)\). It should take more data to convince us of a null hypothesis that seemed very unlikely than to convince us of a null hypothesis that seemed very likely.

For a null hypothesis of the form \(H_0: \theta_\true = \theta_0\) where \(\theta\) ranges over an interval, it can be difficult to assign a prior probability to \(H_0\). For any continuous distribution of \(\theta\), the probability that it takes any particular value is zero. One way around this difficulty is to assign a prior probability mass to the null value \(\theta_0\). A more difficult problem is to assign a prior probability to the alternative hypothesis \(H_1\), which is often not clearly specified. This means that the posterior probability of the null hypothesis is often not clearly defined.

However, it is not difficult to calculate a lower bound on the probability that \(H_0\) is true given the data (Edwards, Lindman, and Savage 1963; Berger and Sellke 1987). Let \(\pi_0\) be the prior probability of \(H_0\), and suppose we have a single alternative hypothesis \(H_1: \theta_\true = \theta_1\) with prior probability \(1 - \pi_0\). Then the posterior probability of \(H_0\) is \[ \Pr(H_0 \given{} \data) = \frac{L(\theta_0) \pi_0}{L(\theta_0) \pi_0 + L(\theta_1) (1 - \pi_0)} = \bigg(1 + \frac{1 - \pi_0}{\pi_0} \frac{L(\theta_1)}{L(\theta_0)}\bigg)^{-1}. \] Given the data, the posterior probability of \(H_0\) is minimized if we happen to get the MLE \(\hat{\theta} = \theta_1\), so \[ \Pr(H_0 \ \true \given{} \data) \geq \bigg(1 + \frac{1 - \pi_0}{\pi_0}\frac{L(\hat{\theta})}{L(\theta_0)}\bigg)^{-1}. \] From Wilk’s theorem (Wilks 1938) for the likelihood ratio test, twice the log likelihood ratio has an approximate \(\chi^2_1\) distribution in large samples. To get a p-value of \(\alpha\) from the likelihood ratio test, we need \[ 2\big(\ell(\hat{\theta}) - \ell(\theta_0)\big) = z_{1 - \frac{\alpha}{2}}^2 \;\Rightarrow\; \frac{L(\hat{\theta})}{L(\theta_0)} = e^{\frac{1}{2} z_{1 - \frac{\alpha}{2}}^2}. \] Figure 4.1 shows the minimum posterior probability of \(H_0\) if \(\pi_0 = 0.5\) for different p-values. The p-value is almost always much lower than the lower bound of the posterior probability of the null. For \(\pi_0 = 0.5\), the lower bounds for \(\Pr(H_0 \ \true \given{} \data)\) are approximately 0.205 for \(p = 0.10\), 0.128 for \(p = 0.05\), and 0.035 for \(p = 0.01\). In practice, the posterior probability of \(H_0\) can be much larger than its lower bound (Berger and Sellke 1987).

Code
postH0.R
## Posterior probability of the null hypothesis (H0)

# function to calculate lower bound
lowerb <- function(pi0=0.5, pval=0.05) {
  # args: pi0 = prior probability of H0, pval = p-value
  # return: lower bound on posterior probability of H0
  z <- qnorm(1 - pval / 2)
  1 / (1 + (1 - pi0) / pi0 * exp(0.5 * z^2))
}

# plot of lower bounds for p-value = 0.01, 0.05, and 0.1
x <- seq(0, 1, by = .01)
plot(x, lowerb(x), type = "n", xlim = c(0, 1), ylim = c(0, 1),
     xlab = expression("Prior probability of H"[0]),
     ylab = expression("Minimum posterior probability of H"[0]))
grid()
abline(0, 1, col = "gray")
lines(x, lowerb(x))
lines(x, lowerb(x, pval = .01), lty = "dashed")
lines(x, lowerb(x, pval = .1), lty = "dotted")
legend("topleft", bg = "white", lty = c("dotted", "solid", "dashed"),
       legend = c("p = 0.10", "p = 0.05", "p = 0.01"))
Figure 4.1: The minimum posterior probability of \(H_0\) as a function of its prior probability \(\pi_0\) for p-values of 0.01, 0.05, and 0.1. These posterior probabilities can be much higher than the p-value.

4.2 Bayesian estimation of a probability

When estimating a probability \(\ptrue\), our likelihood will be the binomial likelihood \[ L(p) = \binom{n}{k} p^k (1 - p)^{n - x} \] when \(k\) out of \(n\) samples equal one. Because we only need to calculate the likelihood up to a constant of proportionality, we can safely ignore the \(\binom{n}{k}\) because it does not depend on \(p\). The posterior distribution of \(p\) will be \[ \pi(p \given{} \data) \propto p^k (1 - p)^{n - k} \pi(p) \] where \(\pi(p)\) is the prior distribution of \(p\). When \(\pi(p \given{} \data)\) and \(\pi(p)\) are from the same family of distributions, the prior \(\pi(p)\) is said to be a conjugate distribution for the binomial likelihood. Conjugate distributions exist for many likelihoods used in epidemiology.

4.2.1 Beta distribution

The conjugate distribution for the binomial likelihood is the beta distribution. It has is a support on \([0, 1]\) (where \(p_\true\) must live) with the PDF \[ f(x, \alpha, \beta) = \frac{\Gamma(\alpha + \beta)}{\Gamma(\alpha) \Gamma(\beta)} x^{\alpha - 1} (1 - x)^{\beta - 1} \propto x^{\alpha - 1} (1 - x)^{\beta - 1}. \] where \(\alpha > 0\) and \(\beta > 0\) are shape parameters and \(\Gamma(v)\) is the gamma function.3 Because we will only need to calculate PDFs up to a mutiplicative constant, the gamma function term can be safely ignored. If \(X \sim \text{beta}(\alpha, \beta)\), then \[ \E[X] = \frac{\alpha}{\alpha + \beta} \] and \[ \Var(X) = \frac{\alpha \beta}{(\alpha + \beta)^2 (\alpha + \beta + 1)}. \] The beta distribution has a number of important special cases:

  • When \(\alpha = \beta = 1\), it is a uniform(\(0, 1\)) distribution.

  • The beta distribution with \(\alpha = \beta = 1 / 2\) is the Jeffreys prior for the binomial likelihood.4 A Jeffreys prior is proportional to the square root of the expected information \(\mathcal{I}_1(\theta)\) of a single observation(Jeffreys 1946). They are widely used as noninformative priors. For the binomial likelihood, \(\mathcal{I}_1(p) = \frac{1}{p (1 - p)}\).

4.2.2 Posterior point and interval estimates

If the prior distribution of \(p\) is a beta(\(\alpha, \beta\)) distribution, then \[ \begin{aligned} \pi(p \given \data) &\propto p^k (1 - p)^{n - k} \times p^{\alpha - 1} (1 - p)^{\beta - 1} \\ &= p^{k + \alpha - 1} (1 - p)^{n - k + \beta - 1} \end{aligned} \] so the posterior distribution of \(p\) is a beta(\(k + \alpha, n - k + \beta\)) distribution. The posterior mean is \[ \bar{p} = \frac{k + \alpha}{(k + \alpha) + (n - k + \beta)} = \frac{k + \alpha}{n + \alpha + \beta}, \] and the posterior variance is \[ \frac{(k + \alpha) (n - k + \beta)}{(n + \alpha + \beta)^2 (n + \alpha + \beta + 1)} = \frac{\bar{p} (1 - \bar{p})}{n + \alpha + \beta + 1}. \] The endpoints of the \(1 - \alpha\) central credible interval are the \(\alpha / 2\) and \(1 - \alpha / 2\) quantiles of the beta(\(k + \alpha, n - k + \beta)\) distribution. Figure 4.2 shows prior and posterior distributions for 15 successes out of 22 trials. Although the prior distributions are quite different, the posterior distributions are quite similar. With large samples, the prior distribution disappears into the likelihood.

Code
normplots.R
## Bayesian prior and posterior distributions for a probability

# beta prior and posterior distributions
# The prior is beta(1, 1), which is the uniform(0, 1) distribution.
# Because k = 15 and n = 22, the posterior is beta(15 + 1, 22 - 15 + 1)
p <- seq(0.01, 0.99, by = 0.01)
plot(p, dbeta(p, 16, 8), type = "n", ylim = c(0, 5),
     xlab = "p", ylab = "Probability density")
grid()
lines(p, dbeta(p, 1, 1), lty = "dashed")  # prior PDF
lines(p, dbeta(p, 16, 8))                 # posterior PDF
postlower <- qbeta(0.025, 16, 8)          # 95% credible interval lower bound
postupper <- qbeta(0.975, 16, 8)          # 95% credible interval upper bound
polygon(c(0, seq(0, postlower, by = 0.01), postlower),
        c(0, dbeta(seq(0, postlower, by = 0.01), 16, 8), 0),
        col = "darkgray")
polygon(c(postupper, seq(postupper, 1, by = 0.01), 1),
        c(0, dbeta(seq(postupper, 1, by = 0.01), 16, 8), 0),
        col = "darkgray")
legend("topleft", bg = "white",
       lty = c("dashed", "solid", NA, "dashed", "solid"),
       col = c("black", "black", NA, "darkgray", "darkgray"),
       fill = c(NA, NA, "darkgray", NA, NA),
       border = c(NA, NA, "black", NA, NA),
       legend = c("uniform prior", "posterior (uniform)",
                  "2.5% tails (uniform)", "Jeffreys prior",
                  "posterior (Jeffreys)"))
lines(p, dbeta(p, 0.5, 0.5), lty = "dashed", col = "darkgray")
lines(p, dbeta(p, 15.5, 7.5), col = "darkgray")
Figure 4.2: Prior and posterior distributions for \(p\) after observing 15 successes out of 22 trials. The uniform prior and the resulting posterior distribution are shown in black with the 2.5% tails shaded. The central 95% credible interval includes all values of \(p\) between the two tails. The Jeffreys prior and the corresponding posterior distribution are shown in dark gray.

As \(n \rightarrow \infty\), we have \(\bar{p} - \hat{p} \rightarrow 0\) and \[\frac{\bar{p} (1 - \bar{p})}{n + \alpha + \beta + 1} - \frac{\hat{p} (1 - \hat{p})}{n} \rightarrow 0.\] Thus, the posterior distribution approaches approximate normal distribution of the maximum likelihood estimate \(\hat{p}\) in large samples. However, the Bayesian posterior distribution is valid for any sample size, not just large samples.

4.2.3 Jeffreys confidence interval

The \(1 - \alpha\) Jeffreys confidence interval is the central credible interval with a beta(\(1 / 2, 1 / 2)\) prior, which is the Jeffreys prior for a binomial model. When \(k > 0\) and \(k < n\), its endpoints are the \(\alpha / 2\) and \(1 - \alpha / 2\) quantiles of the beta(\(k + 1 / 2, n - k + 1 / 2\)) posterior distribution that we get if we see \(k\) successes in \(n\) trials. When \(k = 0\), the lower endpoint is 0. When \(k = n\), the upper endpoint is 1. For a binomial proportion, the Jeffreys confidence interval has width and coverage probability similar to the score (Wilson) and mid-p exact confidence intervals (Brown, Cai, and DasGupta 2001).

4.3 Comparison of binomial confidence intervals

Table 4.1 shows eight types of confidence intervals for a probability that we have discussed. These are calculated for the sensitivity, sensitivity, positive predictive value (PPV), and negative predictive value (NPV) of the diabetes test one hour after the meal, where a positive test was defined as a blood glucose concentration above 130 mg/dL.

Table 4.1: 95% confidence intervals for the sensitivity, specificity, PPV, and NPV of diabetes test in Remein and Wilkerson (1961).
Sensitivity Specificity PPV NPV
95% CI type \(55 / 70 \approx 0.786\) \(462 / 510 \approx 0.906\) \(55 / 103 \approx 0.534\) \(462 / 477 \approx 0.969\)
Wald (0.690, 0.882) (0.881, 0.931) (0.438, 0.630) (0.953, 0.984)
Logit (0.674, 0.866) (0.877, 0.928) (0.438, 0.628) (0.949, 0.981)
Agresti-Coull (0.675, 0.867) (0.877, 0.928) (0.438, 0.627) (0.948, 0.981)
Score (0.676, 0.866) (0.877, 0.928) (0.438, 0.627) (0.949, 0.981)
Likelihood ratio (0.680, 0.871) (0.879, 0.929) (0.438, 0.629) (0.950, 0.982)
Exact (0.671, 0.875) (0.877, 0.930) (0.433, 0.633) (0.949, 0.982)
Mid-p (0.678, 0.870) (0.878, 0.929) (0.437, 0.629) (0.950, 0.982)
Jeffreys (0.679, 0.869) (0.878, 0.929) (0.438, 0.628) (0.950, 0.982)

Because of their good coverage probabilities and narrow widths, the score (Wilson), likelihood ratio, and Jeffreys intervals are recommended by Agresti and Coull (1998) and Brown, Cai, and DasGupta (2001). The Agresti-Coull intervals are slightly wider than these intervals, but they have slightly higher coverage probabilities and are simpler to calculate. Mid-p exact confidence intervals are similar to the Jeffreys intervals, but they are more difficult to calculate. Exact intervals are too wide, and the Wald intervals have coverage probabilities that are often too low. The logit-transformed Wald interval has good coverage probabilities, but it can be even wider than the exact interval. In large samples (with larger samples required for probabilities near zero or one), all of the intervals are similar.

binconf-table.R
## Comparison of binomial confidence limits
library(DescTools)

# Sensitivity (55 / 70)
# Use round() to get rounded numbers shown in the table.
round(BinomCI(55, 70, method = "wald"), 3)
round(BinomCI(55, 70, method = "logit"), 3)
round(BinomCI(55, 70, method = "agresti-coull"), 3)
round(BinomCI(55, 70, method = "wilson"), 3)
round(BinomCI(55, 70, method = "lik"), 3)
round(BinomCI(55, 70, method = "clopper-pearson"), 3)
round(BinomCI(55, 70, method = "midp"), 3)
round(BinomCI(55, 70, method = "jeffreys"), 3)

# Specificity (462 / 510)
round(BinomCI(462, 510, method = "wald"), 3)
round(BinomCI(462, 510, method = "logit"), 3)
round(BinomCI(462, 510, method = "agresti-coull"), 3)
round(BinomCI(462, 510, method = "wilson"), 3)
round(BinomCI(462, 510, method = "lik"), 3)
round(BinomCI(462, 510, method = "clopper-pearson"), 3)
round(BinomCI(462, 510, method = "midp"), 3)
round(BinomCI(462, 510, method = "jeffreys"), 3)

# PPV (55 / 103)
round(BinomCI(55, 103, method = "wald"), 3)
round(BinomCI(55, 103, method = "logit"), 3)
round(BinomCI(55, 103, method = "agresti-coull"), 3)
round(BinomCI(55, 103, method = "wilson"), 3)
round(BinomCI(55, 103, method = "lik"), 3)
round(BinomCI(55, 103, method = "clopper-pearson"), 3)
round(BinomCI(55, 103, method = "midp"), 3)
round(BinomCI(55, 103, method = "jeffreys"), 3)

# NPV (462 / 477)
round(BinomCI(462, 477, method = "wald"), 3)
round(BinomCI(462, 477, method = "logit"), 3)
round(BinomCI(462, 477, method = "agresti-coull"), 3)
round(BinomCI(462, 477, method = "wilson"), 3)
round(BinomCI(462, 477, method = "lik"), 3)
round(BinomCI(462, 477, method = "clopper-pearson"), 3)
round(BinomCI(462, 477, method = "midp"), 3)
round(BinomCI(462, 477, method = "jeffreys"), 3)

  1. Joseph Berkson (1899–1982) was an American physician and statistician at the Mayo Clinic in Rochester, Minnesota. He helped develop and popularize the use of logistic regression for binary outcomes, coining the term “logit” for the log odds in 1944. He also pioneered the study of selection bias, a special case of which is called “Berkson’s bias”. In the late 1950s and the 1960s, he argued that scientific evidence did not establish that smoking causes lung cancer.↩︎

  2. This convergence follows from the Laplace approximation to the posterior distribution (Gelman et al. 2014). It occurs when the likelihood \(L(\theta)\) has a continuous second derivative with respect to \(\theta\) and \(\theta_\true\) is not on the boundary of the support of the prior distribution. These are similar to the regularity conditions for maximum likelihood estimation.↩︎

  3. The gamma function is \(\Gamma(v) = \int_0^\infty y^{v - 1} e^{-y} \dif y\). It is used to define the gamma distribution, of which the chi-squared distributions (including \(\chi^2_1\)) are special cases. If \(v\) is a positive integer, then \(\Gamma(v) = (v - 1)!\).↩︎

  4. Harold Jeffreys (1891–1989) was an English mathematician, statistician, geophysicist, and astronomer. He helped revive the Bayesian notion of probability as an expression of our knowledge about an unknown quantity, wrote a classic textbook on mathematical physics with his wife Bertha (also a mathematician and physicist), and was a prominent opponent of the theory of plate tectonics.↩︎