1. Home
  2. Explore
  3. Statistics
  4. Bayesian Inference Fundamentals

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Bayesian Inference Fundamentals

Bayesian Inference: Reasoning Under Uncertainty

1. Why Bayesian inference is useful

Scientific measurements and the quantities scientists want to understand are uncertain. Bayesian inference provides a mathematical framework for reasoning about that uncertainty and updating conclusions when new observations become available.

A useful way to see the need for careful reasoning is to consider the claim that eating chocolate increases the chance of winning a Nobel Prize. A reported comparison across nations found a strong correlation between per-capita chocolate consumption and Nobel laureates per population: the correlation was about 0.7910.7910.791, with a reported ppp-value of 0.00010.00010.0001.

These statistics describe an association in the observed data, but they do not establish that eating chocolate causes people to win Nobel Prizes. The data compare nations rather than individuals, so the association could reflect other differences between nations, such as wealth, education, research investment, or access to scientific careers. This is an example of the general distinction between association and causation.

The first step in investigating a scientific claim is to state the question precisely. “Does chocolate make people clever?” is vague. A more precise question might be:

What is the probability of winning a Nobel Prize given a particular amount of chocolate consumption?

This is a conditional probability. In notation, if NNN denotes winning a Nobel Prize and CCC denotes a specified chocolate-consumption level, the question is P(N∣C)P(N\mid C)P(N∣C).

Conditional probabilities must be distinguished carefully. The probability of winning given chocolate consumption, P(N∣C)P(N\mid C)P(N∣C), is not the same as the probability of eating a certain amount of chocolate given that a person has won, P(C∣N)P(C\mid N)P(C∣N). Confusing these two quantities is a common reasoning error.


2. Events, probability spaces, and joint probabilities

Probability can be introduced by considering a set Ω\OmegaΩ of possible outcomes, called a sample space or probability space. Events such as AAA and BBB are subsets of Ω\OmegaΩ.

Three basic kinds of probability are especially useful:

Marginal probability

The marginal probability of an event describes the probability of that event without conditioning on another event. It is written as P(A)P(A)P(A) or P(B)P(B)P(B).

Joint probability

The joint probability that two events occur together is written as P(A,B)P(A,B)P(A,B) or P(A∩B)P(A\cap B)P(A∩B). It represents the probability that an outcome belongs to both AAA and BBB.

Conditional probability

The conditional probability of AAA given BBB is written as P(A∣B)P(A\mid B)P(A∣B). It asks how probable AAA is among outcomes for which BBB is already known to be true.


3. A probability table: sunshine and rain

Let:

  • AAA mean “the sun is shining”

  • BBB mean “it is raining”

  • Aˉ\bar AAˉ mean “the sun is not shining”

  • Bˉ\bar BBˉ mean “it is not raining”

Suppose the joint probabilities are:

  • P(A,B)=0.1P(A,B)=0.1P(A,B)=0.1: it is sunny and raining.

  • P(A,Bˉ)=0.5P(A,\bar B)=0.5P(A,Bˉ)=0.5: it is sunny and not raining.

  • P(Aˉ,B)=0.2P(\bar A,B)=0.2P(Aˉ,B)=0.2: it is not sunny and it is raining.

  • P(Aˉ,Bˉ)=0.2P(\bar A,\bar B)=0.2P(Aˉ,Bˉ)=0.2: it is neither sunny nor raining.

These four combinations cover all possible cases, so their probabilities must sum to one:

0.1+0.5+0.2+0.2=10.1+0.5+0.2+0.2=10.1+0.5+0.2+0.2=1

The marginal probability of sunshine is found by adding the joint probabilities for all cases in which the sun is shining:

P(A)=P(A,B)+P(A,Bˉ)=0.1+0.5=0.6P(A)=P(A,B)+P(A,\bar B)=0.1+0.5=0.6P(A)=P(A,B)+P(A,Bˉ)=0.1+0.5=0.6

Likewise, the probability of no sunshine is:

P(Aˉ)=P(Aˉ,B)+P(Aˉ,Bˉ)=0.2+0.2=0.4P(\bar A)=P(\bar A,B)+P(\bar A,\bar B)=0.2+0.2=0.4P(Aˉ)=P(Aˉ,B)+P(Aˉ,Bˉ)=0.2+0.2=0.4

Marginal probabilities can be thought of as totals placed at the margins of a table of joint probabilities. They are found by marginalization: summing over the possible values of the other variable.

The marginal probability that it is not raining is:

P(Bˉ)=P(A,Bˉ)+P(Aˉ,Bˉ)=0.5+0.2=0.7P(\bar B)=P(A,\bar B)+P(\bar A,\bar B)=0.5+0.2=0.7P(Bˉ)=P(A,Bˉ)+P(Aˉ,Bˉ)=0.5+0.2=0.7

Calculating a conditional probability

The probability that the sun is shining given that it is not raining is not simply the joint probability P(A,Bˉ)P(A,\bar B)P(A,Bˉ). It is the proportion of all non-rainy cases in which the sun is shining:

P(A∣Bˉ)=P(A,Bˉ)P(Bˉ)=0.50.7≈0.71P(A\mid\bar B) = \frac{P(A,\bar B)}{P(\bar B)} = \frac{0.5}{0.7} \approx 0.71P(A∣Bˉ)=P(Bˉ)P(A,Bˉ)​=0.70.5​≈0.71

The denominator includes every case in which it is not raining. The numerator includes only those cases in which it is both not raining and sunny.


4. The basic rules of probability

Probability calculations rely on a small set of fundamental rules.

Normalization

The probabilities of all mutually exclusive and exhaustive outcomes must sum to one. For a discrete variable AAA:

∑aP(A=a)=1\sum_a P(A=a)=1∑a​P(A=a)=1

Marginalization

A joint probability can be summed over possible values of one variable to obtain the marginal probability of another:

P(B)=∑aP(A=a,B)P(B)=\sum_a P(A=a,B)P(B)=∑a​P(A=a,B)

For continuous variables, summation is replaced by integration.

The product rule

A joint probability can be expressed as a conditional probability multiplied by a marginal probability:

P(A,B)=P(A∣B)P(B)P(A,B)=P(A\mid B)P(B)P(A,B)=P(A∣B)P(B)

It can also be written in the reverse direction:

P(A,B)=P(B∣A)P(A)P(A,B)=P(B\mid A)P(A)P(A,B)=P(B∣A)P(A)

These are two expressions for the same joint probability. The product rule is the basis for deriving Bayes’ rule.

The rules of probability can also be motivated through general requirements for rational reasoning. If degrees of plausibility are represented by real numbers, if those numbers are to correspond sensibly to common reasoning, and if calculations must be internally consistent, then probability theory provides the rules that such reasoning must follow.


5. Bayes’ rule and belief updating

Equating the two expressions for the joint probability gives:

P(A∣B)P(B)=P(B∣A)P(A)P(A\mid B)P(B)=P(B\mid A)P(A)P(A∣B)P(B)=P(B∣A)P(A)

Dividing by P(B)P(B)P(B) gives Bayes’ rule:

P(A∣B)=P(B∣A)P(A)P(B)P(A\mid B)=\frac{P(B\mid A)P(A)}{P(B)}P(A∣B)=P(B)P(B∣A)P(A)​

Bayes’ rule relates the probability of a hypothesis after observing evidence to quantities describing the hypothesis and evidence before that update.

Its terms have common interpretations:

  • Posterior probability, P(A∣B)P(A\mid B)P(A∣B): the probability of AAA after observing BBB.

  • Likelihood, P(B∣A)P(B\mid A)P(B∣A): the probability of observing BBB if AAA is true.

  • Prior probability, P(A)P(A)P(A): the probability assigned to AAA before observing BBB.

  • Evidence or marginal probability, P(B)P(B)P(B): the overall probability of observing BBB across possible states of AAA.

For a discrete set of possible values of AAA, the evidence can be expanded by marginalization:

P(B)=∑aP(B∣A=a)P(A=a)P(B)=\sum_a P(B\mid A=a)P(A=a)P(B)=∑a​P(B∣A=a)P(A=a)

Bayes’ rule therefore provides a principled way to update a probability distribution over possibilities in light of new observations. A probability distribution represents the uncertainty or belief associated with those possibilities. After new evidence arrives, the distribution changes from a prior distribution to a posterior distribution.


6. Using Bayes’ rule to reverse a conditional probability

Bayes’ rule is especially useful when the conditional probability needed to answer a question is difficult to measure directly, but the reverse conditional probability is easier to obtain.

Let NNN mean “a person has won a Nobel Prize” and CCC mean “a person consumes a specified amount of chocolate.” Then:

P(N∣C)=P(C∣N)P(N)P(C)P(N\mid C)=\frac{P(C\mid N)P(N)}{P(C)}P(N∣C)=P(C)P(C∣N)P(N)​

The probability of winning given chocolate consumption, P(N∣C)P(N\mid C)P(N∣C), may be extremely hard to estimate directly. A direct study would require many people assigned to different chocolate-consumption levels and followed for decades, because Nobel Prizes are rare.

The quantities on the right-hand side may be easier to estimate:

  • P(C∣N)P(C\mid N)P(C∣N): the distribution of chocolate consumption among Nobel laureates, estimated from a survey.

  • P(N)P(N)P(N): the base rate of being a Nobel laureate in the population.

  • P(C)P(C)P(C): the distribution of chocolate consumption in the general population.

Bayes’ rule shows how these quantities can be combined to infer the conditional probability of interest indirectly.

The base rate matters greatly. Even if a characteristic is common among Nobel laureates, the probability that someone with that characteristic will become a laureate may still be very small because Nobel laureates are exceptionally rare. The inverse conditional probabilities are not interchangeable.


7. Bayesian inference in neuroimaging

Neuroimaging commonly involves a forward model and an inverse scientific question.

A forward model describes how an underlying brain state generates measurements. Let θ\thetaθ represent a brain state or model parameter and let YYY represent an observed measurement. The forward model describes the distribution of observations given the state:

P(Y∣θ)P(Y\mid\theta)P(Y∣θ)

This is the likelihood: it specifies what measurements are expected under different possible brain states.

In an experiment, researchers observe YYY and want to infer the state that produced it. The quantity of interest is therefore:

P(θ∣Y)P(\theta\mid Y)P(θ∣Y)

Bayesian inference combines the forward model with prior knowledge about possible states:

P(θ∣Y)=P(Y∣θ)P(θ)P(Y)P(\theta\mid Y) = \frac{P(Y\mid\theta)P(\theta)}{P(Y)}P(θ∣Y)=P(Y)P(Y∣θ)P(θ)​

Thus, Bayesian inference turns a model that predicts measurements from brain states into an inference about brain states from measurements. This is important because measurements are noisy and multiple underlying states may be compatible with the same observation.


8. A decision example: comparing component lifetimes

Suppose a company is choosing between components from manufacturers AAA and BBB. Components from BBB cost more, but may last longer. The available data consist of observed lifetimes for samples from each manufacturer.

A simple comparison might use the arithmetic mean of each sample. The mean is a reasonable summary in many settings because positive and negative measurement errors can cancel across observations. Treating the mean as a maximum-likelihood estimate also corresponds to a Gaussian model for measurement errors. When the known information about errors is limited largely to their variance, a Gaussian assumption is often a reasonable conservative choice.

However, an estimate alone does not describe all uncertainty. Bayesian inference represents uncertainty about the lifetimes with probability distributions and allows a decision rule to be applied to those distributions.

Specify the question and decision rule

A precise question is:

What is the probability that the mean lifetime of components from BBB exceeds the mean lifetime of components from AAA by more than three hours?

Let μA\mu_AμA​ and μB\mu_BμB​ denote the mean lifetimes for the two manufacturers. The probability of interest is:

P(μB−μA>3∣data)P(\mu_B-\mu_A>3\mid \text{data})P(μB​−μA​>3∣data)

A decision rule might be:

  • Choose manufacturer BBB if the probability that its components last more than three hours longer is at least 0.80.80.8.

  • Otherwise, choose manufacturer AAA or seek further information.

This rule accounts for the extra cost of the components from BBB by requiring evidence for a meaningful increase in lifetime.

Specify the model and calculate the posterior

A model can include:

  • A likelihood describing how observed lifetimes vary around the manufacturers’ underlying mean lifetimes.

  • A prior describing plausible values of those lifetimes before observing the data.

In the example, Gaussian likelihoods and Gaussian-gamma priors are used. Once the posterior distributions for μA\mu_AμA​ and μB\mu_BμB​ are calculated, the probability of interest can be evaluated from them. With posterior samples, this can be done by computing μB−μA\mu_B-\mu_AμB​−μA​ for each paired draw and finding the proportion of draws greater than 333.

The resulting probability is reported as approximately 0.95010.95010.9501. Since this is greater than the decision threshold of 0.80.80.8, the stated decision rule favors manufacturer BBB.

This probability is not a classical ppp-value and does not derive its meaning from a 0.050.050.05 significance threshold. It directly addresses the specified event under the model and data: that the mean lifetime difference exceeds three hours.


9. Bayesian and classical approaches to inference

Classical hypothesis testing

A classical test typically:

  1. Defines a null hypothesis.

  2. Calculates how unusual the observed data would be if that null hypothesis were true.

  3. Rejects or fails to reject the null hypothesis according to a chosen significance threshold.

For a comparison of means, a ttt-test may be used. Depending on the assumptions, a test may use equal or unequal variances. An FFF-test is sometimes used to compare variances, although failing to find a statistically significant variance difference does not prove that the variances are equal.

A non-significant result does not show that there is no meaningful difference. It means that the data did not provide sufficient evidence to reject the chosen null hypothesis under the test procedure. A test of this kind may not directly answer a practical question such as whether one component is likely to last at least three hours longer.

Bayesian inference

A Bayesian analysis instead:

  1. Defines the quantity or event of interest.

  2. Specifies a likelihood and prior.

  3. Calculates the posterior distribution.

  4. Uses that posterior to answer the question or apply a decision rule.

In the component example, the posterior probability of a difference greater than three hours answers a more specific question than whether a test crosses a significance threshold.

Keeping uncertainty through the analysis

A succession of binary decisions can discard information. For example, an analyst may choose one test or another, decide whether a result is “significant,” and then treat that decision as if it were certainty. Each fork can cause uncertainty to be lost or the analysis to depend too strongly on arbitrary thresholds.

A Bayesian analysis aims to propagate uncertainty through the full sequence of calculations. The final decision is then made using the resulting probability distribution rather than a series of intermediate yes-or-no classifications.

This does not mean classical statistics can never provide a correct answer. With careful choices and appropriate methods, classical procedures can address many of the same scientific questions and may agree with Bayesian results. The distinction is that Bayesian inference makes probability distributions over unknown quantities central to the analysis, while classical procedures often require additional methods and decisions to obtain comparable conclusions.


10. Odds and the Bayes factor

Probability can be expressed as odds. For an event AAA, the odds in favor of AAA are:

Odds⁡(A)=P(A)P(Aˉ)\operatorname{Odds}(A)=\frac{P(A)}{P(\bar A)}Odds(A)=P(Aˉ)P(A)​

For example, if P(A)=0.5P(A)=0.5P(A)=0.5, then P(Aˉ)=0.5P(\bar A)=0.5P(Aˉ)=0.5, so the odds are 111, or 1:11:11:1.

Probability can be recovered from odds. If the odds in favor of AAA are ooo, then:

P(A)=o1+oP(A)=\frac{o}{1+o}P(A)=1+oo​

The wording used for betting odds can vary. Odds “in favor” and odds “against” express reciprocal quantities, so the convention must be checked before translating betting odds into a probability.

Posterior odds and likelihood ratio

Bayes’ rule can be written in odds form:

P(H∣Y)P(Hˉ∣Y)=P(Y∣H)P(Y∣Hˉ)P(H)P(Hˉ)\frac{P(H\mid Y)}{P(\bar H\mid Y)} = \frac{P(Y\mid H)}{P(Y\mid\bar H)} \frac{P(H)}{P(\bar H)}P(Hˉ∣Y)P(H∣Y)​=P(Y∣Hˉ)P(Y∣H)​P(Hˉ)P(H)​

This says:

Posterior odds = likelihood ratio ×\times× prior odds.

The ratio

P(Y∣H)P(Y∣Hˉ)\frac{P(Y\mid H)}{P(Y\mid\bar H)}P(Y∣Hˉ)P(Y∣H)​

is the Bayes factor for HHH over Hˉ\bar HHˉ. It measures how much more strongly the observation favors HHH than its alternative.

Different analysts can begin with different prior odds and therefore arrive at different posterior odds. But for the same hypotheses and observation, the Bayes factor is the same: it describes how the observation changes the odds, not what the starting odds were.


11. Bayes factors and model comparison

For two hypotheses or models, H1H_1H1​ and H0H_0H0​, posterior odds can be written as:

P(H1∣Y)P(H0∣Y)=P(Y∣H1)P(Y∣H0)P(H1)P(H0)\frac{P(H_1\mid Y)}{P(H_0\mid Y)} = \frac{P(Y\mid H_1)}{P(Y\mid H_0)} \frac{P(H_1)}{P(H_0)}P(H0​∣Y)P(H1​∣Y)​=P(Y∣H0​)P(Y∣H1​)​P(H0​)P(H1​)​

The probabilities P(Y∣H1)P(Y\mid H_1)P(Y∣H1​) and P(Y∣H0)P(Y\mid H_0)P(Y∣H0​) are marginal likelihoods, also called model evidence. Each marginal likelihood averages the probability of the observed data over the parameter values allowed by that model, weighted by the model’s prior distribution.

The Bayes factor for comparing the two models is:

BF10=P(Y∣H1)P(Y∣H0)\mathrm{BF}_{10} = \frac{P(Y\mid H_1)}{P(Y\mid H_0)}BF10​=P(Y∣H0​)P(Y∣H1​)​

Taking logarithms turns the ratio into a difference:

log⁡BF10=log⁡P(Y∣H1)−log⁡P(Y∣H0)\log \mathrm{BF}_{10} = \log P(Y\mid H_1)-\log P(Y\mid H_0)logBF10​=logP(Y∣H1​)−logP(Y∣H0​)

A model’s evidence score is not usually interpreted in isolation. Its value is most informative when compared with the score for another model.

Complexity and accuracy

Model comparison must consider both how well a model accounts for the data and how complex the model is. A common conceptual decomposition of a variational objective is:

accuracy−complexity\text{accuracy}-\text{complexity}accuracy−complexity

Here:

  • Accuracy rewards a model for explaining the observed data.

  • Complexity penalizes a model for using a complicated or highly flexible explanation, often relative to its prior.

Terminology and signs vary across fields and software. Variational free energy is commonly used as a bound or approximation related to log model evidence, with an accuracy-minus-complexity decomposition. The precise sign convention should be checked in the relevant method.


12. Model comparison criteria and their limitations

Several scores are used to compare models, including:

  • Akaike information criterion, or AIC

  • Bayesian information criterion, or BIC

  • Bayes factors

  • Log model evidence

  • Variational free energy

AIC and BIC approximate aspects of model evidence and penalize complexity using relatively simple formulas. These criteria can be useful, but their complexity penalties may not represent a model’s complexity as accurately as a full calculation of model evidence.

Model evidence is also sensitive to prior assumptions. Changing a model’s priors can change its evidence and potentially alter the result of a model comparison. Therefore, model-selection conclusions should be interpreted in light of the assumptions that produced them.

Formal scores cannot replace the scientific question. A model that fits the data well is not useful for a particular study if it cannot answer that study’s question.


13. Choosing and checking prior distributions

A prior distribution should represent plausible parameter values before the data are fitted. A practical way to evaluate a prior is to simulate observations from the model before fitting the actual data. The resulting distribution of simulated observations is the prior predictive distribution.

A reasonable prior predictive distribution should:

  • Include observations that are plausible given background knowledge.

  • Avoid assigning substantial probability to impossible or absurd outcomes.

  • Be wide enough to represent genuine uncertainty, but not so wide that it permits unreasonable behavior.

A very flat or diffuse prior is not automatically “uninformative.” It may produce a prior predictive distribution that includes impossible values. Such a model can be overly flexible and vulnerable to overfitting. A tighter prior can be more defensible when it rules out outcomes that are already known to be implausible.

After fitting the data, the model can be checked using the posterior predictive distribution. The procedure is:

  1. Use the posterior distributions of the model’s parameters.

  2. Simulate new, artificial data from the fitted model.

  3. Compare patterns in the simulated data with patterns in the observed data.

If the simulated data reproduce important features of the real observations, that supports the model’s adequacy. If they fail to reproduce important patterns, the model may be missing relevant structure.

Three central questions guide model evaluation:

  1. Does the model answer the scientific question?

  2. Does the prior predictive distribution produce plausible observations?

  3. Does the posterior predictive distribution reproduce important patterns in the observed data?

When all three answers are satisfactory, the model has passed important practical checks, even if formal model-comparison scores are also examined.


14. Applications of Bayesian inference in neuroimaging

Bayesian inference appears in many neuroimaging methods because measurements are noisy and the underlying brain states are uncertain.

Statistical inference

Posterior distributions summarize uncertainty about effects or parameters. Posterior probability maps represent spatially varying posterior information across the brain.

Segmentation and normalization

Image segmentation and spatial normalization rely on prior constraints or regularization. These priors help select plausible solutions when the image data alone do not uniquely determine the underlying structure. Without such constraints, the problem may be poorly determined or impossible to solve reliably.

Dynamic causal modeling

Dynamic causal modeling uses Bayesian inference both to estimate model parameters and to compare candidate models of interactions among brain regions.

Multivariate decoding

Multivariate decoding uses measured patterns to infer conditions or states. Bayesian principles can contribute to estimating uncertainty and constraining the possible solutions.

Time-series analysis and group studies

Bayesian methods are used in neuroimaging time-series analysis and in model comparison across groups. More generally, Bayesian inference is useful wherever the goal is to infer uncertain latent states or model parameters from noisy measurements.


15. Central principles

  • Conditional probabilities must be distinguished. In general, P(A∣B)P(A\mid B)P(A∣B) is not the same as P(B∣A)P(B\mid A)P(B∣A).

  • Bayes’ rule updates beliefs using evidence. It combines prior probabilities, likelihoods, and the overall probability of the observations.

  • Uncertainty should be propagated. Retaining probability distributions through an analysis provides more information than replacing uncertainty with repeated binary decisions.

  • Decisions should reflect the scientific or practical question. A probability about a meaningful threshold can be more directly useful than a generic significance label.

  • Models require checking. Priors should generate plausible predictions, and fitted models should reproduce important features of observed data.

  • Model comparison is conditional on assumptions. Evidence scores depend on the models, priors, and data being compared.

Bayesian inference expresses uncertain knowledge with probability distributions and uses the rules of probability to update that knowledge as observations accumulate.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent