28.11.2014 Views

Bayes - Medreonet

Bayes - Medreonet

Bayes - Medreonet

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Background


Deductive logical schemes<br />

Result 1<br />

Result 2<br />

cause<br />

Result 3<br />

Result 4


Inductive logical schemes<br />

cause<br />

cause<br />

cause<br />

Result 1<br />

Result 2<br />

Result 3<br />

Result 4<br />

Given a series of outcomes, it is possible to hypothesize the<br />

most likely cause(s). The more the prior information we have,<br />

the better the reliability of our estimates


Two rules are important to apply <strong>Bayes</strong>'<br />

theorem:<br />

RULE OF SUM:<br />

P<br />

( A) + P( A)<br />

= 1<br />

where: P ( A) = P( A not occurring)


Two rules are important to apply <strong>Bayes</strong>'<br />

theorem:<br />

RULE OF PRODUCT:<br />

P<br />

P<br />

( A∩<br />

B) = P( B) ⋅ P( A B)<br />

( B ∩ A) = P( A)<br />

⋅ P(<br />

B / A)<br />

P<br />

( B A<br />

)<br />

=<br />

P<br />

( B<br />

) ⋅<br />

P<br />

( A B<br />

)<br />

P( A)


<strong>Bayes</strong>'<br />

theorem


P<br />

( B A)<br />

=<br />

P<br />

( B) ⋅ P( A B)<br />

P( A)<br />

If we consider B the hypothesis and A the set of collected data:<br />

P<br />

where:<br />

( hypothesis | data)<br />

=<br />

P<br />

( hypothesis)<br />

⋅ P(<br />

data / hypothesis)<br />

P<br />

( data)<br />

P(hypothesis) = Prior probability of the hypothesis is the probability of the<br />

hypothesis being true before we collect and analyze the set of data, that is<br />

the state of knowledge before the analysis of data<br />

P(data | hypothesis) = Likelihood function obtained after the experiment<br />

P(hypothesis | data) = Posterior probability of the hypothesis after the<br />

analysis of data<br />

P(data) = Probability of all possible cases giving those data


Example:<br />

Predictive value of a positive result to a diagnostic<br />

test.<br />

We take an animal belonging to a population with<br />

prevalence of infection PR to a certain disease<br />

The hypothesis is "the animal is infected"


P(hypothesis) = probability of the hypothesis being true before<br />

we collect and analyze the set of data = PR prevalence of<br />

infection<br />

We test the animal and get a positive result. This is the data<br />

collection.<br />

P(data | hypothesis) = Likelihood function obtained after the<br />

experiment = probability of a positive test result (the data we<br />

got) given that the animal is infected (that's our hypothesis) = it<br />

is the Sensitivity of our diagnostic test!<br />

P(data) = Probability of all possible cases giving those data. A<br />

positive animal can be a either True positive or a False positive.<br />

Probability of being a True positive is PR times Sensitivity of the test<br />

Probability of being a False positive is (1-PR) times (1-Specificity of the<br />

test)<br />

so, the Predictive value of a positive result to a diagnostic<br />

test, i.e. the probability of our positive animal being infected is:<br />

P<br />

( )<br />

( hypothesis)<br />

⋅ P(<br />

data / hypothesis)<br />

PR ⋅ Sensitivity<br />

P hypothesis | data =<br />

=<br />

P( data) PR ⋅ Sensitivity + ( 1−<br />

PR) ⋅( 1−<br />

Specificity)


<strong>Bayes</strong>ian inference


<strong>Bayes</strong>ian inference<br />

<strong>Bayes</strong>ian inference is a useful, powerful technique whereby<br />

newly acquired empirical data can be combined with<br />

existing information,<br />

whether that information is itself based on pre-existing<br />

empirical data or on expert opinion,<br />

to improve an estimate of the parameter(s) used to<br />

characterise a distribution.<br />

Note: <strong>Bayes</strong>ian inference is based on subjective probability (q.v.)


<strong>Bayes</strong>ian inference<br />

<strong>Bayes</strong>ian inference is a natural extension of <strong>Bayes</strong>’<br />

theorem<br />

It provides a powerful and flexible means of learning<br />

from experience<br />

As new information becomes available it enables our<br />

existing knowledge to be easily and logically updated<br />

It explicitly acknowledges subjectivity and describes<br />

the learning process mathematically<br />

We begin with an opinion, however vague, and modify<br />

it as new information becomes available


<strong>Bayes</strong>ian inference<br />

<br />

<strong>Bayes</strong>ian inference involves three steps:<br />

1. Determining a prior estimate of a parameter in the form of<br />

a probability distribution that expresses our state of<br />

knowledge (or ignorance) before any observations are<br />

made.<br />

2. Finding an appropriate likelihood function for the<br />

2. Finding an appropriate likelihood function for the<br />

observed data. The likelihood function calculates the<br />

probability of observing the data for a given value of the<br />

prior estimate of the parameter<br />

3. Calculating the posterior (i.e. revised) estimate of the<br />

parameter in form of a probability distribution of all<br />

possible values of the parameter


Step 1. Prior distributions<br />

<br />

<br />

<br />

A prior distribution expresses our state of knowledge<br />

before any new observations are made<br />

The prior distribution is not necessarily dependent on<br />

data and may be purely subjective<br />

Depending on the circumstances there are several<br />

options available:<br />

1. Uninformed priors<br />

2. Informed priors


Uninformed priors<br />

An uninformed prior does not provide any<br />

additional information to a <strong>Bayes</strong>ian inference<br />

other than establishing a possible range.<br />

For example, in some circumstances we may not have any<br />

information about the likely prevalence of infection within a<br />

herd.<br />

We might assume that, for a particular disease, the prevalence<br />

is likely to range from 0% to 30% and that any value within<br />

this range is equally as likely as any other value.<br />

This constitutes a uniform prior, Uniform(0,0.3), and has no<br />

influence on the <strong>Bayes</strong>ian inference calculation, apart from<br />

establishing a range


Other examples of uninformed priors<br />

We might want to estimate the average number of<br />

disease outbreaks per year (λ)<br />

If we assume that each outbreak is independent of<br />

every other outbreak and that there is a constant and<br />

continuous probability of a disease outbreak occurring<br />

throughout the year, then the outbreaks follow a<br />

Poisson process.


Other examples of uninformed priors<br />

The average number of outbreaks per year can also be<br />

expressed as 1/β, where β is the mean interval between<br />

events<br />

We might think it is reasonable to assign an<br />

We might think it is reasonable to assign an<br />

uninformed prior in the form of a uniform<br />

distribution, Uniform(0,x), to λ.


Other examples of uninformed priors<br />

However, we could have just as easily parameterised the<br />

problem in terms of β.<br />

Since β=1/λ our prior distribution would be 1/Uniform(0,x)<br />

which is clearly not uninformed with respect to β.<br />

probability<br />

0.35<br />

0.30<br />

0.25<br />

0.20<br />

0.15<br />

0.10<br />

prior distribution for β<br />

expressed as<br />

1/λ = 1/Uniform(0,x)<br />

0.05<br />

0.00<br />

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5


Other examples of uninformed priors<br />

A useful technique in these circumstances to minimise the<br />

effects of re-parameterisation is<br />

to set up the prior distribution for λ as 1/λ and for β as 1/β,<br />

that is we are using β as a prior for λ and vice versa.<br />

As a result, the prior distribution is transformation<br />

invariant.


Other examples of uninformed priors<br />

While such a distribution still does not appear to be<br />

uninformed, it is the best that can be achieved in the<br />

circumstance<br />

and gives the same answer whether we undertake an<br />

analysis from the point of view of λ or β.<br />

probability<br />

0.35<br />

0.30<br />

0.25<br />

0.20<br />

0.15<br />

0.10<br />

0.05<br />

0.00<br />

prior distribution for λ<br />

1<br />

prior( λ)<br />

∝<br />

λ<br />

0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5<br />

lambda


Informed priors<br />

An informed prior may be based on actual data or be<br />

purely subjective<br />

A conjugate prior has the same functional form as the<br />

likelihood function and leads to a posterior<br />

distribution belonging to the same distribution as the<br />

prior


Conjugate priors and their associated likelihoods<br />

and posterior distributions


Step 2. Likelihood functions<br />

The likelihood function calculates the probability of<br />

observing the data for a given value of the prior<br />

estimate of a parameter<br />

The shape of the likelihood function embodies the<br />

amount of information contained in the data<br />

If the information is limited, the likelihood function<br />

will be broadly distributed, whereas if the information<br />

is significant, the likelihood function will be tightly<br />

focused around a particular parameter value


Likelihood functions<br />

There are a number of useful probability distribution<br />

functions that can be used as likelihood functions,<br />

depending on the circumstances<br />

These include the Binomial, Poisson, hypergeometric and<br />

These include the Binomial, Poisson, hypergeometric and<br />

negative binomial


Step 3. Posterior distributions<br />

The posterior distribution is the revised estimate<br />

of the parameter we are investigating and is<br />

obtained simply by multiplying the prior<br />

distribution and the likelihood function<br />

Since the individual probabilities calculated by the<br />

likelihood function are independent of each other,<br />

the resulting posterior probabilities need to be<br />

normalised<br />

This ensures that the area under the curve of a<br />

continuous distribution equals one and that the<br />

probabilities for a discrete distribution all add up<br />

to one


What form does <strong>Bayes</strong>’ theorem assume<br />

when dealing with distributions<br />

where:<br />

pr(H i |D) = Posterior probability of the hypothesis after the analysis of<br />

data. We have a distribution of posterior probabilities (one for each of the i<br />

values of the distribution)<br />

pr(H i ) = Prior probability of the hypothesis (one for each of the i values of<br />

the distribution)<br />

Σ j pr(H j )pr(D|H j ) = Sum of all probabilities of the data given all the<br />

hypotheses. (*)


What form does <strong>Bayes</strong>’ theorem assume<br />

when dealing with distributions<br />

Note:<br />

Σ j pr(H j )pr(D|H j ) = Sum of all probabilities of the data given all the<br />

hypotheses. It is very difficult to know all probabilities of data given all the<br />

hypotheses.<br />

Nevertheless, since this expression is the same denominator for each<br />

pr(H i ǀD):<br />

pr(H i ǀD)∝pr(H i )pr(DǀH i )<br />

and Σ j pr(H j )pr(DǀH j ) becomes a normalization constant to make the sum of<br />

all numerators = 1


How to apply bayesian inference<br />

Let’s imagine that we test a flock of 50 sheep with a<br />

test with 93% sensitivity and 95% specificity<br />

We get no positive results<br />

What is the probability distribution of the number of<br />

What is the probability distribution of the number of<br />

(undetected) infected animals in the flock?


How to apply bayesian inference<br />

Tested= 50<br />

Positive = 0<br />

Sensitivity of the test= 93%<br />

Specificity of the test= 95%<br />

=Uniform(0,50)<br />

→Pr(H i )=1/51<br />

Infected animals<br />

in the sample Prior Binomial likelihood Posterior Nurmalized posterior<br />

0 0,019608 1 0,019608 0,93<br />

1 0,019608 0,07 0,001373 0,0651<br />

2 0,019608 0,0049 9,61E-05 0,004557<br />

3 0,019608 0,000343 6,73E-06 0,00031899<br />

49 0,019608 2,56924E-57 5,04E-59 2,38939E-57<br />

50 0,019608 1,79847E-58 3,53E-60 1,67257E-58


How to apply bayesian inference<br />

Tested= 50<br />

Positive = 0<br />

Sensitivity of the test= 93%<br />

Specificity of the test= 95%<br />

=Binomial(0,n,93%,false)<br />

Infected animals<br />

in the sample Prior Binomial likelihood Posterior Nurmalized posterior<br />

0 0,019608 1 0,019608 0,93<br />

1 0,019608 0,07 0,001373 0,0651<br />

2 0,019608 0,0049 9,61E-05 0,004557<br />

3 0,019608 0,000343 6,73E-06 0,00031899<br />

49 0,019608 2,56924E-57 5,04E-59 2,38939E-57<br />

50 0,019608 1,79847E-58 3,53E-60 1,67257E-58


How to apply bayesian inference<br />

Tested= 50<br />

Positive = 0<br />

Posterior=Prior x Likelihood<br />

Sensitivity of the test= 93%<br />

Specificity of the test= 95%<br />

Infected animals<br />

in the sample Prior Binomial likelihood Posterior Nurmalized posterior<br />

0 0,019608 1 0,019608 0,93<br />

1 0,019608 0,07 0,001373 0,0651<br />

2 0,019608 0,0049 9,61E-05 0,004557<br />

3 0,019608 0,000343 6,73E-06 0,00031899<br />

49 0,019608 2,56924E-57 5,04E-59 2,38939E-57<br />

50 0,019608 1,79847E-58 3,53E-60 1,67257E-58


How to apply bayesian inference<br />

Tested= 50<br />

Positive = 0<br />

Sensitivity of the test= 93%<br />

Specificity of the test= 95%<br />

Normalized=Posterior/Sum<br />

Infected animals<br />

in the sample Prior Binomial likelihood Posterior Nurmalized posterior<br />

0 0,019608 1 0,019608 0,93<br />

1 0,019608 0,07 0,001373 0,0651<br />

2 0,019608 0,0049 9,61E-05 0,004557<br />

3 0,019608 0,000343 6,73E-06 0,00031899<br />

49 0,019608 2,56924E-57 5,04E-59 2,38939E-57<br />

50 0,019608 1,79847E-58 3,53E-60 1,67257E-58


How to apply bayesian inference<br />

Tested= 50<br />

Positive = 0<br />

Sensitivity of the test= 93%<br />

Specificity of the test= 95%<br />

Normalized=Posterior/Sum<br />

Infected animals<br />

in the sample Prior Binomial likelihood Posterior Nurmalized posterior<br />

0 0,019608 1 0,019608 0,93<br />

1 0,019608 0,07 0,001373 0,0651<br />

2 0,019608 0,0049 9,61E-05 0,004557<br />

3 0,019608 0,000343 6,73E-06 0,00031899<br />

49 0,019608 2,56924E-57 5,04E-59 2,38939E-57<br />

50 0,019608 1,79847E-58 3,53E-60 1,67257E-58


The result is:<br />

<strong>Bayes</strong>ian inference<br />

1<br />

0,9<br />

0,8<br />

0,7<br />

Probability<br />

0,6<br />

0,5<br />

0,4<br />

0,3<br />

0,2<br />

0,1<br />

0<br />

0 1 2 3 4 5<br />

Infected animals in the sample


If we have<br />

positives?


Second order bayesian inference<br />

Let’s imagine to test the same flock and to get three<br />

positives<br />

What is the probability of having 0, 1, 2, 3 true<br />

positives and the remaining positives as false positives?<br />

What is the probability of having 0, 1, 2, 3, 4, ...<br />

infected animals in the flock?


Second order bayesian inference<br />

Tested= 50<br />

Positive = 3<br />

Sensitivity of the test= 93%<br />

Specificity of the test= 95%<br />

Uniform(0,50)<br />

Uniform(0,3)<br />

Binomial likelihood<br />

Posterior<br />

True positives<br />

True positives<br />

Infected animals 0 1 2 3 0 1 2 3<br />

in the sample Prior 0,25 0,25 0,25 0,25 0,25 0,25 0,25 0,25 Normalized posterior<br />

0 0,019608 0,219875 0 0 0 0,001078 0 0 0 0,258188132<br />

1 0,019608 0,015229 0,24538 0 0 7,47E-05 0,001203 0 0 0,306020881<br />

2 0,019608 0,001053 0,034685 0,186289 0 5,16E-06 0,00017 0,000913 0 0,260715921<br />

3 0,019608 7,28E-05 0,003674 0,040322 0,072187 3,57E-07 1,8E-05 0,000198 0,000354 0,136512804<br />

4 0,019608 5,02E-06 0,000346 0,005816 0,021276 2,46E-08 1,69E-06 2,85E-05 0,000104 0,032224319<br />

49 0,019608 0 0 2,67E-53 1,05E-49 0 0 1,31E-55 5,17E-52 1,23862E-49<br />

50 0,019608 0 0 0 8,27E-51 0 0 0 4,05E-53 9,70674E-51


Second order bayesian inference<br />

Binomial(TP,Inf,Se,False) x<br />

Tested= 50<br />

Positive = 3<br />

Sensitivity of the test= 93%<br />

Specificity of the test= 95%<br />

Binomial(Tested-Inf-(Pos-TP),Tested-Inf,Sp,False)<br />

Binomial likelihood<br />

Posterior<br />

True positives<br />

True positives<br />

Infected animals 0 1 2 3 0 1 2 3<br />

in the sample Prior 0,25 0,25 0,25 0,25 0,25 0,25 0,25 0,25 Normalized posterior<br />

0 0,019608 0,219875 0 0 0 0,001078 0 0 0 0,258188132<br />

1 0,019608 0,015229 0,24538 0 0 7,47E-05 0,001203 0 0 0,306020881<br />

2 0,019608 0,001053 0,034685 0,186289 0 5,16E-06 0,00017 0,000913 0 0,260715921<br />

3 0,019608 7,28E-05 0,003674 0,040322 0,072187 3,57E-07 1,8E-05 0,000198 0,000354 0,136512804<br />

4 0,019608 5,02E-06 0,000346 0,005816 0,021276 2,46E-08 1,69E-06 2,85E-05 0,000104 0,032224319<br />

49 0,019608 0 0 2,67E-53 1,05E-49 0 0 1,31E-55 5,17E-52 1,23862E-49<br />

50 0,019608 0 0 0 8,27E-51 0 0 0 4,05E-53 9,70674E-51


Second order bayesian inference<br />

Tested= 50<br />

Positive = 3<br />

Sensitivity of the test= 93%<br />

Specificity of the test= 95%<br />

Prior 1 x Prior 2 x Likelihood<br />

Binomial likelihood<br />

Posterior<br />

True positives<br />

True positives<br />

Infected animals 0 1 2 3 0 1 2 3<br />

in the sample Prior 0,25 0,25 0,25 0,25 0,25 0,25 0,25 0,25 Normalized posterior<br />

0 0,019608 0,219875 0 0 0 0,001078 0 0 0 0,258188132<br />

1 0,019608 0,015229 0,24538 0 0 7,47E-05 0,001203 0 0 0,306020881<br />

2 0,019608 0,001053 0,034685 0,186289 0 5,16E-06 0,00017 0,000913 0 0,260715921<br />

3 0,019608 7,28E-05 0,003674 0,040322 0,072187 3,57E-07 1,8E-05 0,000198 0,000354 0,136512804<br />

4 0,019608 5,02E-06 0,000346 0,005816 0,021276 2,46E-08 1,69E-06 2,85E-05 0,000104 0,032224319<br />

49 0,019608 0 0 2,67E-53 1,05E-49 0 0 1,31E-55 5,17E-52 1,23862E-49<br />

50 0,019608 0 0 0 8,27E-51 0 0 0 4,05E-53 9,70674E-51


Second order bayesian inference<br />

Tested= 50<br />

Positive = 3<br />

Sensitivity of the test= 93%<br />

Sum(Posterior) / Sum<br />

Specificity of the test= 95%<br />

Binomial likelihood<br />

Posterior<br />

True positives<br />

True positives<br />

Infected animals 0 1 2 3 0 1 2 3<br />

in the sample Prior 0,25 0,25 0,25 0,25 0,25 0,25 0,25 0,25 Normalized posterior<br />

0 0,019608 0,219875 0 0 0 0,001078 0 0 0 0,258188132<br />

1 0,019608 0,015229 0,24538 0 0 7,47E-05 0,001203 0 0 0,306020881<br />

2 0,019608 0,001053 0,034685 0,186289 0 5,16E-06 0,00017 0,000913 0 0,260715921<br />

3 0,019608 7,28E-05 0,003674 0,040322 0,072187 3,57E-07 1,8E-05 0,000198 0,000354 0,136512804<br />

4 0,019608 5,02E-06 0,000346 0,005816 0,021276 2,46E-08 1,69E-06 2,85E-05 0,000104 0,032224319<br />

49 0,019608 0 0 2,67E-53 1,05E-49 0 0 1,31E-55 5,17E-52 1,23862E-49<br />

50 0,019608 0 0 0 8,27E-51 0 0 0 4,05E-53 9,70674E-51


Second order bayesian inference<br />

Tested= 50<br />

Positive = 3<br />

Sensitivity of the test= 93%<br />

Sum(Posterior) / Sum<br />

Specificity of the test= 95%<br />

Binomial likelihood<br />

Posterior<br />

True positives<br />

True positives<br />

Infected animals 0 1 2 3 0 1 2 3<br />

in the sample Prior 0,25 0,25 0,25 0,25 0,25 0,25 0,25 0,25 Normalized posterior<br />

0 0,019608 0,219875 0 0 0 0,001078 0 0 0 0,258188132<br />

1 0,019608 0,015229 0,24538 0 0 7,47E-05 0,001203 0 0 0,306020881<br />

2 0,019608 0,001053 0,034685 0,186289 0 5,16E-06 0,00017 0,000913 0 0,260715921<br />

3 0,019608 7,28E-05 0,003674 0,040322 0,072187 3,57E-07 1,8E-05 0,000198 0,000354 0,136512804<br />

4 0,019608 5,02E-06 0,000346 0,005816 0,021276 2,46E-08 1,69E-06 2,85E-05 0,000104 0,032224319<br />

49 0,019608 0 0 2,67E-53 1,05E-49 0 0 1,31E-55 5,17E-52 1,23862E-49<br />

50 0,019608 0 0 0 8,27E-51 0 0 0 4,05E-53 9,70674E-51


And the result is:<br />

Second order bayesian inference<br />

0,35<br />

0,3<br />

0,25<br />

Probability<br />

0,2<br />

0,15<br />

0,1<br />

0,05<br />

0<br />

0 1 2 3 4 5 6 7 8 9 10<br />

Number of infected animals

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!