星期四, 3月 31, 2022

Monty Hall problem, COVID RAT test & Bayes Theorem

  • 點樣將呢樣同病毒檢測扯上關係?其實主持人開一扇門就是給你額外提示,你就要衡量忽視這提示的風險是多少!


  • 當做決策或判斷事態時,途中不斷會有更新資訊,是修正看法或是維持原判,中間都有不同風險


A) Bayes Theorem terminology


P (A) prior

- prob. that event A, the hypothesis, occurs


P(B) normalizing constant

- prob. that event B occurs, i.e. the evidence is present


P(A|B) posterior

- probability that hypothesis A occurs given evidence B


P(B|A) likelihood

- probability that evidence B is valid, i.e. sensitivity 真陽率


P(A) is the prevalence of COVID (中招比例) - now we assume 30% of population already got it (保守估計)


P(B) is the chance you are tested positive


If we assume sensitivity of 80% (真陽率) and specificity of 99% (真陰率) for some Rapid Antigen Test (RAT),


測出陽性而確實中招的機率

P(A|B) 

= P(A)*P(B|A) / P(B)

= 中招比 * 真陽率 / (中招比*真陽率+無中比*假陰率)

= 0.3*0.8/(0.3*0.8+0.7*0.01) = 0.24/0.247

= 0.97166


我們當然可再想像一些有趣例子

1,"Bogus" predictor

有一自稱能提供檢測的人,但實際上他只用擲毫決定

他的可靠性為 0.3*0.5/(0.3*0.5+0.7*0.5) = 0.3

既然先驗都知巿面上是三成人已感染,那麼「唔使問阿貴」都知自己有三成機會中咗。


在可靠性來講,隨口噏不會更好,但又不會更差


2,Doomsayer

任何人走來都說他中了。就像打去《盡數心中情》,白韻琹常叫聽眾離婚。

可靠性為 0.3*1/(0.3*1+0.7*1) = 0.3

結果同樣是三成!因為真的中了的,他全部 100%「應驗」!只是沒感染的,他全部「驗錯」,全部屈機,把命中率拖低七成。


B) Monty Hall problem


//You’re on a game show called “Let’s Make a Deal”. There are 3 closed doors in front of you.


Behind each door is a prize. One door has a car, one door has breath mints, and one door has a bar of soap. You’ll get the prize behind the door you pick, but you don’t know which prize is behind which door. Obviously you want the car!


So you pick door A.


Before opening door A, the host of the show, Monty Hall, now opens door B, revealing a bar of soap. He then asks you if you’d like to change your guess. Should you?


My gut told me it doesn’t matter if I change my guess or not. There are 2 doors so the odds of winning the car with each is 50%. Unfortunately for me, that’s 100% wrong.


This is the famous Monty Hall problem.//


點樣將呢樣同病毒檢測扯上關係?其實主持人開一扇門就是給你額外提示,你就要衡量忽視這提示的風險是多少!


當做決策或判斷事態時,途中不斷會有更新資訊,是修正看法或是維持原判,中間都有不同風險。


分析


1) 簡單來說,你挑一扇門是只有1/3 機會選中,有2/3 機會錯。


假如你選中了,你被主持搞得心動了,走去換門,那麼你就丟失了大獎。


假如你選錯了,你去換門,那除了你最初選擇,以及主持打開的門,剩下那一扇門就必是大獎。


即是你不換門而勝出的機會為1/3, 換門的勝出率為2/3。


2) 用貝氏定理解題


就喚你挑的門叫 A, 而主持人開的門叫 B,餘下叫 C


Event A 大獎在門 A

~Event A 大獎不在門 A (即是大獎在門 C)

Event openB 主持開了門 B


Event A given event openB  在主持開了門 B 之後, 而不換門為正確

Event openB given event A 大獎在門 A 的情況下,主持開了門 B



P(A) 一開頭挑中的機率為 1/3

P(openB) 是主持開了門 B 的機率,需考慮以下三種可能之下的機率,再加起來。

三種可能不重叠,且窮盡所有可能。

i) 假如大獎在門 A, 那門 B 和門 C 主持都可以開,是二選一,開門 B 機率為 P(A)*P(openB|A)=⅓*½


ii) 假如大獎在門 B, 主持人不可能開這門!開門 B 機率為 P(B)*P(openB|B)=⅓*0


iii) 假如大獎在門 C, 這門 B 是唯一主持可打開的,因為他不能開了有大獎的門 C,開門 B 機率為P(C)*P(openB|C)= ⅓ * 1


不換門而取大獎的機會是 P (A|openB)

= 不換門正確率/(換門正確率+不換門正確率)

= P(A)*P(openB|A)/ P(openB)

= P(A)*P(openB|A)/ [P(~A)*P(openB|~A)+P (A)*P(openB|A)]

= ⅓*½ / (0+⅓+⅓*½) = 1/3

因為 P(~A)*P(openB|~A) 是計算當大獎不在門 A 時,主持開門 B 的總機率。而不在門 A 就只能在門 B 或門 C, 因此

P(~A)*P(openB|~A) = P(B)*P(openB|B) + P(C)*P(openB|C)


換門而取大獎的機會是 P (~A|openB)

= 換門正確率/(換門正確率+不換門正確率)

= P(~A)*P(openB|~A)/ P(openB)

=  (0+⅓) / (0+⅓+⅓*½) = 2/3


//條件機率等於聯合機率除以條件變數的邊際機率。反過來講:聯合機率等於條件機率乘以條件變數的邊際機率,如下式所示:


Pr(Y=i,X=j)

=Pr(Y=i|X=j)Pr(X=j)

=Pr(X=j|Y=i)Pr(Y=i)


此公式稱為機率的乘法法則(Multiplication Rule),這個法則對於理解貝式定理至關重要。


前述提及條件機率有兩種,分別為Pr(Y=i|X=j)以及Pr(X=j|Y=i),差別僅在於是以X變數的特定事件為給定前提,還是以Y變數的特定事件為給定前提。表一中,因為X是「行」(column,台灣稱「行」,中國大陸稱「列」)的變數,我們把以X變數特定事件為給定前提的條件機率稱之為「行的條件機率」(column conditional probability);如果是以Y變數特定事件為給定前提的條件機率,因為Y是「列」(row,台灣稱「列」,中國大陸稱「行」)的變數,我們稱之為「列的條件機率」(row conditional probability)。


Pr(Y=i|X=j)以及Pr(X=j|Y=i)這兩個機率,我們可以說它們互為「反機率」(inverse probability)。


貝式定理就是將行的條件機率轉變成列的條件機率,或是將列的條件機率轉變成行的條件機率。貝式定理公式看似複雜,背後邏輯其實相當簡單,它就是一個將「給定X事件已發生的前提下,Y事件發生的條件機率」轉變成「給定Y事件已發生的前提下,X事件發生的條件機率」的過程而已。換句話說,貝氏定理就是在算反機率。// (引自 ref. 1)


延伸題目:


可將例子擴展至不同情況來計算轉或不轉的勝算,如下


五扇門

十扇門

999扇門

N 扇門


Reference


1) 貝氏定理在生活中很有用,可是它到底怎麼算?|林澤民的部落格

https://blog.udn.com/mobile/nilnimest/124668370


2) Solving the Monty Hall Problem with Bayes Theorem, How your intuition can lose you money on game shows

https://towardsdatascience.com/solving-the-monty-hall-problem-with-bayes-theorem-893289953e16


3) Bayes Theorem - drug testing

https://www.mun.ca/biology/scarr/4250_Bayes_Theorem.html


4) Bayesian inference, see Applications section, esp. subsections like...

- Bioinformatics and healthcare applications

- In the courtroom

- Other

https://en.m.wikipedia.org/wiki/Bayesian_inference


++++

沒有留言: