You are on page 1of 84

Introduction to Biostatistics

(Biyoistatistiğe Giriş)
Lecture-3:
Probability and Its Laws
(Olasılık ve Kanunları)
Instructor: Mehmet Kocak, Ph.D.
Professor of Biostatistics, International School of Medicine,
Istanbul Medipol University
Outline
• Definition of Probability (Olasılığın Tanımı)
• Laws of Probability (Olasılık Kanunları)
• Probability Representation in Venn Diagrams (Venn Kümelerinde
Olasılık Temsiliyeti)
• Independent Events (Bağımsız Olaylar)
• Conditional Probability (Şartlı Olasılık)
• Bayes Rule and Probality Calculations for Diagnostic Tests
• Permutation and Combination (Permütasyon ve Kombinasyon)
What is Probability? (Olasılık nedir?)
A proper definition: Probability is a quantification of how likely that
an event of interest will occur. (Olasılık, ilgilenilen bir olayın hangi
ihtimalle gerçekleşeceğinin sayısal (nicel) karşılığıdır.)
• Probability can be as small as zero (0), which is an ‘impossible
event’, and as high as one (1), which is a ‘definite event’. (Olasılık,
‘imkansız olayı’ temsil eden 0 (sıfır) değerini alabileceği gibi, ‘kesin
olayı’ temsil eden 1 (bir) değerini de alabilir)
• The higher the probability of an event is, the more certain we are that
the event will occur. (Bir olayın olasılığı ne kadar yüksekse, biz de o
olayın olacağından o kadar eminiz demektir.)
What is Probability? (Olasılık nedir?)
EXAMPLE: Let’s think about a simple experiment. We toss a ‘fair’
coin once. (Adil bir parayla, bir defa yazı/tura attığımızı varsayalım)
• We know that there are two possible outcomes of this experiment:
Head or Tail. (Yazı ve Tura olarak iki ihtimal mevcut)
• As the coin is ‘fair’, we state that the probability of getting a ‘Head’ is
50%, or 0.50, and similarly, the probability of getting a ‘Tail’ is also
0.50. (Para adil olduğu için, ‘yazı’ gelme olasılığı %50, ‘tura’ gelme
olasılığı da %50’dir)
• We state this mathematically as P(Tail)=0.50 and P(Head)=0.50 (Biz
bunu matematiksel olarak P(Yazı)=0.50 and P(Tura)=0.50 şeklinde
ifade ederiz)
What is Probability? (Olasılık nedir?)
EXAMPLE: Let’s think about another simple experiment (basit bir
deney). In a bag, we have 3 red balls, 5 green balls, and 2 blue balls
(Bir torbada, 3 tane kırmızı, 5 tane yeşil, ve iki tane mavi top var). We
randomly pick a ball (Rastgele bir tane seçelim). What are the possible
outcomes and their corresponding probabilities? (Sonuçlar ve onlara
karşılık gelen olasılıklar nedir?)
Outcomes Probabilities
Red 3/10=0.3
Green 5/10=0.5
Blue 2/10=0.2
What is Probability? (Olasılık nedir?)
Probability Law-1 (Olasılık Kanunu-1): In an experiment, the
probabilities of all possible outcomes add up to 1 (one) (Bir deneyde,
tüm sonuçların olasılık toplamları 1 olmalıdır).
When you construct a table of all possible outcomes and their
corresponding probabilities, it is called the ‘Probability Distribution’
(‘Olasılık Dağılımı’) of that experiment.
Outcomes Probabilities Outcomes Probabilities
Head 0.5 Red 0.3
Tail 0.5 Green 0.5
All Outcomes 1.0 Blue 0.2
All Outcomes 1.0
What is Probability? (Olasılık nedir?)
Probability Law-1 (Olasılık Kanunu-1) : Are the following
distributions ‘Probability Distributions’?

Outcomes P Outcomes P Outcomes P Outcomes P


A 0.78 1 0.25 1 0.01 1 0.15
B 0.23 2 -0.15 2 0.02 2 0.40
3 0.6 3 0.96 3 0
Outcomes P 4 0.3 4 0.01 x 0.35
Small 0.10 y 0
Medium 0.20 Outcomes P Outcomes P z 0.10
Big 0.25 High 1.0 Win 1.0
Huge 0.30 Low 0
What is Probability? (Olasılık nedir?)
Probability Law-1 (Olasılık Kanunu-1) :
Are the following distributions ‘Probability Distributions’?
(a) P(X = 0) = 0.4, P(X = 1) = 0.5, P(X = 2) = 0.1
(b) P(X = 1) = 0.2, P(X = 3) = 0.8
(c) P(X = 0) = 0.6, P(X = 1) = 0.2, P(X = 2) = 0.2
(d) P(X = -2) = 0.2, P(X = 0) = 0.8
(e) P(X = 0) = 0.3, P(X = 1) = 0.4, P(X = 2) = 0.3
(f) P(X) = 1/3, P(Y) = 1/4, P(Z) = ½
(g) P(X = 0) = 0.7, P(X = 1) = 0.3
(h) P(X) = 0.3, P(Y) = 0.4, P(Z) = 0.3
(i) P(X = -1) = 0.1, P(X = 1) = 0.9
(j) P(X = 0) = 0.2, P(X = 1) = 0.4, P(X = 2) = 0.4
What is Probability? (Olasılık nedir?)
EXAMPLE: Let’s think of a new experiment. In a bag, you have five
identical balls numbered from 1 to 5 (Bir torbada 1’den 5’e kadar
numaralanmış özdeş toplar var). You randomly pick a ball. What are
the possible outcomes and their probabilities? (Bir tane topu rastgele
çekersen, muhtemel sonuçlar ve olasılıkları nelerdir?)
Outcomes P
1 1/5=0.2
2 1/5=0.2
3 1/5=0.2
4 1/5=0.2
5 1/5=0.2
What is Probability? (Olasılık nedir?)
EXAMPLE: Now, let’s define some events (Gelin şimdi
bazı olaylar tanımlayalım): Outcomes P
1. Event-A=“The number you pick is an even number 1 1/5=0.2
(Seçtiğin top bir çift sayı).” What is the probability of A? 2 1/5=0.2
Answer: P(A)=P(Getting 2 or 4)=0.4 3 1/5=0.2
2. Event-B=“The number you pick is larger than 2 (2’den 4 1/5=0.2
büyük).” What is the probability of B? 5 1/5=0.2
Answer: P(B)=P(Getting 3 or 4 or 5)=0.6
3. What is the probability that either A or B is true?
Answer: P(A or B)=P(Getting 2 or 3 or 4 or 5)=0.8
4.What is the probability that both A and B are true (Hem
Olay-A, hem Olay-B doğru)?
Answer: P(A and B)=P(Getting 4)=0.2
What is Probability? (Olasılık nedir?)
Union of Events (Olayların Birleşimi)
P(A∪B) means ‘Probability of either A or B occurring’ and is read as ‘Probability of A
Union B’
P(A∪B), ‘ya A-olayının, ya B-olayının gerçekleşeceği’ anlamına gelir ve ‘A ile B’nin
Birleşim olasılığı’ şeklinde okunur
Intersection of Events (Olayların Kesişimi)
P(A∩B) means ‘Probability of both A and B occurring’ and is read as ‘Probability of A
Intersection B’
P(A∩B), ‘A-olayının, ve B-olayının birlikte gerçekleşeceği’ anlamına gelir ve ‘A ile B’nin
Kesişim olasılığı’ şeklinde okunur

Probability Law-2:

P(A∪B)=P(A) + P(B) - P(A∩B)


What is Probability? (Olasılık nedir?)
EXAMPLE: Now, let’s revisit our example Outcomes P
(Örneğimizi tekrar dönelim):
1 1/5=0.2
Event-A=“The number you pick is an even number.” 2 1/5=0.2
Event-B=“The number you pick is larger than 2.” 3 1/5=0.2
• What is the probability that both A and B are true? 4 1/5=0.2
P(A∩B)=0.2 5 1/5=0.2
• What is the probability that either A or B is true?
P(A∪B)=P(A) + P(B) - P(A∩B)
=0.4 + 0.6 – 0.2=0.8
What is Probability? (Olasılık nedir?)
In Class Activity: Suppose we have the following distribution in a middle school
(Bir ortaokulda aşağıdaki dağılıma sahip olduğumuzu varsayalım):
6th Grade 7th Grade 8th Grade
Males 16 20 14
Females 14 15 11

Pick a student randomly and find the probabilities of the following events
(Rastgele bir öğrenci seçin ve aşağıdaki olayların olasılıklarını bulun):
• A: It is a female student (kız öğrenci)
• B: It is student less than 8th grade (8. sınıftan daha düşük)
• Both A and B (Hem A, Hem B)
• A or B (A ya da B)
• Neither A nor B (A da değil, B de)
What is Probability? (Olasılık nedir?)
6th Grade 7th Grade 8th Grade Total
Males 16 20 14 50
Females 14 15 11 40
Total 30 35 25 90

Pick a student randomly and find the probabilities of the following events
(Rastgele bir öğrenci seçin ve aşağıdaki olayların olasılıklarını bulun):
• A: It is a female student  P(A)=40/90
• B: It is student less than 8th grade  P(B)=65/90
• Both A and B  P(A∩B)=29/90
• A or B  P(A ∪ B)=40/90+65/90-29/90=76/90
• Neither A nor B  )=14/90
Probability and Venn Diagram

How many disjoint areas can you see in the above Venn diagram? (Yukarıdaki
Venn diyagramda birbirinden ayrı (ayrışık) kaç bölge görebiliyorsunuz?)
Probability and Venn Diagram
Probability and Venn Diagram
Probability and Venn Diagram
Probability and Venn Diagram
Probability and Venn Diagram

Not B=BC= (reads B-complement)


(B Olayının dışında kalanlar)
Probability and Venn Diagram

(Sadece A Olayı; yani, A ama B-Değil)


Probability and Venn Diagram

(Sadece B Olayı; yani, B ama A-Değil)


Probability and Venn Diagram

(Yalnızca A ya da Yalnızca B, ama birlikte değil)


Probability and Venn Diagram

(Yalnızca A gerçekleşemez)
Probability and Venn Diagram
Probability and Venn Diagram
EXAMPLE: For the given event space (olay uzayı), please find the
following probabilities:
1. P(A)
2. P(B but Not A)
3. P(Not A nor B)
4. P(Not Just B)
5. P(A or not B)
6. P(Both A and B or neither)
Probability and Venn Diagram
EXAMPLE: For the given event space, please find the
following probabilities:
1. P(A)=0.36+0.12=0.48
2. P(B but Not A)=0.30
3. P(Not A nor B)=0.22
4. P(Not Just B)=1-0.30=0.70
5. P(A or not B)=0.48+0.22=0.70
6. P(Both A and B or neither)=0.12+0.22=0.34
Independent Events (Bağımsız Olaylar)
EXAMPLE: Let’s think of an experiment where we toss a ‘fair’ coin twice (Adil
bir parayı iki defa yazı/tura attığımızı varsayalım).
• We know that there are now four (4) possible outcomes of this experiment (Bu
deneyin 4 muhtemel sonucu olduğunu biliyoruz): HeadHead, HeadTail,
TailHead, TailTail
(YazıYazı, YazıTura, TuraYazı, TuraTura)
• Here, we need to make some assumptions (Burada bazı varsayımlarda
bulunmamız gerekiyor): Two consecutive tosses are independent of each other
(peşpeşe iki yazı/tura atışı birbirinden bağımsızdır); in other words, the result of
the first toss does not affect the outcome of the second toss (yani, ilk atışın
sonucu ikinci atışın sonucunu etkilemez).
• This ‘independence’ assumption is very critical in statistics in general (Bu
‘bağımsızlık’ varsayımı istatistikte çok kritik bir yere sahiptir).
Independent Events (Bağımsız Olaylar)
Definition (Tanım): Two events are independent of each other if the occurrence
of one does not change the probability of the occurrence of the other.
(İki olaydan birinin gerçekleşmesi diğerini etkimediği durumlarda bu iki olay
birbirinden bağımsızdır)
• If we assume that the two consecutive tosses are independent, then, what is the
probability of getting a Head first and another Head in the second toss, that is,
P(HeadHead)?
• Peşpeşe iki yazı/tura atışının birbirinden bağımsızlığını varsayarsak, iki yazı
gelmesi olasılığı, yani P(YazıYazı) olasılığı nedir?
Probability Law-3: If A and B are two independent events (Eğer A ve
B bağımsız olaylarsa), then P(A ∩ B)=P(A).P(B)
What is Probability?
Probability Law-3: If A and B are two independent events, then
P(A ∩ B)=P(A).P(B)
Here, P(A ∩ B) can also be written as P(AB), where ‘∩’means
‘intersection’ (‘kesişim’), that is, both events occur together (her iki
olay da birlikte gerçekleşir).
So, for independent events, we simply multiply the individual
probabilities of the events to find the probability of all those events
happening at the same time.
(Bundan dolayı, bağımsız olaylarda, bu olayların birlikte gerçekleşmesi
olasılığını, her bir olayın olasılığını çarparak buluruz).
What is Probability?
EXAMPLE: Let’s go back to our earlier example (Önceki örneğimize
geri dönelim). We know that there are now four (4) possible outcomes
of this experiment: HH, HT, TH, TT.
• If we assume that the tosses are independent, then,
P(HH)=P(H).P(H)=0.5*0.5=0.25.
(P(YY)=P(Y).P(Y)=0.5*0.5=0.25)
• This is also true for all other three possibilities (Bu durum diğer tüm
muhtemel olaylar için de geçerlidir)
• We illustrate this as follows (Bunu aşağıdaki şekilde gösteririz):
What is Probability?
Outcome Probability
0.50 Head HH 0.5*0.5=0.25
Head
0.50
0.50 Tail HT 0.5*0.5=0.25
Start

0.50
0.50 Head TH 0.5*0.5=0.25
Tail

0.50 Tail TT 0.5*0.5=0.25


What is Probability?
In Class Exercise: In an experiment, you toss a fair coin three times
and count the number of Heads (Bir deneyde, adil bir parayı üç defa
yazı/tura atıyorsunuz ve kaç tane yazı geldiğini sayıyorsunuz).
Generate a table of all possible outcomes and their corresponding
probabilities (Tüm sonuçların ve olasılıklarının bir tablosunu
oluşturun).
What is Probability?
Outcome Probability
0.50 Head HHH=3 0.125
0.50 Head
0.50 Tail HHT=2 0.125
Head
0.50 0.50 Head HTH=2 0.125
Tail
0.50
0.50 Tail HTT=1 0.125
Start
0.50 Head THH=2 0.125
0.50 Head
0.50
0.50 Tail THT=1 0.125
Tail 0.50 Head TTH=1 0.125
Tail
0.50
0.50 Tail TTT=0 0.125
What is Probability?
Outcome (Sonuç) Probability
HHH3 0.125
(HHT, HTH, THH)2 0.375
(HTT, THT, TTH)1 0.375
TTT0 0.125
Dependent and Independent events
Bağımlı ve Bağımsız Olaylar
• A bag has 5 red and 5 blue balls (Bir torbada 5 kırmızı, 5 mavi top var). We take
a ball randomly, record the color and put it back (Bir topu rastgele çeker, rengini
kaydeder ve geri bırakırız). We then take a ball again randomly, record the color
and put it back (Sonra rastgele bir top daha çeker, rengini kaydeder ve geri
bırakırız)
(This is called ‘Random selection with replacement’; buna, ‘Yerine koyarak
rastgele çekim’ denir ).
• Event-A: The color of the first ball is red
• Event-B: The color of the second ball is red
• Are these two events independent? (Bu iki olay bağımsız mıdır?)
Dependent and Independent events
Bağımlı ve Bağımsız Olaylar
• In a class, there are 12 girls and 8 boys. We randomly pick two students from
the class as the president and vice-president. (Bir sınıfta 12 kız ve 8 erkek var.
Bu sınıftan biri başkan biri başkan yardımcısı olmak üzere iki öğrenciyi rastgele
çekiyoruz).
• Event-A: The president is a girl;
• Event-B: The vice-president is a girl;
• Are these two events independent? (Bu iki olay bağımsız mıdır?)
• P(A)=12/20
• P(B)=P(President-Boy, VP-Girl) or P(President-Girl, VP-Girl)
=8/20*12/19+12/20*11/19=0.60
• P(AB)= P(President-Girl, VP-Girl)=0.35≠0.36 (A and B are not independent)
Dependent and Independent events
Bağımlı ve Bağımsız Olaylar
Exercise-1: Think of all the integers from 1-20. You pick a number randomly. Are
the following two events independent? (1’den 20’ye kadar olan tamsayıları
düşünelim. Bu sayılardan bir tanesini rastgele seçelim. Buna göre, aşağıdaki
olaylar bağımsız mıdır?)
Event-A: You pick a prime number (asal sayı)
Event-B: You pick an odd number (tek sayı)
P(A)=P(Getting 2, 3, 5, 7, 11, 13, 17, 19)=8/20
P(B)=P(Getting 1, 3, 5, 7, 9, 11, 13, 15, 17, 19)=10/20
P(AB)=P(Getting 3, 5, 7, 11, 13, 17, 19)=7/20

P(AB)=P(A).P(B)=8/20*10/20=4/20≠7/20 (A and B are not independent)


Dependent and Independent events
Bağımlı ve Bağımsız Olaylar
Exercise-2: In a hospital, you randomly pick a patient. Discuss if the following
two events independent? (Bir hastanede, rasgele bir hasta çekiyorsunuz.
Aşağıdaki iki olayın bağımsız olup olmadığını tartışın)
Event-A: It is a brain tumor patient (bir beyin tümörü hastası)
Event-B: It is a female patient (bir bayan hasta).
Exercise-3: In a prison, you randomly pick an inmate. Discuss if the following
two events are independent? (Bir hapishaneden, rasgele bir mahkum
çekiyorsunuz. Aşağıdaki iki olayın bağımsız olup olmadığını tartışın)
Event-A: The inmate has a college degree (Mahkum üniversite mezunu).
Event-B: The crime committed is financial fraud (Suçu mali dolandırıcılık).
Dependent and Independent events
Bağımlı ve Bağımsız Olaylar
Exercise-4: From an apple farm, you randomly pick a tree. Discuss if the
following two events are independent? (Bir elma bahçesinden, rasgele bir elma
ağacı çekiyorsunuz. Aşağıdaki iki olayın bağımsız olup olmadığını tartışın)
Event-A: The tree is a diseased tree (hastalıklı bir ağaç).
Event-B: The owner of the farm had triplet babies this year (Bahçe sahibinin bu
yıl üçüzleri oldu).
Dependent and Independent events
Bağımlı ve Bağımsız Olaylar
Exercise-5: In a room of 23 people, what is the probability that at least two
people share the same birthday? (Note: This is a classic problem and the
probability is surprisingly high)
A) About 5%
B) About 23%
C) About 50%
D) About 70%
E) More than 90%
Dependent and Independent events
Bağımlı ve Bağımsız Olaylar
Exercise-6: Imagine you have a drawer containing 10 pairs of socks: 5 pairs are
black, and 5 pairs are blue. The socks are mixed up in the drawer. If you randomly
select two socks from the drawer without looking, what is the probability that
they are a matching pair?
A) 10/20
B) 4/19
C) 5/19
D) 9/19
E) 1/10
CONDITIONAL PROBILITY (ŞARTLI OLASILIK)
• Conditional probability is defined as the probability of an event with the
knowledge that another event already occurred (Şartlı olasılık, bir olayın, başka
bir olayın olmuş olduğu bilgisi ışığında olma olasılığıdır);
• Mathematically, we denote this P(A|B), which reads ‘Probability of A given B’
(‘B zaten olduysa A’nın da olma olasılığı’).
CONDITIONAL PROBILITY (ŞARTLI OLASILIK)
• We know that B happened and the rest of the event space is not relevant any
longer (B’nin gerçekleştiğini biliyoruz; bu nedenle, olay uzayının geri kalan
kısmıyla ilgilenmiyoruz artik).

• The probability that A will also occur is the


proportion of P(A∩B) to P(B) as shown here:
CONDITIONAL PROBILITY (ŞARTLI OLASILIK)
• If A and B are independent events, what happens to the conditional probability
of A|B? (Eğer A ve B olayları bağımsız olaylarsa, A|B’nin olasılığına ne olur?)

• That means, by definition, if A and B are independent, knowing that B already


occurred doesn’t give us any information about A (Bu demektir ki, eğer A ve B
olayları bağımsız olaylarsa, B olayının gerçekleşmiş olması, A olayının
gerçekleşip gerçekleşmeyeceği konusunda bize hiçbir bilgi vermez.)
CONDITIONAL PROBILITY (ŞARTLI OLASILIK)
• If A and B cannot occur together (i.e., if they are disjoint events), what happens
to the conditional probability of A|B? (Eğer A ve B birlikte gerçekleşemeyen
olaylarsa (yani A ve B ayrışık olaylarsa), A|B’nin olasılığına ne olur?)

• That means, by definition, if we know that B happened already, the probability


of A happening as well is simply zero (Yukarıdaki varsayım altında, eğer B olayı
gerçekleşmişse, zaten A olayı gerçekleşemez).
CONDITIONAL PROBILITY (ŞARTLI OLASILIK)
EXAMPLE: Suppose we have the following student distribution in a middle
school (Bir ortaokulda, aşağıdaki dağılımın olduğunu varsayalım)
6th Grade 7th Grade 8th Grade
Males 16 20 14
Females 14 15 11

Let’s pick a student randomly and find the following probabilities (Rastgele bir
öğrenci seçelim ve aşağıdaki olasılıkları bulalım):
• It is a female student
 P(A)=40/90
• Knowing that it is a 6th grade, what is the probability that it is a female
student? (Öğrencinin 6. sınıf olduğunu biliyorsak, P(F|6. sınıf)=?)
 P(F|6th grader)=P(F and 6th Grader)/P(6th Grader)=(14/90)/(30/90)=14/30
CONDITIONAL PROBILITY (ŞARTLI OLASILIK)
EXAMPLE: In a box of 100 led-bulbs, you know that there are 10 defective ones
(100 led-ampul içeren bir kutuda, 10 tane bozuk ampul var). You randomly pick
two (Rastgele iki tane seçin).
• What is the probability that the first bulb is defective? (İlk ampulün bozuk olma
olasılığı nedir?)
P(1st bulb defective)=10/100
• You realize that the first bulb is not defective; what is the probability that the
second one is also not defective? (İlk ampul bozuk değilse, ikincinin bozuk olma
olasılığı nedir?)
P(2nd bulb not defective|1st bulb not defective)=89/99=(90/100)(89/99)/(90/100)
• What is the probability that both are defective? (Her ikisinin de bozuk olma
olasılığı nedir?)
P(Both bulbs are defective)=10/100*9/99
CONDITIONAL PROBILITY (ŞARTLI OLASILIK)
EXERCISE: At a school, 10% of the students play both basketball (B) and table
tennis (TT), and 40% play basketball (B). If you pick a random student from this
school and the student tells you that s/he plays basketball, what is the probability
that s/he also plays table tennis?
(Bir okuldaki öğrencilerin %10’u hem basketbol hem masa tenisi oynarken,
toplam %40’ı basketbol oynuyor. Rastgele bir öğrenci çekiyorsun ve öğrenci
basketbol oynadığını söylüyor. Bu durumda, bu öğrencinin aynı zamanda masa
tenisi oynama olasılığı nedir?)
P(TT|B)=P(TT∩B)/P(B)=0.10/0.40=0.25
CONDITIONAL PROBILITY (ŞARTLI OLASILIK)
EXERCISE: If the probability of encountering a red traffic light on the way to
work is 30%, and the probability of being late to work when you hit a red light is
40%, what is the probability of being late to work and hitting a red light?
A) 12%
B) 20%
C) 30%
D) 40%
E) 70%
CONDITIONAL PROBILITY (ŞARTLI OLASILIK)
EXERCISE: The probability that a diagnostic test is positive and the person who
is being diagnosed has the disease of interest is 0.08. Overall, this test is positive
10% of the time. Given that the test is positive for someone, what is the
probability that the person has the disease of interest?
(Bir tanı testinin pozitif çıkma ve test edilen kişinin de gerçekten o hastalığa sahip
olma olasılığı 0.08’dir. Bu test, genel olarak, %10 oranında pozitif çıkmaktadır.
Buna göre, eğer bir kişi için test pozitif çıkmışsa, o test edilen kişinin gerçekten
hastalığa sahip olma olasılığı nedir?)
P(D+|T+)=P(D+∩T+)/P(T+)=0.08/0.10=0.80 (80%)
Bayes Rule (Bayes Kuralı)
• Think about the following event space (Aşağıdaki olay uzayını düşünün):

• How many disjoint parts of Event A can you identify? (A olayının kaç
tane ayrışık parçası var?)
Bayes Rule (Bayes Kuralı)
• We see two disjoint parts (iki tane ayrışık parça görüyoruz): and
• We express these two parts mathematically as
follows (Bunu matematiksel olarak aşağıdaki
gibi ifade ederiz):
So, P(A)=P()+P()
• Each intersection can be expressed as a
conditional probability as follows (Her
kesişim, şartlı olasılık cinsinden aşağıdaki gibi
ifade edilebilir):
 P()=
=
Thus, we reach the following expression (Böylece aşağıdaki ifadeye ulaşırız):
 )+ )
Bayes Rule (Bayes Kuralı)
)+ )
• Here, we see that we can compute the
probability of a whole as a sum of
conditional probabilities (Burada, bir
bütünün olasılığının, parçaların şartlı
olasılığı olarak elde edilebileceğini
görüyoruz).

• We can similarly express P(B) (Aynı şekilde P(B)’yi de ifade edebiliriz):


 )+ )
• We can also derive the following expressions easily (Aynı şekilde aşağıdaki
ifadelere de kolayca ulaşabiliriz):
Bayes Rule (Bayes Kuralı)
• From this, we can derive the following (Buradan da, aşağıdaki ifadeye ulaşırız):

• This is called Bayes Rule (İşte buna ‘Bayes Kuralı’ denir).


• Bayes Rule is very useful in complicated probability calculations (Bayes Kuralı,
karmaşık olasılıkların hesaplamasında çok kullanışlıdır).
• The use of Bayes Rule forms the basis for diagnostic tests (Bayes Kuralı
kullanımı, tanı testlerinde temel teşkil eder).
• Based on Bayes Rule, a branch of statistics called Bayesian Statistics has been
established (Bayes Kuralına dayanan, Bayesçi İstatistik diye bir istatistik dalı
geliştirilmiştir).
Bayes Rule
EXAMPLE: A given disease of interest is prevalent in 10% of a given population A
diagnostic test for this disease is positive in 90% of the diseased population
(SENSITIVITY) and negative in 95% of the healthy population (SPECIFICITY). A
patient just receives his/her test result and it is positive. What is the probability that the
patient really has the disease? (Bir hastalığın bir popülasyondaki prevelansı %10’dur.
Bir tanı testi hastalıklı popülasyonda %90 oranında pozitif
(DUYARLILIK/HASSASLIK), sağlıklı popülasyonda %95 oranında negatif
çıkmaktadır (SEÇİCİLİK). Bir hasta bu testi kullanmış ve pozitif çıkmıştır. Bu
hastanın gerçekten hastalığı taşıma olasılığı nedir?)
• Let’s first list what we know (Önce bildiklerimizi listeleyelim):
• P(T+|D+)=0.90; this implies, P(T-|D+)=0.10
• P(T-|D-)=0.95; this implies, P(T+|D-)=0.05
• P(D+)=0.10; This implies, P(D-)=0.90
• Now, let’s state what we want to know (Şimdi bilmek istediğimizi ifade edelim):
• P(D+|T+)=?
Bayes Rule
Here, how do we find P(T+) (P(T+)’ı nasıl bulacağız)?
Remember, we can express an event as the sum of its conditional events.
(Hatırlayın, bir olayı, o olayın şartlı olayları olarak ifade edebiliriz)

0.135
Now, we can compute our desired probability (İşte şimdi istediğimiz olasılığı
hesaplayabiliriz):

Is this a good diagnostic test? (Sizce bu iyi bir test mi?)


Bayes Rule
EXAMPLE (Continued): Under the same setting, a patient just receives his/her
test result and it is negative. (Aynı şartlar altında, başka bir hasta tanı sonucunu
negatif olarak alır).
• What is the probability that the patient actually has the disease? (Bu hastanın
aslında hasta olma olasılığı nedir?)

• What is the probability that the patient really doesn’t have the disease? (Bu
hastanın gerçekten hasta olmama olasılığı nedir?)
Bayes Rule: R Computations
EXAMPLE: Let’s do these computations in R (Gelin bu hesaplamaları R’da
yapalım şimdi):
We first enter the information we know. We can explain each step using # sign.
(Önce bildiklerimizi girelim. Burada ben her adım için # işaretiyle açıklamalar
kullanabiliriz).
### BAYES RULE APPLICATION: Let's use d for disease, t for test, 0 for negative and 1 for
positive in our variable names.
### Değişken isimlerinde, d hastalığı, t testi, 0 negatifi, 1 pozitifi temsil etsin.
### Probability that the test was positive when the disease is positive (Sensitivity-Duyarlılık)
p_t1_d1=0.90; p_t1_d1
### Probability that the test was negative when the disease is negative
(Specificity-Seçicilik/Hassaslık)
p_t0_d0=0.95; p_t0_d0
### Probability that the disese is positive in this population (prevelance)
p_d1=0.10; p_d1
Bayes Rule: R Computations
### Based on the knowns above, we compute our desired probabilities below:
### Yukarıda verilen bilinenlerden hareketle, aşağıda istediğimiz olasılıkları
hesaplıyoruz:
### Disease negative ###
p_d0=1-p_d1; p_d0
### Test positive ###
p_t1=p_t1_d1*p_d1+(1-p_t0_d0)*p_d0; p_t1
### The patient has the disease when the test is positive ###
p_d1_t1=p_t1_d1*p_d1/p_t1; p_d1_t1
### The patient actually doesn not have the disease when the test is positive ###
p_d0_t1=1-p_d1_t1; p_d0_t1
### The patient does not have the disease when the test is negative ###
p_d0_t0=p_t0_d0*p_d0/(1-p_t1); p_d0_t0
### The patient actually has the disease when the test is negative ###
p_d1_t0=1-p_d0_t0; p_d1_t0
Bayes Rule: R Computations
> ### Disease negative ###
> p_d0=1-p_d1; p_d0
[1] 0.9
> ### Test positive ###
> p_t1=p_t1_d1*p_d1+(1-p_t0_d0)*p_d0; p_t1
[1] 0.135
> ### The patient has the disease when the test is positive ###
> p_d1_t1=p_t1_d1*p_d1/p_t1; p_d1_t1
[1] 0.6666667
> ### The patient actually doesn not have the disease when the test is positive ###
> p_d0_t1=1-p_d1_t1; p_d0_t1
[1] 0.3333333
> ### The patient does not have the disease when the test is negative ###
> p_d0_t0=p_t0_d0*p_d0/(1-p_t1); p_d0_t0
[1] 0.9884393
> ### The patient actually has the disease when the test is negative ###
> p_d1_t0=1-p_d0_t0; p_d1_t0
Bayes Rule: R Computations
EXAMPLE: Once you establish your computational platform, you can change
your inputs however you like and compute the desired Outcomes easily (Bir defa
hesaplama platformununu oluşturdunuz mu, girdilerinizi istediğiniz şekilde
değiştirip, istediğiniz sonuçları kolayca elde edebilirsiniz).
### Probability that the test was positive when the
disease is positive (Sensitivity) > ### The patient has the disease when
p_t1_d1=0.70; p_t1_d1 the test is positive ###
### Probability that the test was negative when > p_d1_t1=p_t1_d1*p_d1/p_t1;
the disease is negative (Specificity) p_d1_t1
p_t0_d0=0.85; p_t0_d0 [1] 0.1971831
### Probability that the disese is positive in this > ### The patient does not have the
population (prevelance) disease when the test is negative ###
p_d1=0.05; p_d1 > p_d0_t0=p_t0_d0*p_d0/(1-p_t1);
p_d0_t0
[1] 0.9817629
Bayes Rule
EXERCISE: A given disease of interest is prevalent in 5% of a given population.
(Bir hastalığın prevelansı %5’tir). Doctors have two diagnostic tests for this
disease (Doktorların bu hastalık için iki tane tanı testi vardır):
Test-A: Positive in 90% of the diseased population and negative in 90% of the
healthy population (hastalıklı popülasyonda %90 pozitif, sağlıklı popülasyonda
%90 negatif).
Test-B: Positive in 85% of the diseased population and negative in 95% of the
healthy population. (hastalıklı popülasyonda %85 pozitif, sağlıklı popülasyonda
%95 negatif).
• Compute (hesaplayın) P(D+|T+) and P(D-|T-) for both tests (her iki test için).
• Argue which test is better for screening for this disease (Hastalık taramasında
hangi testin daha iyi olduğunu tartışın).
Bayes Rule
EXERCISE: The probability that a computer has a virus is 5%. If a computer has
a virus, the probability that it shows an error message is 60%. The computer
shows an error message 6% of the time regardless of the virüs. What is the
probability that a computer has a virus given that it is showing an error message?
A) 15%
B) 25%
C) 35%
D) 50%
E) 70%
Bayes Rule
EXERCISE: The probability that a computer has a virus is 5%. If a computer has
a virus, the probability that it shows an error message is 60%. The computer
shows an error message 10% of the time when there is no virus. What is the
probability that a computer has a virus given that it is showing an error message?
A) 15%
B) 24%
C) 33%
D) 55%
E) 62%
Probability by Geometry
EXERCISE: Two friends make the following arrangement: They will come to
the city center randomly anytime between 10 and 11 o’clock in the morning. If
the other is not there, wait for the other for 10 minutes or until 11 (whichever is
earlier), and leave if the other doesn’t show up. If they can meet, they will go to a
cafe and study Dr. Kocak’s statistics class. What is the probability that they will
meet?
(İki arkadaş şöyle bir plan yaparlar: Her ikisi de şehir merkezine saat 10 ile 11
arasında rastgele bir zamanda gelecekler; eğer diğer arkadaş orada değilse 10
dakika ya da 11’e kadar (hangi zaman önce gelirse) bekleyip ayrılacaklar. Eğer
buluşabilirlerse, bir kafeteryaya gidip, Koçak Hoca’nın istatistik dersine
çalışacaklar. Bu iki arkadaşın buluşabilme olasılıkları nedir?)
PERMUTATION AND COMBINATION
Permutation (Ordered Shuffling)-Permütasyon (Sıralı Karıştırma)
Example: In how many ways can you arrange 5 different flowers in a balcony if
you have exactly five places? (5 Değişik çiçeği balkonda kaç değişik şekilde
sıralayabilirsiniz?)
Place-1 Place-2 Place-3 Place-4 Place-5
5 4 3 2 1

5*4*3*2*1=5!=120 different ways.


Example: You plan to give two of the flowers to a friend of yours in two
occasions one by one. In how different selections can you have? (Arkadaşınıza
çiçeklerden iki tanesini kaç değişik şekilde verebilirsiniz?)
1st Flower 2nd Flower
5 4 Perm(5,2)=5!/(5-2)!=(5*4*3*2*1)/(3*2*1)=5*4
PERMUTATION AND COMBINATION
Permutation (Ordered Shuffling) -Permütasyon (Sıralı Karıştırma)
Calculations in Excel and
Google Sheet

Calculations in R
#install if necessary > permutations(n=5,r=2) [7,] 2 4 [15,] 4 3
[,1] [,2] [8,] 2 5 [16,] 4 5
install.packages('gtools')
[1,] 1 2 [9,] 3 1 [17,] 5 1
#load library [2,] 1 3 [10,] 3 2 [18,] 5 2
library(gtools) [3,] 1 4 [11,] 3 4 [19,] 5 3
permutations(n=5,r=2) [4,] 1 5 [12,] 3 5 [20,] 5 4
[5,] 2 1 [13,] 4 1
[6,] 2 3 [14,] 4 2
PERMUTATION AND COMBINATION
Permutation (Ordered Shuffling)
Example: In a class of 20 students, in how many different ways can you
select a 1st place, 2nd place, and 3rd place winner? (20 kişilik bir sınıfta, 1.yi,
2.yi, ve 3.yü kaç değişik şekilde seçebilirsiniz?)
Place-1 Place-2 Place-3
20 19 18

Perm(20, 3)=20!/(20-3)!=20*19*18=6,840 Calculations in R


nrow(permutations(n=20,r=3))

> nrow(permutations(n=20,r=3))
[1] 6840
PERMUTATION AND COMBINATION
Permutation (Shuffling)
As you see, in Permutation, ordering of your selection is important. What if it is
not? Then, your problem reduces to a ‘Combination’ problem. (Gördüğünüz gibi,
permütasyonda sıralama önemli? Önemli olmazsa ne olur? O zaman problemimiz
bir kombinasyon problemine dönüşür.)

Combination (Grouping)
Combination defines ‘distinct’ groups of the same size from a given population.
The idea is the same as Permutation but the ordering is not important. Therefore,
even the formulas are slight modifications of each other.
(Kombinasyon, bir popülasyondan, birbirinden farklı aynı genişlikte groupları
temsil eder. Permütasyonla aynı mantığa sahiptir ama sıralama önemli değildir.
Bundan dolayı, formüllerde birbirine benzer.)
PERMUTATION AND COMBINATION
Permutation (Shuffling)

Combination (Grouping)

The k! in the denominator removes the duplicates due to ordering. (Paydadaki k!


Sıralamadan doğan çiftlemeleri ortadan kaldırır).
Let’s see an example.
PERMUTATION AND COMBINATION
EXAMPLE: We have the flowers, A, B, C, D, E, and we like to pick two of them
one by one for two occasions. (Sahip olduğunuz A, B, C, D, E çiçeklerimizden iki
tanesini, bir bir iki ziyaret için seçiyoruz).
Permutations Permutations Group
1 A-B 11 B-D If you give the 1 A-B or B-A={A, B}
2 B-A 12 D-B flowers at the 2 A-C or C-A={A, C}
3 A-C 13 B-E same time… 3 A-D or D-A={A, D}
4 C-A 14 E-B 4 A-E or E-A={A, E}
5 A-D 15 C-D 5 B-C or C-B={B, C}
6 D-A 16 D-C 6 B-D or D-B={B, D}
7 A-E 17 C-E 7 B-E or E-B={B, E}
8 E-A 18 E-C 8 C-D or D-C={C, D}
9 B-C 19 D-E 9 C-E or E-C={C, E}
10 C-B 20 E-D 10 D-E or E-D={D, E}
PERMUTATION AND COMBINATION
EXAMPLE: We have the flowers, A, B, C, D, E, and we like to pick two of them
to give as gifts in a special occasion. In how many different ways can we pick two
of them? (Sahip olduğunuz A, B, C, D, E çiçeklerimizden iki tanesini, özel bir
ziyaret için kaç değişik şekilde seçebiliriz?)
Comb(5,2)=5C2=“5 Choose 2”=

Calculations in R
nrow(combinations(n=5,r=2))

> nrow(combinations(n=5,r=2))
[1] 10
PERMUTATION AND COMBINATION
EXAMPLE: In a basketball team of 9 players, how many different groups of 5
can the coach pick to start the game? (9 kişilik bir basketbol takımında, takım
koçu 5 kişilik kaç değişik group seçebilir?)
Comb(9,5)=9C5=

EXAMPLE: In a soccer team of 18 players, how many different groups of 11 can


the coach pick to start the game if every player can play at any given position?
(18 kişilik bir futbol takımında, takım koçu, her oyuncunun her pozisyonda
oynayabilme varsayımı altında, 11 kişilik kaç değişik takım çıkarabilir?)
Comb(18, 11)=31,824
PERMUTATION AND COMBINATION
EXAMPLE: In a class of 25 students with 15 girls and 10 boys, the teacher
wants to form two teams of 4 students for girls and boys to be sent to a
nationwide math competition to represent their school. In how many different
ways can the teacher form the teams?
(15’i kız 10’u erkek olan 25 kişilik bir sınıftan, öğretmen 4’er kişilik kız ve erkek
ekiplerini, ulusal matematik yarışmasında okulu temsil etmek için seçmek istiyor.
Kaç farklı şekilde bu takımlar oluşturulabilir?)
Comb(15,4)*Comb(10,4)=1365*210=286,650
PERMUTATION AND COMBINATION
EXERCISE: In a town with a population of 1,000 residents, we like to randomly
pick a sample of 20 residents to administer a statistical questionnaire. In how
many different ways can we pick our sample? (1000 kişinin yaşadığı bir
kasabadan, 20 vatandaşı, bir istatistik anketi uygulamak için rastgele seçmek
istiyoruz. Örneğimizi kaç değişik şekilde seçebiliriz?)
Comb(1000, 20)=3.395E+41
You see that there are too many possible samples of size 20 from even this small
town of 1,000 residents. (Gördüğümüz gibi, bu 1000 kişilik kasabadan bile 20 kişi
seçmenin çok fazla muhtemel örneği var.)
Imagine, how many ways would there be if you have a population of 84 million
and you like to pick a sample of 1,000 people to study the political inclination of
people before a national election. (Şimdi düşünün, 84 milyonlu bir
popülasyondan, bir seçimden önceli politik eğilimlerini araştırmak için 1000
kişilik bir örnek seçsek, bunun kaç ihtimali olur?)
COMBINATION and PROBABILITY
EXAMPLE: In a class of 25 students with 15 girls and 10 boys, the principal
randomly picks 6 students to organize the retirement home visits. (15 kız ve 10
erkek öğrenci olan 25 kişilik bir sınıftan, müdür 6 öğrenciyi, yaşlılar evine
ziyaretleri organize etmeleri için rastgele seçmek istiyor.)
a) How many different groups are possible (Muhtemel kaç değişik grup)?
C(25, 6)=177,100
b) How many groups are possible where the group will have 3 girls and 3 boys?
(İçinde 3 kız ve 3 erkek olan kaç farklı group mümkün?)
C(15,3)*C(10,3)=54,600
c) What is the probability that in the group that Principal picks, there are 3 girls
and 3 boys? (Müdürün gruba 3 kız ve 3 erkek seçme olasılığı nedir?)
P(3 Girls, 3 Boys)=54600/177100=0.3083
COMBINATION and PROBABILITY
IMPORTANT PROBABILITY FORMULA (ÖNEMLİ BİR OLASILIK
FORMÜLÜ): Imagine that we have a population of size N, of which N1 is one
kind and the remaining N-N1 is another kind. When we pick n objects from this
population, we find the probability that k of the n objects chosen is of the first
kind using the following formula (Elimizde N1’i bir tür, N-N1’i başka bir tür olan,
N kişilik bir popülasyon olduğunu varsayalım. Bu popülasyondan, k tanesi birinci
türden gelecek (yani N1’den), n kişi seçme olasılığını aşağıdaki formüle göre
buluruz):

We will see soon that the above formula is the Probability Distribution Function
of Hypergeometric Distribution (Yakında yukarıdaki formülün aslında
Hipergeometrik Dağılımın Olasılık Dağılım Fonksiyonu olduğunu göreceğiz.)
COMBINATION and PROBABILITY
EXAMPLE: In a box of 12 blue and 8 red pens, you like to pick four pens to give
to your friend. (İçinde 12’si mavi, 8’i kırmızı kalem olan bir kutudan, arkadaşına
vermek üzere 4 kalem seçmek istiyorsun.)
a) What is the probability that you give no red pens? (Hiç kırmızı kalem
vermeme olasılığı nedir?)
Combin(8,0)*Combin(12,4)/Combin(20,4)=1*495/4845=0.1022
In Excel (Google Sheet):

Calculations in R
## Inputs: k, N1, N-N1, n ## > dhyper(0,8,12,4)
dhyper(0,8,12,4) [1] 0.1021672
COMBINATION and PROBABILITY
EXAMPLE: In a box of 12 blue and 8 red pens, you like to pick four pens to give
to your friend. (İçinde 12’si mavi, 8’i kırmızı kalem olan bir kutudan, arkadaşına
vermek üzere 4 kalem seçmek istiyorsun.)
b) What is the probability that you give one red and 3 blue? (Bir kırmızı, 3 mavi
olasılığı)?
Combin(8,1)*Combin(12,3)/Combin(20,4)=8*220/4845=0.3633
dhyper(1,8,12,4)0.3632611
c) What is the probability that you give 3 red and 1 blue? (3 kırmızı, 1 mavi
olasılığı?)
Combin(8,3)*Combin(12,1)/Combin(20,4)=56*12/4845=0.1387
dhyper(1,8,12,4)0.1386997
COMBINATION and PROBABILITY
EXERCISE: From a local Doctors Without Borders team of 23 Female and 28
male doctors, United Nations wants to pick 5 doctors to be sent to Central Africa
for a health promotion mission. (23 kadın ve 28 erkek doktorlu bir lokal Sınır
Tanımayan Doktorlar ekibinden 5 doktor, Birleşmiş Millerler tarafından Orta
Afrika’ya bir sağlık misyonuna katılmak üzere seçilecek.)
a) The probability that there is no female doctor? (Ekipte hiç kadın doktor
olmama olasılığı?)
b) The probability that there is one female doctor? (Ekipte 1 kadın doktor)
c) The probability that there are two female doctors? (Ekipte 2 kadın doktor)
d) The probability that there are three female doctors? (Ekipte 3 kadın doktor)
e) The probability that there are four female doctors? (Ekipte 4 kadın doktor)
f) The probability that there are five female doctors? (Ekipte 5 kadın doktor)
COMBINATION and PROBABILITY
EXAMPLE: In a school, there are 50 pre-school students, 40 elementary school
students, 30 middle school students, 20 high school students. You like to take a
random sample of 20 students from this school to administer a parent
questionnaire. (Bir okulda, 50 okul öncesi, 40 ilkokul, 30 ortaokul, 20 lise
öğrencisi mevcut. 20 öğrenciyi, bir veli anketi uygulamak için rastgele seçmek
istiyorsunuz.)
a) What is the probability that you select 5 students from each level? (Her
seviyeden 5 öğrenci seçme olasılığı nedir?)

In Excel,
=COMBIN(50,5)*COMBIN(40,5)*COMBIN(30,5)*COMBIN(20,5)/COMBIN(140,20)
COMBINATION and PROBABILITY
EXAMPLE: In a school, there are 50 pre-school students, 40 elementary school
students, 30 middle school students, 20 high school students. You like to take a
random sample of 20 students from this school to administer a parent
questionnaire. (Bir okulda, 50 okul öncesi, 40 ilkokul, 30 ortaokul, 20 lise
öğrencisi mevcut. 20 öğrenciyi, bir veli anketi uygulamak için rastgele seçmek
istiyorsunuz.)
b) What is the probability that you select 7 from pre-school, 6 from elementary
school, 4 from middle school and 3 from high school? (Okul öncesinden 7,
ilkokuldan 6, ortaokuldan 4 ve liseden 3 öğrenci seçme olasılığı nedir?)

In Excel,
=COMBIN(50,7)*COMBIN(40,6)*COMBIN(30,4)*COMBIN(20,3)/COMBIN(140,20)
END
OF
LECTURE-3

You might also like