25 Intro to Bayesian Inference (1)
25 Intro to Bayesian Inference (1)
com
#EPIB621-25
22
26 Introduction to Bayesian Inference
Qihuang Zhang
→ We can decide the prior according to the likelihood (data generating model)
5
Conjugate priors – example 1
Normal-Normal
a normal prior
𝜃 ∼ 𝑁(µ, 𝜏 2 )
(known hyper-parameters 𝜇 and 𝜏 ) results in a normal posterior
𝜎2 2 −1
𝜇 + 𝜏 𝑦ത 𝑛 1
𝜃|𝑦 ∼ Normal 𝑛 , 2+ 2
𝜎 2 𝜎 𝜏
+ 𝜏2
𝑛
6
What will happen if we increase tau?
8
For Normal prior + Normal Outcome, what is the
preferred form of the reported point estimates?
Posterior mean
Posterior median
Posterior mode
It doesn't matter
𝑌𝑖 ∼ 𝐵𝑒𝑟𝑛𝑜𝑢𝑙𝑙𝑖(1, 𝜋), 𝑖 = 1, . . . , 𝑛
𝜋| 𝑦 ∼ 𝑏𝑒𝑡𝑎 𝑎 + 𝑦𝑖 , 𝑏 + 𝑛 − 𝑦𝑖
𝑖=1 𝑖=1
10
Conjugate priors – example 2
About beta distribution “Out of 𝑎 + 𝑏 − 2 experiments, we
expected 𝑎 − 1 success and 𝑏 − 1 failure,
𝜋 ~ 𝑏𝑒𝑡𝑎(𝑎, 𝑏) what is the distribution of success
(0 ≤ 𝜋 ≤ 1) proportion 𝜋?”
𝑎
→𝐸 𝜋 =
𝑎+𝑏
→ The mode of 𝑃:
𝑎−1
Mode 𝜋 =
𝑎+𝑏−2
(for 𝑎 > 1 and 𝑏 > 1)
11
Conjugate priors – example 2
About beta distribution What would happen if the prior is
Beta(1,1)?
The posterior is given by:
𝑛 𝑛
𝜋| 𝑦 ∼ beta 1 + 𝑦𝑖 , 1 + 𝑛 − 𝑦𝑖
𝑖=1 𝑖=1
1 +σ𝑛𝑖=1 𝑦𝑖 −1 σ𝑛
𝑖=1 𝑦𝑖
mode 𝜃 = =
1 +σ𝑛 𝑛
𝑖=1 𝑦𝑖 +1 +𝑛 −σ𝑖=1 𝑦𝑖 −2 𝑛
12
Beta-Binomial example
▪ Consider the mysterious infectious disease that I know nothing about and am
interested in estimating the risk of infection among McGill students/faculty/staff.
→ I draw a random sample of 50 individuals at McGill and test them, among
these 16 are infected.
16
Mode: 𝑀𝑜𝑑𝑒 𝜋𝑖 𝑌𝑖 =
50
13
Beta-Binomial example (Cont’d)
Prior knowledge:
▪ Later I learn that my colleague has performed a similar study with a sample size
of 35 with 8 infected individuals. How can I incorporate this information in
my analysis?
𝑎=9
𝑎+𝑏−2 𝑎−1 𝑏 = 28
𝜋 ~ 𝑏𝑒𝑡𝑎(9, 28)
14
Prior*
• Noninformative priors:
a prior that can be guaranteed to play a minimal role
Rationale: “Let the data speak for themselves.”
aka, reference priors, vague, flat, diffuse
e.g, beta(1,1), N(0,infinity)
15
Non-conjugate framework*
▪ Conjugate priors aren’t always available;
▪ Most realistic models fall outside the conjugate family of models;
▪ These are cases where
Recall Bayes Theorem:
17
Posterior Estimates vs Posterior Probabilities
• The posterior estimates help to conduct the estimation of the parameters
in the Bayesian framework
Posterior Mean/Median/Mode
18
Posterior probabilities: example
▪ In the mysterious disease example, what is the posterior probability that
the risk is below 20% from my study?
▪ What is the posterior probability that the risk is between 10% and 20%
from both studies?
pbeta(0.3,a , b) - pbeta(0.2,a, b)
19
19
Uncertainty estimates: Bayesian credible intervals
▪ ... are defined based on the posterior probabilities: they are simply the range
of most credible parameter values under the posterior (i.e., given the data)
20
Bayesian hypothesis testing
▪ Much more intuitive than classical hypothesis testing;
▪ Relies on the probabilities of the statistical hypotheses, 𝐻0 and 𝐻𝐴 given the
observed data:
𝑃(𝐻0 |𝑦), 𝑃(𝐻𝐴 |𝑦)
→ The first one is exactly what we are told to not confuse p-values with! 😂
21
Bayesian hypothesis testing
22
Bayesian hypothesis testing
23
Some Life Lessons from Statistics
24
Panic about something?
▪ Do you worry about car accidents on a daily basis? If the expected cost is
lower than it, then why would you worry about it every day?
25
About Confidence Interval
▪ Allow the existence of error and allow yourself for a larger margin of error.
26
About Poisson Distribution
In one year, you will hear about 8 good news. When will that happen?
Randomly sample 8 points?
1 year
27
About Poisson Distribution
However, if you think of the good news per day is a Poisson distribution.
Number of good news on day 𝑖 ~ 𝑃𝑜𝑖𝑠𝑠𝑜𝑛(8/365)
1 year
28
What it really looks like would be:
1 year
The period with no good news will take up the majority of our time
1 year
It’s absolutely normal that multiple bad things can happen at the
same time. You will get over it anyway.
29
What do we know about Final Exams
Mainly focus on the content after midterm (after and including lecture
12).
General Questions: Similar to the warm-up questions
Data analysis 1: Logistic regression
Data analysis 2: Poisson regression
Data analysis 3: Correlated outcome
Data analysis 4 (small): Two-way Table
Data analysis 5 (small): Bayesian Statistics
Thank you!