introduction to bayesian methods

56
Introduction to Bayesian Methods Theory, Computation, Inference and Prediction Corey Chivers PhD Candidate Department of Biology McGill University

Upload: corey-chivers

Post on 19-Aug-2014

24.646 views

Category:

Education


2 download

DESCRIPTION

A guest lecture given in advanced biostatistics (BIOL597) at McGill University. EDIT: t=Principle.

TRANSCRIPT

Page 1: Introduction to Bayesian Methods

Introduction to Bayesian Methods Theory, Computation, Inference and Prediction

Corey ChiversPhD CandidateDepartment of BiologyMcGill University

Page 2: Introduction to Bayesian Methods

Script to run examples in these slides can be found here:

bit.ly/Wnmb2W

These slides are here:

bit.ly/P9Xa9G

Page 3: Introduction to Bayesian Methods
Page 4: Introduction to Bayesian Methods

Corey Chivers, 2012

Page 5: Introduction to Bayesian Methods

The Likelihood Principle

L |x ∝P X= x |

● All information contained in data x, with respect to inference about the value of θ, is contained in the likelihood function:

Corey Chivers, 2012

Page 6: Introduction to Bayesian Methods

The Likelihood Principle

L.J. Savage R.A. Fisher

Corey Chivers, 2012

Page 7: Introduction to Bayesian Methods

The Likelihood Function

L |x ∝P X= x |

Where θ is(are) our parameter(s) of interestex:

Attack rate

Fitness

Mean body mass

Mortality

etc...

L |x = f | x

Corey Chivers, 2012

Page 8: Introduction to Bayesian Methods

The Ecologist's Quarter Lands tails (caribou up) 60% of the time

Corey Chivers, 2012

Page 9: Introduction to Bayesian Methods

The Ecologist's Quarter

● 1) What is the probability that I will flip tails, given that I am flipping an ecologist's quarter (p(tail=0.6))?

● 2) What is the likelihood that I am flipping an ecologist's quarter, given the flip(s) that I have observed?

Px |=0.6

L=0.6 | x

Corey Chivers, 2012

Lands tails (caribou up) 60% of the time

Page 10: Introduction to Bayesian Methods

L |x =∏t=1

T

∏h=1

H

1−

The Ecologist's Quarter

L=0.6 | x=H T T H T

=∏t=1

3

0.6∏h=1

2

0.4

=0.03456

Corey Chivers, 2012

Page 11: Introduction to Bayesian Methods

L |x =∏t=1

T

∏h=1

H

1−

The Ecologist's Quarter

L=0.6 | x=H T T H T

=∏t=1

3

0.6∏h=1

2

0.4

=0.03456

But what does this mean? 0.03456 ≠ P(θ|x) !!!!

Corey Chivers, 2012

Page 12: Introduction to Bayesian Methods

How do we ask Statistical Questions?

A Frequentist asks: What is the probability of having observed data at least as extreme as my data if the null hypothesis is true?

P(data | H0) ? ← note: P=1 does not mean P(H

0)=1

A Bayesian asks: What is the probability of hypotheses given that I have observed my data?

P(H | data) ? ← note: here H denotes the space of all possible hypotheses

Corey Chivers, 2012

Page 13: Introduction to Bayesian Methods

P(data | H0) P(H | data)

But we both want to makeinferences about our hypotheses,not the data.

Corey Chivers, 2012

Page 14: Introduction to Bayesian Methods

Bayes Theorem

P | x=P x |P

P x

● The posterior probability of θ, given our observation (x) is proportional to the likelihood times the prior probability of θ.

Corey Chivers, 2012

Page 15: Introduction to Bayesian Methods

The Ecologist's Quarter Redux

Corey Chivers, 2012

Lands tails (caribou up) 60% of the time

Page 16: Introduction to Bayesian Methods

L |x =∏t=1

T

∏h=1

H

1−

The Ecologist's Quarter

L=0.6 | x=H T T H T

=∏t=1

3

0.6∏h=1

2

0.4

=0.03456

Corey Chivers, 2012

Page 17: Introduction to Bayesian Methods

Corey Chivers, 2012

P(x |θ)

P(θ | x )But we want to know

Likelihood of data given hypothesis

Page 18: Introduction to Bayesian Methods

● How can we make inferences about our ecologist's quarter using Bayes?

P(θ | x )=P( x |θ)P(θ)

P(x )

Corey Chivers, 2012

Page 19: Introduction to Bayesian Methods

● How can we make inferences about our ecologist's quarter using Bayes?

P | x=P x |P

P x

Likelihood

Corey Chivers, 2012

Page 20: Introduction to Bayesian Methods

● How can we make inferences about our ecologist's quarter using Bayes?

P(θ | x )=P( x |θ)P(θ)

P(x )

Likelihood Prior

Corey Chivers, 2012

Page 21: Introduction to Bayesian Methods

● How can we make inferences about our ecologist's quarter using Bayes?

P | x=P x |P

P x

Likelihood Prior

Posterior

Corey Chivers, 2012

Page 22: Introduction to Bayesian Methods

● How can we make inferences about our ecologist's quarter using Bayes?

P | x=P x |P

P x

Likelihood Prior

Posterior

P x =∫P x |P d

Not always a closed form solution possible!!

Corey Chivers, 2012

Page 23: Introduction to Bayesian Methods
Page 24: Introduction to Bayesian Methods

Randomization to Solve Difficult Problems

`

Feynman, Ulam &Von Neumann

∫ f d

Corey Chivers, 2012

Page 25: Introduction to Bayesian Methods

(1,0 )

(0 ,1)

(0 .5 ,0 )

Monte Carlo

Throw darts at random

P(blue) = ?

P(blue) = 1/2

P(blue) ~ 7/15 ~ 1/2

Feynman, Ulam &Von Neumann

Corey Chivers, 2012

Page 26: Introduction to Bayesian Methods

Your turn...

Let's use Monte Carlo to estimate π

- Generate random x and y values using the number sheet

- Plot those points on your graph

How many of the points fallwithin the circle?

x=4

y=17

Page 27: Introduction to Bayesian Methods

Your turn...

Estimate π using the formula:

≈4 # in circle / total

Page 28: Introduction to Bayesian Methods

Now using a more powerful computer!

Page 29: Introduction to Bayesian Methods

Posterior Integration via Markov Chain Monte Carlo

A Markov Chain is a mathematical construct where given the present, the past and the future are independent.

“Where I decide to go next depends not on where I have been, or where I may go in the future – but only on where I am right now.”

-Andrey Markov (maybe)

Corey Chivers, 2012

Page 30: Introduction to Bayesian Methods
Page 31: Introduction to Bayesian Methods

Corey Chivers, 2012

Page 32: Introduction to Bayesian Methods

Metropolis-Hastings Algorithm

The Markovian Explorer!1. Pick a starting location at random.

2. Choose a new location in your vicinity.

3. Go to the new location with probability:

4. Otherwise stay where you are.

5. Repeat.

p=min 1, x proposal

xcurrent

Corey Chivers, 2012

Page 33: Introduction to Bayesian Methods

MCMC in Action!

Corey Chivers, 2012

Page 34: Introduction to Bayesian Methods

● We've solved our integration problem!

P | x=P x |P

P x

P | x∝Px | P

Corey Chivers, 2012

Page 35: Introduction to Bayesian Methods

Ex: Bayesian Regression

● Regression coefficients are traditionally estimated via maximum likelihood.

● To obtain full posterior distributions, we can view the regression problem from a Bayesian perspective.

Corey Chivers, 2012

Page 36: Introduction to Bayesian Methods

##@ 2.1 @##

Corey Chivers, 2012

Page 37: Introduction to Bayesian Methods

Example: Salmon Regression

Y=a+bX+ϵ

ϵ ~ Normal(0,σ)

a ~Normal (0,100)

b ~Normal (0,100)

σ ~gamma (1,1/100)

Model Priors

Corey Chivers, 2012

P(a ,b ,σ |X ,Y )∝P(X ,Y |a ,b ,σ)

P(a)P(b)P(σ)

Page 38: Introduction to Bayesian Methods

Example: Salmon Regression

Corey Chivers, 2012

P(X ,Y |a ,b ,σ)=∏i=1

n

N ( y i ,μ=a+b x i , sd=σ)

Likelihood of the data (x,y), given the parameters (a,b,σ):

Page 39: Introduction to Bayesian Methods

Corey Chivers, 2012

Page 40: Introduction to Bayesian Methods

Corey Chivers, 2012

Page 41: Introduction to Bayesian Methods

Corey Chivers, 2012

Page 42: Introduction to Bayesian Methods

##@ 2.5 @##>## Print the Bayesian Credible Intervals> BCI(mcmc_salmon)

0.025 0.975 post_meana -13.16485 14.84092 0.9762583b 0.127730 0.455046 0.2911597Sigma 1.736082 3.186122 2.3303188

Inference:

Does body length have an effect on egg mass?EM=ab BL

Corey Chivers, 2012

Page 43: Introduction to Bayesian Methods

The Prior revisited● What if we do have prior information?

● You have done a literature search and find that a previous study on the same salmon population found a slope of 0.6mg/cm (SE=0.1), and an intercept of -3.1mg (SE=1.2).How does this prior information change your analysis?

Corey Chivers, 2012

Page 44: Introduction to Bayesian Methods

Corey Chivers, 2012

Page 45: Introduction to Bayesian Methods

Example: Salmon Regression

EM=ab BL

~ Normal 0,

a ~Normal (−3.1,1 .2)

b ~Normal (0.6,0 .1)

~ gamma1,1 /100

ModelInformative

Priors

Corey Chivers, 2012

Page 46: Introduction to Bayesian Methods

If you can formulate the likelihood function, you can estimate the posterior, and we have a coherent way to incorporate prior information.

Corey Chivers, 2012

Most experiments do happen in a vacuum.

Page 47: Introduction to Bayesian Methods

Making predictions using point estimates can

be a dangerous endeavor – using the posterior (aka predictive) distribution allows us to take full account of uncertainty.

Corey Chivers, 2012

How sure are we about our predictions?

Page 48: Introduction to Bayesian Methods

Aleatory Stochasticity, randomness

Epistemic Incomplete knowledge

Page 49: Introduction to Bayesian Methods

##@ 3.1 @##

● Suppose you have a 90cm long individual salmon, what do you predict to be the egg mass produced by this individual?

● What is the posterior probability that the egg mass produced will be greater than 35mg?

Corey Chivers, 2012

Page 50: Introduction to Bayesian Methods

Corey Chivers, 2012

Page 51: Introduction to Bayesian Methods

P(EM>35mg | θ)

Corey Chivers, 2012

Page 52: Introduction to Bayesian Methods

Clark (2005)

Extensions:

Page 53: Introduction to Bayesian Methods

Extensions:● By quantifying our uncertainty through

integration of the posterior distribution, we can make better informed decisions.

● Bayesian analysis provides the basis for decision theory.

● Bayesian analysis allows us to construct hierarchical models of arbitrary complexity.

Corey Chivers, 2012

Page 54: Introduction to Bayesian Methods

Summary● The output of a Bayesian analysis is not a single estimate of θ, but rather the entire posterior distribution., which represents our degree of belief about the value of θ.

● To get a posterior distribution, we need to specify our prior belief about θ.

● Complex Bayesian models can be estimated using MCMC.

● The posterior can be used to make both inference about θ, and quantitative predictions with proper accounting of uncertainty.

Corey Chivers, 2012

Page 55: Introduction to Bayesian Methods

Questions for Corey

● You can email me! [email protected]

● I blog about statistics:

bayesianbiologist.com

● I tweet about statistics:

@cjbayesian

Page 56: Introduction to Bayesian Methods

Resources● Bayesian Updating using Gibbs Sampling

● Just Another Gibbs Sampler

● Chi-squared example, done Bayesian:

http://www.mrc-bsu.cam.ac.uk/bugs/winbugs/

http://madere.biol.mcgill.ca/cchivers/biol373/chi-squared_done_bayesian.pdf

http://www-ice.iarc.fr/~martyn/software/jags/

Corey Chivers, 2012