Bayesian inference
Difference between Bayesian and frequentist inference
The difference is in the definition of probability
Bayesian
- Bayesian Approach to Statistics - Probability is a measure of uncertainty.
- Both parameters and data in a statistical model can contain uncertainty
- "The population mean is between 3.5 and 5 with probability 28%"
Frequentist
- Frequentist Approach to Statistics - Probability is a proportion (frequency) of successes in an infinite number of repeated experiments
- This is how it was explained in the Probability - Fundamentals lecture from Eva's course
- Only data and estimators can be given a probabilistic statement, not parameters
Under a frequentist definition we cannot say for example that "The population mean is between 3.5 and 5 with probability 28%".
However, we can say "the estimator for population mean is between 3.5 and 5 in 28% of the experiments".
The Bayesian definition is inclusive of the frequentist definition, but not the other way around.
Example - fishes
This example requires an understanding of conditional distribution, marginalization and integration (calculus), which are essential in Bayesian stats
- Conditional distribution was discussed as part of Categorical covariates. It's the distrubution of a random response variable
given that another variable is at a fixed position - Marginalization is basically the opposite of conditional distribution - the effect of a single variable on the response without the effect of another variable
- Integration was discussed in Continuous Distributions lecture in Eva's class (area under a curve)
Let's go back to our fish population mean example. Assuming we have a population of individuals whose length (
This is our probability density function and observation model.
- Assume that the variance
is known, so we are only trying to use statistical inference to find the population mean - As shown in Week 3 (maximum likelihood estimate), the likelihood function for a normal distribution is:
- Therefore the maximum likelihood function is
. This is a function of the parameters ( ) when the data ( ) is fixed
Conditional Probability
The first plot shows how the probability density of
!lecture_notes_week5_1, p.3
Let's say that there is an equal chance of
Joint probability density
From Bayes' Theorem, the joint probability density for
This is a function with two parameters now. If we look at how they co-vary with the conditional distributions we will get
If we had a continuous (non-discrete) values of
Of course, our example discrete prior probability values are not very applicable to real life, especially to our fish example. In theory, their mean could be any positive real number (infinitely many possible values). Therefore, instead of summing up discrete values, we should instead use an integral from
Bayes theorem
As discussed in math class we can use Bayes' Theorem to describe this:
Anatomy
- Posterior probability - the probability of getting this mean value ( ) given this data ( ). - Likelihood function - the likelihood of getting these value of given -in this example this is the Gaussian distribution - Prior probability density - the likelihood of having this value of in any scenario. - Marginal probability density or marginal likelihood of model. We called this "total probability" in Eva's course, these are the same thing.
Applied
If we sampled one individual from the population which has
In R:
# possible values for mu
mu = seq(-2,7,by=0.1)
# Uniform probability for values of mu
Pr.mu = rep(1/length(mu),length(mu))
# e.g. equal probability of 1/91 for being 91 discrete values.
# Likelihood function for mu
y1 = 1
likelihood = dnorm(y1, mean = mu, sd = sqrt(sigma2))
## Bayes theorem
posterior.prob = Pr.mu * likelihood / sum(Pr.mu * likelihood)
# Plot the posterior distribution
plot(mu, posterior.prob)
!lecture_notes_week5_1, p.7
This result is a probability density at each of these 90 discrete values from -2 to 7 at 0.1 intervals. Since this is a probability density, we can do statistical inference like getting the mean and variance.
The Posterior mean, which is similar to the maximum likelihood estimate:
In R, we would calculate this with:
posterior.mean = sum(mu*posterior.prob) # posterior.prob is a vector with 91 values
print(posterior.mean)
## [1] 1
We can also calculate the posterior probability of the population mean being above zero:
posterior.prob.over.zero = sum(posterior.prob * (mu>0) )
print(posterior.prob.over.zero)
## [1] 0.9833605
With integrals
We are still pretty far from actually applying this - these uniform distributions are not realistic. To get something more realistic, we need to integrate.
More realisitc Posterior mean with integrals:
In frequentist statistics, the most complex operation to do is finding maxima and minima - AKA derivatives. For Bayesian statistics, estimating parameters requires the use of integrals, which are very difficult to calculate by hand or with a computer (uses much processing power). This is why Bayesian statistics has only started to become more useful after the 1990s when more powerful computers became available.
Bayesian Computation
In our example, we used 91 points as an approximation for integration. If we are using many more points and adding more parameters this kind of calculation becomes terrible - for example if we had a sequence of 100 plausible values and ten parameters, we would need to calculate
The most common way to do these tough calculations is the Markov chain Monte Carlo methods. Used to sample random realizations from the posterior distribution, then use this posterior sample to calculate the inference summaries.
Using some R techniques which aren't actually important for the lesson (just use for visualizing) we can visualize a histogram of the posterior probability density based on the random samples. Now, using these samples we can calculate the "inferential summaries" such as the Posterior mean with this formula:
Where
Bayesian applications, the next lecture, goes into more detail about libraries used for Bayesian analysis.
Prior density
- In order for Bayesian stats to work, the "Prior distribution" needs to be known
- There are debates about whether this is appropriate for objective science
- However, for basic applications, we don't need to worry about it too much
- The default prior probabilities for fixed effects, variance, and Random Effects are well justified and available as default options in Bayesian software like R