30
Coin Tossing The General Case Math 141 Lecture 3: The Binomial Distribution Albyn Jones 1 1 Library 304 [email protected] www.people.reed.edu/jones/courses/141 Albyn Jones Math 141

Math 141 - Lecture 3: The Binomial Distributionpeople.reed.edu/~jones/Courses/P03.pdf · Coin Tossing The General Case Math 141 Lecture 3: The Binomial Distribution Albyn Jones1 1Library

  • Upload
    voduong

  • View
    219

  • Download
    1

Embed Size (px)

Citation preview

Coin TossingThe General Case

Math 141Lecture 3: The Binomial Distribution

Albyn Jones1

1Library [email protected]

www.people.reed.edu/∼jones/courses/141

Albyn Jones Math 141

Coin TossingThe General Case

Outline

Coin TossesThe General Case

Albyn Jones Math 141

Coin TossingThe General Case

Independent Coin TossesCrucial Features

Dichotomous Trials: Each toss results in either Heads, H,or Tails T .Independence: Successive tosses are independent;knowing we got H on the first toss does not help us predictthe outcome of the second toss.Constant probability: Each trial has the same probabilityP(H) = 1/2 = P(T ) (a ‘fair coin’).

Albyn Jones Math 141

Coin TossingThe General Case

Examples of Different Experiments

Binomial: Count the number of Heads in a fixed number oftosses.Geometric: Count the number of Tails before the first Head.Negative Binomial: Count the number of Tails beforebefore the k -th Head.

Albyn Jones Math 141

Coin TossingThe General Case

Random Variables

Random Variable: A random variable is a function mappingpoints in the sample space to R, the real numbers.

Example: Let X be the number of Heads in 3 independenttosses of a fair coin.

Albyn Jones Math 141

Coin TossingThe General Case

A Binomial Random Variable

Toss a fair coin 3 times, count the number of Heads. Let X bethe number of Heads. What are the possible outcomes?

{HHH} 7→ X = 3

{HHT} ∪ {HTH} ∪ {THH} 7→ X = 2

{HTT} ∪ {THT} ∪ {TTH} 7→ X = 1

{TTT} 7→ X = 0

Albyn Jones Math 141

Coin TossingThe General Case

Probabilities

Thus we can compute probabilities for the random variable (RV)X is we can compute probabilities of events in the originalsample space.

P(X = 3) = P({HHH})

P(X = 2) = P({HHT} ∪ {HTH} ∪ {THH})

P(X = 1) = P({HTT} ∪ {THT} ∪ {TTH})

P(X = 0) = P({TTT})

Albyn Jones Math 141

Coin TossingThe General Case

Probabilities

Successive tosses are independent, so

P(X = 3) = P({HHH}) = P(H)P(H)P(H) =

(12

)3

and

P(X = 0) = P({TTT}) = P(T )P(T )P(T ) =

(12

)3

In fact, the probability of any sequence of 3 tosses is the same,for example

P({HHT}) = P(H)P(H)P(T ) =

(12

)3

Albyn Jones Math 141

Coin TossingThe General Case

More Probabilities

Since probabilities of unions of disjoint events add, we just haveto count the number of sequences of three tosses with 2 Headsto get P(X = 2):

P(X = 2) = P({HHT} ∪ {HTH} ∪ {THH})

= P({HHT}) + P({HTH}) + P({THH})

Again, due to independence, the order of getting the two Headsand one Tail doesn’t matter, so

P({HHT}) = P({HTH}) = P({THH}) =(

12

)3

Thus

P(X = 2) = 3(

12

)3

=38

Albyn Jones Math 141

Coin TossingThe General Case

Finally: Probabilities for 3 tosses

P(X = 3) = 1(

12

)3

=18

P(X = 2) = 3(

12

)3

=38

P(X = 1) = 3(

12

)3

=38

P(X = 0) = 1(

12

)3

=18

Note:

P(X = 0) + P(X = 1) + P(X = 2) + P(X = 3) = 1

Albyn Jones Math 141

Coin TossingThe General Case

X ∼ Binomial(n,1/2)Count Heads in n independent tosses of a fair coin

As with 3 independent tosses, any sequence of nindependent tosses of a fair coin has the same probability.Example: for 8 tosses,

P(HHHHTTTT ) = P(HTHTHTHT ) = P(TTTTTTHH) =

(12

)8

The point: to compute P(X = k) we have to count thenumber of sequences of n symbols {H,T} with k H ’s, andthus (n − k) T ’s, then multiply by the probability of anysequence of n tosses.

Albyn Jones Math 141

Coin TossingThe General Case

Counting Things: Permutations

How many ways are there to rearrange the numbers 1,2,3,4?We could list them all, with some effort:

{1,2,3,4}, {2,1,3,4}, {3,1,2,4}, {4,1,2,3}, . . .

We could be clever:There are 4 choices for the first position.After choosing the first, there remain 3 choices for thesecond position.After choosing the first and second positions, there are 2possibilities for the third, and only 1 for the fourth.

4 · 3 · 2 · 1 = 4! = 24

Albyn Jones Math 141

Coin TossingThe General Case

Permutations of n objects

How many ways are there to rearrange the numbers1,2,3, . . . ,n?

There are n choices for the first position.After choosing the first, there remain (n − 1) choices forthe second position.After choosing the first and second positions, there are(n − 2) possibilities for the third, and so forth.

n · (n − 1) · (n − 2) . . . · 1 = n!

n! gets big quickly: 10! = 3628800.

Albyn Jones Math 141

Coin TossingThe General Case

Example: Permutations of 4 objects

Each row lists permuations beginning with the same object,grouped by the choices for the second object:

1234 1243 1324 1342 1423 1432

2134 2134 2314 2341 2413 2431

3124 3142 3214 3241 3412 3421

4123 4123 4213 4231 4312 4321

Albyn Jones Math 141

Coin TossingThe General Case

Practice with Factorials

What is 1! ?What is 2! ?What is 3! ?What is 0! ?

Albyn Jones Math 141

Coin TossingThe General Case

A Formal definition for Factorials

The standard recursive definition is

0! = 1

For n > 0 ∈ Z,n! = n · (n − 1)!

It is useful to remember this recursive definition! Forexample it makes obvious the relation

n!n

= (n − 1)!

Albyn Jones Math 141

Coin TossingThe General Case

Combinations

How many ways are there to rearrange the 5 symbolsH,H,H,T ,T , that is three Heads and two Tails?

Label them uniquely: H1,H2,H3,T4,T5

We have 5 objects, there are 5! orders.Some of those orders are redundant: {H1,H2,H3,T4,T5} isindistinguishable from {H3,H2,H1,T5,T4} or{H3,H1,H2,T4,T5}.Divide out the number of indistinguishable (or equivalent)patterns of 3 Heads, i.e. 3!, and 2 Tails, i.e. 2!.Answer:

5!3! · 2!

=5 · 4 · 3!3! · 2!

=5 · 42 · 1

= 10

Albyn Jones Math 141

Coin TossingThe General Case

Example: 4 Coin Tosses

4 HHHH(4

4

)3 HHHT ,HHTH,HTHH,THHH

(43

)2 HHTT ,HTHT ,THHT ,TTHH,THTH,HTTH

(42

)1 TTTH,TTHT ,THTT ,HTTT

(41

)0 TTTT

(40

)Albyn Jones Math 141

Coin TossingThe General Case

Sequences of k Heads in n tosses

For 3 H and 2 T the number of possible orders was

5!3! · 2!

For k H and (n − k) T in n tosses the number of possibleorders will be ‘n choose k ’: the number of ways to select kobjects out of a set of size n.(

nk

)=

n!k ! · (n − k)!

Note: (n

n − k

)=

n!(n − k)! · k !

=

(nk

)

Albyn Jones Math 141

Coin TossingThe General Case

Practice with Binomial Coefficients

What is each of the following? (n0

)(

nn

)(

n1

)(

nn − 1

)(

n2

)Albyn Jones Math 141

Coin TossingThe General Case

The General Case

In general, we might be working with dichotomous trials wherethe event of interest has probability p, possibly not 1/2. Most ofwhat we have learned about coin-tossing carries over to thegeneral case.

Albyn Jones Math 141

Coin TossingThe General Case

The Binomial DistributionX ∼ Binomial(n, p)

Dichotomous Trials: Each trial results in either a ‘Success’,S, or a ‘Failure’ F .Independence: Trials are mutually independent; knowingwe got S on one trial does not help us predict the outcomeof any other trial.Constant probability: Each trial has the same probabilityP(S) = p, and P(F ) = 1− p.X counts the number of S’s.n the number of trials is fixed.

Albyn Jones Math 141

Coin TossingThe General Case

Binomial(n,p) Probabilities

Independence: Every sequence of n trials with ksuccesses has the same probability!

P(SSF ) = P(S)P(S)P(F ) = P(F )P(S)P(S) = P(FSS)

Let p = P(S) and q = 1− p = P(F ), then for a RVX ∼ Binomial(n,p)

P(X = k) =(

nk

)pk qn−k

Again,(n

k

)counts the number of sequences of length n

with k successes.

Albyn Jones Math 141

Coin TossingThe General Case

Example

Suppose we roll a fair die 5 times. What is the probability weget no ones?

What Binomial distribution should we use?Let S be the event we roll a 1. If the die is fair,p = P(S) = 1/6. n = 5, as there are 5 trials. Let X be thenumber of 1’s we get in the 5 rolls. Then

X ∼ Binomial(5,16)

Thus

P(X = 0) =(

50

) (16

)0 (56

)5

= 1 · 1 · 31257776

∼ 0.402

Albyn Jones Math 141

Coin TossingThe General Case

Binomial(10,1/2)

0 1 2 3 4 5 6 7 8 9 10

0.00

0.05

0.10

0.15

0.20

Albyn Jones Math 141

Coin TossingThe General Case

Binomial(10,1/5)

0 1 2 3 4 5 6 7 8 9 10

0.00

0.05

0.10

0.15

0.20

0.25

0.30

Albyn Jones Math 141

Coin TossingThe General Case

Sums of Binomial RV’s

Suppose that X ∼ Binomial(n,p) and Y ∼ Binomial(m,p)are independent Binomial RV’s with the same probability p.What is the distribution of X + Y ?X + Y ∼ Binomial(n + m,p)!

Albyn Jones Math 141

Coin TossingThe General Case

R functions

Density Function: P(X = k) = dbinom(k ,n,p)(Cumulative) Distribution Function:P(X ≤ k) = pbinom(k ,n,p)Random numbers: rbinom(N,n,p)Last Example: X ∼ Binomial(5, 1

6),P(X = 0) = dbinom(0,5,1/6) = 0.4018776

Albyn Jones Math 141

Coin TossingThe General Case

Binomial Random WalkRandom Walk functions on 141 website

RW = function(n){

x = sample(c(-1,1),size=n,replace=T)rw = cumsum(x)plot(1:n,rw,xlab="N",ylim=c(-3.1*sqrt(n),3.1*sqrt(n)),type="l")abline(h=0,lty=2)

}

RW1= function(n,color="blue"){

x = sample(c(-1,1),size=n,replace=T)rw = cumsum(x)lines(1:n,rw,col=color)

}

Albyn Jones Math 141

Coin TossingThe General Case

Summary

There are n! permutations of n objects.Binomial coefficients, the number of subsets of size k froma set of n objects: (

nk

)=

n!k ! (n − k)!

The Binomial Distribution:

P(X = k) =(

nk

)pk qn−k

Albyn Jones Math 141