Bayesian Inference Fundamentals


Bayesian Inference Fundamentals

Hope
Welcome to our conversation about Bayesian inference: the mathematics of reasoning about uncertain things using data. It matters in science generally, and especially in neuroimaging, where measurements and the states we infer from them are uncertain.

Maria
Let’s begin with a deliberately surprising scientific claim: does eating more chocolate make a nation more likely to produce Nobel Prize winners? One article pointed to a study showing a strong association between national chocolate consumption and Nobel laureates per population.

Hope
The graph compared chocolate consumption per person with Nobel laureates per ten million people. The reported correlation was about 0.8, with a p-value of 0.0001. That is a striking pattern, but it does not by itself tell us what causes what—or answer the question we care about.

Maria
Right. “Will I win the Nobel Prize if I eat lots of chocolate?” is too vague. A more precise question is: how does the amount of chocolate I eat affect the probability that I’ll win a Nobel Prize? In probability language, we’re asking for a conditional probability.

Hope
A conditional probability describes the chance of one event given that another is known. For example, the probability of winning a Nobel Prize given that you eat a particular amount of chocolate is different from the probability of eating that amount given that you’ve won a Nobel Prize. Mixing those up is a common reasoning trap.

Maria
Before Bayes’ rule, we need three basic probability ideas. Imagine a space of all possible observations, called omega, and two events within it, A and B. A marginal probability is the probability of A alone; a joint probability is the probability that A and B happen together; and a conditional probability is the chance of one event once we know the other occurred.

Hope
Here’s the weather example. Let A mean “the sun is shining,” and B mean “it is raining.” A table can list the probabilities of all four combinations: A and B, A and not B, not A and B, and not A and not B. In the example, those joint probabilities are 0.1, 0.5, 0.2, and 0.2.

Maria
Those four possibilities cover the whole space, so their probabilities add to one. To get a marginal probability, add the relevant joint probabilities across the table. For instance, the chance that the sun is shining is 0.1 plus 0.5, or 0.6; the chance that it isn’t shining is 0.4.

Hope
And the chance that it isn’t raining is 0.5 plus 0.2, or 0.7. Now suppose we ask, what’s the probability the sun is shining given that it isn’t raining? We focus only on the not-raining cases, then ask what proportion of those also have sunshine.

Maria
That’s the joint probability of sunshine and no rain divided by the total probability of no rain: 0.5 divided by 0.7, which is about 0.71. It isn’t 0.5, because 0.5 is the joint probability of sunshine and no rain, not the conditional probability after restricting attention to no-rain cases.

Hope
These examples lead to the basic rules of probability. Probabilities across all possibilities add to one. Marginalization means summing joint probabilities over the possible values of another variable. And the product rule connects joint and conditional probabilities: the probability of A and B equals the probability of A given B times the probability of B.

Maria
You can also write that joint probability the other way around: the probability of B given A times the probability of A. These rules are treated as axioms, and they can also be motivated by three reasonable requirements: represent plausibility with real numbers, behave consistently with common sense, and get the same answer whenever there are multiple valid ways to calculate something.

Hope
Now equate those two expressions for the joint probability and divide by the probability of B. You get Bayes’ rule: the probability of A given B equals the probability of B given A times the probability of A, divided by the probability of B. If we expand that denominator by summing across possible values of A, we’re using marginalization too.

Maria
The key power of Bayes’ rule is that it lets us reverse a conditional probability. We may know how likely an observation is under a hypothesis—B given A—but what we want is how likely the hypothesis is after seeing the observation—A given B. Bayes’ rule updates our probability distribution for A in light of B.

Hope
In that update, the prior is our probability distribution for A before seeing the observation. The likelihood tells us how probable the observation is under A, and the marginal probability of the observation provides the normalization. The result is the posterior: our updated probability distribution for A after observing B.

Maria
Back to chocolate and Nobel Prizes. Directly estimating the probability of winning a Nobel Prize at each level of chocolate consumption would be extraordinarily difficult. We’d need enormous groups assigned to different amounts of chocolate and would have to follow them for decades or longer, because Nobel Prizes are rare.

Hope
But the reverse conditional probability is more accessible: among Nobel Prize winners, how much chocolate do they eat? We could survey laureates. We could also estimate the prior probability of encountering a living laureate at random, and the general distribution of chocolate consumption in the population.

Maria
Those quantities let us use Bayes’ rule to work indirectly toward the probability we actually want. That’s the central idea: sometimes the quantity of interest is hard to measure directly, but other probabilities are easier to estimate and can help us infer it.

Hope
This is why probability is so important in science. Measurements are uncertain, and the things we reason about are uncertain too. Bayesian inference gives us a systematic way to represent and update that uncertainty. It echoes Laplace’s description of probability theory as common sense reduced to calculation.

Maria
In neuroimaging, the forward model describes how a brain state, represented by theta, gives rise to measurements, represented by Y. We can model the probability distribution of measurements given a brain state. But in an experiment, we observe Y and want to infer theta given Y.

Hope
Bayesian inference turns that forward model around: from a model of brain-to-measurement, together with the actual measurement, we infer a probability distribution over possible brain states. That is the move from the generative model to the quantity we care about.

Maria
Let’s see how this approach can guide a practical decision. Imagine a company choosing between parts from manufacturers A and B. B’s parts cost more, but might last longer. We observe lifetimes from both manufacturers, and the sample for B looks longer-lived.

Hope
A common first comparison is the arithmetic mean. Taking a mean is not merely lazy: the errors in individual measurements can cancel out, and using the mean as a maximum-likelihood estimate corresponds to assuming Gaussian errors. When we know little beyond a quantity’s location and variance, a Gaussian error model can be a reasonable, conservative choice.

Maria
A classical workflow might compare the sample variances with an F-test, choose an equal- or unequal-variance t-test, and then ask whether the mean difference is statistically significant. In this example, the variance test had a p-value around 0.33, so the procedure used an equal-variance t-test. That test did not find a significant difference between the means.

Hope
But “not statistically significant” does not answer the company’s decision question. Looking at the data, someone might reasonably favor B, yet that sequence of tests appears to say there’s no evidence of a difference. Bayesian inference lets us ask a more direct question and carry uncertainty forward rather than reducing the result to a yes-or-no significance label.

Maria
First we define the question and the decision rule. For this example: if B’s parts last at least three hours longer than A’s with a probability of at least 80 percent, we’ll choose B, because B costs more. That gives us a concrete threshold tied to the decision.

Hope
Next we specify a model. The example uses a Gaussian likelihood and a Gaussian-gamma prior. Once the model is fitted, it gives us joint posterior distributions for the mean lifetimes of A and B. We can then ask directly what probability the posterior assigns to the difference we care about.

Maria
The question becomes: what is the probability that the mean lifetime for B minus the mean lifetime for A is greater than three hours? In the example, that probability is 0.9501. Since it exceeds the decision threshold of 0.8, the stated rule favors buying from B.

Hope
That 0.95 is not a classical p-value, and it is not being compared with a p-value cutoff of 0.05. It is the posterior probability of a specific claim about the difference in lifetimes, given the model and data. The distinction matters: the two approaches are answering different questions.

Maria
The broader lesson is to preserve uncertainty through the analysis. Instead of making a series of early binary choices—such as choosing a test and then classifying a result as significant or not—we can propagate uncertainty into posterior distributions and make the decision at the end.

Hope
The practical Bayesian sequence is: define the question of interest, specify a likelihood and prior, calculate the posterior using Bayes’ rule, and ask the original question of that posterior. Some calculations can be technically difficult, but software and sampling methods can handle many of them.

Maria
Classical inference often starts with a null hypothesis and asks how unusual the observed data would be if that hypothesis were true. If the data seem sufficiently unlikely, the null is rejected. But there can be latitude in choosing the null hypothesis, and a sequence of procedural choices can create pitfalls.

Hope
Bayesian inference instead builds a model of the situation and examines the posterior distribution of the quantity of interest. If a final decision has to be binary, we can base it on how much posterior probability lies beyond a decision threshold, as we did with the three-hour difference.

Maria
That doesn’t mean classical statistics can never get the right answer. Done carefully, classical methods can solve the same kinds of problems and yield the same probabilistically correct answer. The argument is that there are more ways to go wrong with a collection of separate procedures, while the Bayesian framework starts from probability rules and makes uncertainty explicit.

Hope
The names can also be misleading: Bayesian ideas date back to the eighteenth century and were developed by Laplace around 1800, while classical statistics became prominent in the 1920s and 1930s. The once-contentious divide has softened, and there has been substantial reconciliation between the approaches.

Maria
Now let’s connect Bayes’ rule to odds. The odds of A are the probability of A divided by the probability of not A. If the probability is one half, the odds are one. You can convert between odds and probabilities, and Bayes’ rule can be expressed as posterior odds equal to prior odds multiplied by a likelihood ratio.

Hope
That likelihood ratio compares how probable the observation is if a hypothesis is true with how probable it is if the hypothesis is false. It is often called the Bayes factor. The Bayes factor measures how strongly the observation favors one hypothesis over its alternative.

Maria
People can begin with different prior odds because they have different prior beliefs. But for the same hypotheses and observation, the Bayes factor is the same: it tells both people how the evidence changes their odds. Their posterior odds may still differ because their starting odds differed.

Hope
This connects directly to model comparison. For hypotheses H1 and H0, the posterior odds are the prior odds multiplied by the Bayes factor. In this setting, the likelihood ratio is a ratio of marginal likelihoods, also called model evidence.

Maria
Taking logarithms turns that ratio into a difference: the log Bayes factor is the log model evidence for H1 minus the log model evidence for H0. This kind of comparison appears in neuroimaging, including comparisons of dynamic causal models.

Hope
Another term you’ll encounter is negative variational free energy, sometimes loosely called free energy. In the account here, it can be decomposed into accuracy minus complexity. In model comparison, it’s important to know what a score means and how it is being used.

Maria
AIC, BIC, Bayes factors, log model evidence, and free energy are among the scores used to compare models. A score by itself is not very informative; the difference between models’ scores is what matters. AIC and BIC approximate log model evidence and penalize complexity using heuristics, which may not represent complexity as accurately.

Hope
Log model evidence can handle complexity more directly, but it is sensitive to the priors chosen by the modeller. Changing priors can change the comparison, so if a model-comparison result is important, examine the assumptions behind it rather than treating the score as automatic truth.

Maria
There are three practical questions to ask about a model. First: does it let us answer our scientific question? A model might fit the data well and still fail to address what we set out to learn.

Hope
Second: does the prior predictive distribution make sense? Simulate observations from the model before fitting the data. The resulting distribution should cover plausible observations given background knowledge, without including absurd behavior or impossible values.

Maria
That helps explain why a very loose or supposedly uninformative prior can be a problem. It may produce prior predictions that are far too broad and include implausible outcomes, making the model vulnerable to overfitting. A tighter prior can be the more conservative choice when it keeps predictions within a sensible range.

Hope
Third: does the posterior predictive distribution make sense? After fitting the data, simulate new data using the posterior parameter distributions. The simulated data should reproduce patterns seen in the observations. If the scientific question, prior predictions, and posterior predictions all make sense, that is strong practical reassurance about the model.

Maria
Bayesian inference has many applications in neuroimaging. It supports statistical inference and posterior probability maps, and Bayesian priors provide regularization that segmentation and normalization depend on.

Hope
It also underlies dynamic causal modeling, both for inference and model comparison, and supports multivariate decoding. Bayesian inference is used in time-series analysis and enables model comparison for group studies as well.

Maria
So the thread running through the whole episode is simple: state the question clearly, represent uncertainty with probability distributions, use a model to connect observations to the quantities we care about, and let Bayes’ rule update what we believe. Then keep checking that the model’s assumptions and predictions make scientific sense.

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