| State | Prior | \(P(+ \mid \text{state})\) | Prior \(\times\) likelihood | Posterior |
|---|---|---|---|---|
| disease | 0.01 | 0.95 | 0.0095 | 0.161 |
| healthy | 0.99 | 0.05 | 0.0495 | 0.839 |
| Sum | 1 | 0.059 | 1 |
STAT 536 — Statistical Computing
Fall 2026
where \(\mathbf{x}\): the observed data; \(L(\theta)\): the likelihood, the model’s density at \(\mathbf{x}\) as a function of \(\theta\); \(\pi(\theta)\): the density of \(\theta\) before the data; \(\pi(\theta \mid \mathbf{x})\): its density after the data.
| Frequentist | Bayesian | |
|---|---|---|
| Parameter \(\theta\) | fixed but unknown | treated as random: a distribution describes what we know about it |
| Data | random | fixed, once observed |
| Probability | long-run frequency | degree of belief |
| Inference via | the sampling distribution of \(\hat\theta\) | the posterior distribution of \(\theta\) |
| Goal | find \(\hat\theta\) that maximizes \(L(\theta)\) | compute the posterior \(\pi(\theta \mid \mathbf{x})\) |
where \(L(\theta)\): the likelihood, the model’s density at the observed data as a function of \(\theta\); \(\pi(\theta \mid \mathbf{x})\): the density of \(\theta\) given the observed data \(\mathbf{x} = (x_1, \ldots, x_n)\).
where \(X\): the number of heads in the 10 flips; \(k = 7\): its observed value.
\[L(\theta) = \binom{10}{7}\,\theta^7(1-\theta)^3, \qquad 0 \le \theta \le 1\]
where \(\theta\): the probability of heads; the data, 7 heads in 10 flips, are held fixed.
where \(\hat\theta\): the observed proportion of heads; \(1.96\): the 0.975 quantile of the standard normal.
| Frequentist | Bayesian, flat prior | |
|---|---|---|
| Estimate | MLE \(\hat\theta = 0.70\) | posterior mean \(0.667\) |
| 95% interval | Wald: \([0.42,\ 0.98]\) | credible: \([0.39,\ 0.89]\) |
| What the 95% is | “If we repeat this experiment many times, 95% of such intervals will contain the true \(\theta\).” | “Given the data, there is 95% probability that \(\theta\) lies in \([l, u]\).” |
| \(P(\theta > 0.5)\) | no such probability: \(\theta\) is fixed | \(0.887\) |
where \([l, u]\): the credible interval, here the 2.5% and 97.5% quantiles of the posterior.
\[P(A \mid B) = \frac{P(B \mid A)\,P(A)}{P(B)}, \qquad P(B) = P(B \mid A)\,P(A) + P(B \mid A^c)\,P(A^c)\]
where \(A\), \(B\): events; \(A^c\): the complement of \(A\); the second equation: the law of total probability.
where \(+\), \(-\): a positive and a negative test result.
| State | Prior | \(P(+ \mid \text{state})\) | Prior \(\times\) likelihood | Posterior |
|---|---|---|---|---|
| disease | 0.01 | 0.95 | 0.0095 | 0.161 |
| healthy | 0.99 | 0.05 | 0.0495 | 0.839 |
| Sum | 1 | 0.059 | 1 |
\[\pi(\theta_j \mid \mathbf{x}) = \frac{L(\theta_j)\,\pi(\theta_j)}{\sum_{l} L(\theta_l)\,\pi(\theta_l)}\]
where \(\theta_1, \theta_2\): the possible values of \(\theta\); \(\pi(\theta_j)\): the prior probability of \(\theta_j\); \(L(\theta_j) = \binom{10}{7}\theta_j^7(1-\theta_j)^3\): the likelihood; \(\pi(\theta_j \mid \mathbf{x})\): the posterior probability of \(\theta_j\) given the data \(\mathbf{x}\) (7 heads in 10 flips).
| \(\theta\) | Prior \(\pi(\theta)\) | Likelihood \(L(\theta)\) | Prior \(\times\) likelihood | Posterior \(\pi(\theta \mid \mathbf{x})\) |
|---|---|---|---|---|
| 0.50 | 0.50 | 0.117 | 0.059 | 0.368 |
| 0.80 | 0.50 | 0.201 | 0.101 | 0.632 |
| Sum | 1 | 0.159 | 1 |
where \(m(\mathbf{x}) = \sum_l L(\theta_l)\,\pi(\theta_l)\): the normalizing constant, the sum of the fourth column.
\[\pi(\theta \mid \mathbf{x}) = \frac{L(\theta)\,\pi(\theta)}{m(\mathbf{x})}, \qquad m(\mathbf{x}) = \int L(\theta)\,\pi(\theta)\,d\theta\]
where \(f(x \mid \theta)\): the model’s density (or probability mass function) for one observation; \(\mathbf{x} = (x_1, \ldots, x_n)\): the observed data.
where \(L(\theta)\): the likelihood; \(\pi(\theta)\): the prior density; \(m(\mathbf{x})\): the normalizing constant.
\[\pi(\theta \mid \mathbf{x}) \propto L(\theta)\,\pi(\theta)\]
where \(\pi(\theta \mid \mathbf{x})\): the posterior density; \(L(\theta)\): the likelihood; \(\pi(\theta)\): the prior density; \(\propto\): proportional to, as a function of \(\theta\).
The Week in One Line
The posterior density is the likelihood times the prior, rescaled to integrate to 1.
| Distribution of \(\theta\) | Kernel | Range of \(\theta\) | Mean |
|---|---|---|---|
| \(\Betad(a, b)\) | \(\theta^{a-1}(1-\theta)^{b-1}\) | \(0 < \theta < 1\) | \(\dfrac{a}{a+b}\) |
| \(\Gam(a, b)\) | \(\theta^{a-1}e^{-b\theta}\) | \(\theta > 0\) | \(\dfrac{a}{b}\) |
| \(\Normal(a, b^2)\) | \(\exp\left\{-\dfrac{(\theta - a)^2}{2b^2}\right\}\) | \(-\infty < \theta < \infty\) | \(a\) |
where \(a\), \(b\): the parameters of the named distribution, with \(b > 0\), and \(a > 0\) for the Beta and the Gamma; \(\Gam(a, b)\) has shape \(a\) and rate \(b\); \(\Normal(a, b^2)\) has mean \(a\) and variance \(b^2\).
| Symbol | Meaning |
|---|---|
| \(\theta\) | the unknown parameter (\(\lambda\) for a Poisson rate, \(\mu\) for a normal mean) |
| \(\mathbf{x} = (x_1, \ldots, x_n)\) | the observed data |
| \(f(x \mid \theta)\) | the model: the density or probability mass function of one observation given \(\theta\) |
| \(L(\theta) = \prod_i f(x_i \mid \theta)\) | the likelihood: the model at the observed data, as a function of \(\theta\) |
| \(\pi(\theta)\); \(\pi(\theta \mid \mathbf{x})\) | the prior density of \(\theta\); its posterior density given the data |
| \(m(\mathbf{x}) = \int L(\theta)\,\pi(\theta)\,d\theta\) | the normalizing constant |
| \(\propto\) | equal up to a factor free of \(\theta\) |
\(\pi\) is always a density of the unknown. What stands behind the bar says what has been observed.
\[\pi(\theta) = \frac{\Gamma(\alpha+\beta)}{\Gamma(\alpha)\,\Gamma(\beta)}\,\theta^{\alpha-1}(1-\theta)^{\beta-1}, \qquad 0 < \theta < 1\]
where \(\alpha, \beta > 0\): the two parameters; \(\Gamma\): the gamma function; the fraction: the constant that makes the density integrate to 1.
\[\alpha = m\,n_0, \qquad \beta = (1 - m)\,n_0\]
where \(m = \alpha/(\alpha+\beta)\): the prior mean; \(n_0 = \alpha + \beta\): the prior sample size.
\[\pi(\theta) = \frac{\Gamma(\alpha + \beta)}{\Gamma(\alpha)\,\Gamma(\beta)}\,\theta^{\alpha-1}(1-\theta)^{\beta-1}, \qquad L(\theta) = \binom{n}{k}\,\theta^k(1-\theta)^{n-k}\]
where \(\alpha, \beta > 0\): the parameters of the prior; \(\Gamma\): the gamma function; \(k\): the number of successes in \(n\) trials. Both leading constants are free of \(\theta\).
\[\pi(\theta \mid \mathbf{x}) \propto \theta^k(1-\theta)^{n-k} \cdot \theta^{\alpha-1}(1-\theta)^{\beta-1} = \theta^{\alpha+k-1}(1-\theta)^{\beta+n-k-1}\]
where \(\mathbf{x}\): the data, \(k\) successes and \(n - k\) failures; \(\alpha\), \(\beta\): the parameters of the prior.
where \(\alpha\), \(\beta\): the parameters of the prior; \(k\): the number of successes in \(n\) trials.
where \(\Betad(\alpha, \beta)\): the prior, with pseudo-counts \(\alpha\) (heads) and \(\beta\) (tails).
where \(\theta\): the probability of a six on one roll; \(X\): the number of sixes in the 20 rolls; \(\mathbf{x}\): the observed rolls.
where \(m\): the prior mean; \(n_0\): the number of rolls the prior is worth.
\[\pi(\theta \mid \mathbf{x}) \propto \underbrace{\theta^{8}(1-\theta)^{12}}_{\text{likelihood}} \cdot \underbrace{\theta^{2-1}(1-\theta)^{10-1}}_{\text{kernel of the prior}} = \theta^{9}(1-\theta)^{21} = \theta^{10-1}(1-\theta)^{22-1}\]
where \(\mathbf{x}\): the data, 8 sixes and 12 other faces; the dropped factors, \(\binom{20}{8}\) and the constant of the prior, are free of \(\theta\).
1 - pbeta(1/6, 10, 22) and qbeta(c(0.025, 0.975), 10, 22).| Prior | Worth | Posterior | Posterior mean | \(P(\theta > 1/6 \mid \mathbf{x})\) |
|---|---|---|---|---|
| \(\Betad(1, 1)\) | 2 rolls | \(\Betad(9, 13)\) | 0.4091 | 0.996 |
| \(\Betad(2, 10)\) | 12 rolls | \(\Betad(10, 22)\) | 0.3125 | 0.975 |
| \(\Betad(10, 50)\) | 60 rolls | \(\Betad(18, 62)\) | 0.2250 | 0.901 |
| A significance test | The posterior | |
|---|---|---|
| Computes | \(P(X \ge 8 \mid \theta = 1/6) = 0.011\) | \(P(\theta > 1/6 \mid \mathbf{x}) = 0.975\) |
| A probability about | the data, given a value of \(\theta\) | \(\theta\), given the data |
| In words | 8 or more sixes would be rare with a fair die | the die favors six, with probability \(0.975\) under the \(\Betad(2, 10)\) prior |
| Needs | a null value and a meaning for “more extreme” | a prior |
where \(X\): the number of sixes in 20 rolls; \(0.011\): the p-value of the one-sided test of \(\theta = 1/6\).
| Likelihood | Conjugate prior | Posterior | Used for |
|---|---|---|---|
| Binomial | Beta | Beta | binary outcomes |
| Poisson | Gamma | Gamma | counts |
| Normal (known \(\sigma^2\)) | Normal | Normal | measurements |
| Normal (known \(\mu\)) | Inverse-Gamma | Inverse-Gamma | variances |
| Exponential | Gamma | Gamma | waiting times |
| Multinomial | Dirichlet | Dirichlet | categories |
qbeta, qgamma, qnorm).where \(L(\theta)\): the likelihood; kernel: the part of a density that depends on \(\theta\).
where \(\lambda\): the Poisson rate; \(\Gam(\alpha, \beta)\): shape \(\alpha\) and rate \(\beta\), with density \(\dfrac{\beta^\alpha}{\Gamma(\alpha)}\,\lambda^{\alpha-1}e^{-\beta\lambda}\) and mean \(\alpha/\beta\).
\[L(\lambda) = \prod_{i=1}^n \frac{\lambda^{x_i}e^{-\lambda}}{x_i!} \propto \lambda^{\sum_i x_i}\,e^{-n\lambda}, \qquad \pi(\lambda) \propto \lambda^{\alpha-1}e^{-\beta\lambda}\]
\[\pi(\lambda \mid \mathbf{x}) \propto \lambda^{\sum_i x_i}\,e^{-n\lambda} \cdot \lambda^{\alpha-1}e^{-\beta\lambda} = \lambda^{\alpha+\sum_i x_i-1}\,e^{-(\beta+n)\lambda}\]
where \(x_1, \ldots, x_n\): the observed counts; \(\alpha\), \(\beta\): the shape and rate of the prior; the dropped factors \(1/x_i!\) and \(\beta^\alpha/\Gamma(\alpha)\) are free of \(\lambda\).
\[\frac{1}{\tau_n^2} = \frac{1}{\tau_0^2} + \frac{n}{\sigma^2}, \qquad \mu_n = \tau_n^2\left(\frac{\mu_0}{\tau_0^2} + \frac{n\bar x}{\sigma^2}\right)\]
where \(\mu_0\), \(\tau_0^2\): the prior mean and variance; \(\mu_n\), \(\tau_n^2\): the posterior mean and variance; \(\bar x\): the sample mean; \(\sigma^2\): the known variance of one observation.
where every dropped factor is free of \(\mu\): \(e^{-\sum_i x_i^2/(2\sigma^2)}\), \(e^{-\mu_0^2/(2\tau_0^2)}\), \(e^{-\mu_n^2/(2\tau_n^2)}\), and the constants of the two densities.
\[\tau_n^2 = \frac{1}{0.08} = 12.5, \qquad \mu_n = 12.5\,(100 \times 0.04 + 110 \times 0.04) = 105\]
where \(\tau_n^2\), \(\mu_n\): the posterior variance and mean; precision: one over variance.
\[\E[\lambda \mid \mathbf{x}] = \frac{\alpha + \sum_i x_i}{\beta + n} = \underbrace{\frac{\beta}{\beta + n}}_{w}\cdot\frac{\alpha}{\beta} \;+\; \underbrace{\frac{n}{\beta + n}}_{1 - w}\cdot\bar x\]
where \(\alpha/\beta\): the prior mean; \(\bar x = \frac{1}{n}\sum_i x_i\): the sample mean; \(w\): the weight on the prior mean.
| Pair | Prior mean | Data estimate | Prior sample size \(n_0\) | Posterior mean |
|---|---|---|---|---|
| Beta–Binomial | \(\dfrac{\alpha}{\alpha+\beta}\) | \(\dfrac{k}{n}\) | \(\alpha + \beta\) | \(\dfrac{\alpha + k}{\alpha + \beta + n}\) |
| Gamma–Poisson | \(\dfrac{\alpha}{\beta}\) | \(\bar x\) | \(\beta\) | \(\dfrac{\alpha + \sum_i x_i}{\beta + n}\) |
| Normal–Normal | \(\mu_0\) | \(\bar x\) | \(\dfrac{\sigma^2}{\tau_0^2}\) | \(\dfrac{n_0\,\mu_0 + n\,\bar x}{n_0 + n}\) |
\[\text{posterior mean} = w \times \text{prior mean} + (1 - w) \times \text{data estimate}, \qquad w = \frac{n_0}{n_0 + n}\]
where \(n_0\): the number of observations the prior is worth; \(n\): the number in the data; \(w\): the prior’s weight.
Posterior Mean = Weighted Average
In every row the posterior mean is a weighted average of the prior mean and the data estimate. The prior’s weight is its sample size over the total.
where \(n_0\): the prior sample size; \(n\): the number of observations; \(w\): the weight on the prior mean.
where \(\mu_n\), \(\tau_n^2\): the posterior mean and variance; \(\bar x\): the sample mean of the \(n\) observations.
where \(\theta_C\), \(\theta_T\): the conversion rates of the two designs; \(X_C\), \(X_T\): the two counts of conversions; \(\mathbf{x}\): both observed counts.
rbeta(), rgamma(), rnorm(). A probability is then the share of the draws in a region: week 1’s Monte Carlo.where \(L(\theta)\): the likelihood; \(\pi(\theta)\): the prior density; \(\pi(\theta \mid \mathbf{x})\): the posterior density.
The frequentist asks how an estimate would vary over repeated samples. The Bayesian asks what the one sample in hand says about the unknown, and answers with a distribution. Both start from the same likelihood.
Next: unknowns we never get to observe. In a mixture, each observation carries a hidden label that says which component produced it. The posterior probability of that label, given the observation, is the two-coin table. The EM algorithm runs that table inside a loop.