Module2 LMS
Module2 LMS
Contents
1 Ch 2.1 Random Variables of the Discrete Type 2
1.1 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Example - Soft Drinks . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Probability Mass Function . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Binomial Distribution (Start of Ch 2.4) . . . . . . . . . . . . . . 7
1.5 Derivation of Binomial Probabilities . . . . . . . . . . . . . . . . 8
1.6 Sampling with Replacement . . . . . . . . . . . . . . . . . . . . . 8
1.7 Pictures of Binomial Probabilities . . . . . . . . . . . . . . . . . . 9
1.8 Hypergeometric - Sampling without Replacement . . . . . . . . . 9
1.9 Hypergeometric - Derivation . . . . . . . . . . . . . . . . . . . . . 10
1.10 Hypergeometric - Pictures . . . . . . . . . . . . . . . . . . . . . . 10
1
8 Ch 2.4 - The Binomial Distribution 31
8.1 Recall PMF from Module 2 1 . . . . . . . . . . . . . . . . . . . . 31
8.2 Binomial Mean and Variance . . . . . . . . . . . . . . . . . . . . 32
8.3 Sampling with Replacement . . . . . . . . . . . . . . . . . . . . . 32
8.4 MGF for Binomial . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Is often not practical especially when probabilities come from specific past data
or more general beliefs
Often the results of our experiment or observation is a number or numbers and
the events of interest centre on these numbers
For example, in the rocket failure example, we might only be interested in the
number of components that fail - since the components are as-
sumed identical
And in the soft drink example, we might only be concerned about the number
of chains that give more shelf space to P
And in the sampling lines of code example, we might only be concerned about
the total number of lines of code that could be improved
Definitions
2
X(s)
(P,P,P) 3
(P,C,P)
(P,P,C)
(C,P,P) 2
(C,P,C)
(P,C,C) 1
(C,C,P)
(C,C,C) 0
S
Figure 2:
3 chains
1
P (X = 3) = P ({(P, P, P )}) =
8
2 chains
3
P (X = 2) = P ({(P, P, C), (P, C, P ), (C, P, P )}) =
8
1 chain
3
P (X = 1) = P ({(P, C, C), (C, C, P ), (C, P, C)}) =
8
0 chain
1
P (X = 0) = P ({(C, C, C)}) =
8
3
Example - Soft Drinks rv
If X is the number of supermarket chains that give more shelf space to soft
drink P, what is the probability that X is even? odd?
4
P (X is even) = P (X = 0) + P (X = 2) =
8
4
P (X is odd) = P (X = 1) + P (X = 3) =
8
For this reason, the rule which gives for a number x the probability P (X = x)
is called the the probability mass function for the random variable
Small letters are used for arbitrary numbers and capital letters for the names
of random variables
General Definition
4
Rocket Failure PMF - Solution
Let X be the random variable giving the number of rocket components that do
not fail.
The range of X is {0, 1, 2, 3}.
By independence
P (X = 0) = P (A1 ∩ A2 ∩ A3 )
= P (A1 )P (A2 )P (A3 ) = 0.153 = 0.00338
Splitting [X = 1] into the three mutually exclusive events that partition it and
using independence gives
Similarly
x 0 1 2 3
P(X=x) 0.003375 0.057375 0.325125 0.614125
The probability computed in the first Rocket Failure example in Module 1 was
P (X ≥ 1), which was computed as 1 − P (X = 0).
An alternative would have been to compute it as P (X = 1)+P (X = 2)+P (X =
3) but this is much more complicated.
5
Figure 3: Probability Mass Function for X
Out[1]=
6
1.4 Binomial Distribution (Start of Ch 2.4)
Similarities
Similar Examples In both the soft drink example and the rocket failure example,
the pmf calculations for the rv X were similar
Difference The only difference was the probability 0.5 in the soft drink exam-
ple (equally likely outcomes) compared to 0.85 in the rocket failure
example
Structure? Both examples had the idea of a successful outcome in each of 3
independent trials
Soft Drink Ex. the trials were the decisions of the three supermarket chain and
success was soft drink P having more shelf space
Rocket Ex. the trials were the performance of the components and success was
a component not failing
Two Outcomes Each trial has one of two possible outcomes success or failure
denoted S and F
Events of success The results of the trials define independent events A1 , A2 , · · · , An
representing success, S, on trials 1, 2, · · · , n
Events of failure So the events of failure, F , on the same trials are Ac1 , Ac2 , · · · , Acn
Binomial RV X
Binomial RV Consider the rv, X, which is the number of trials that result in
success
7
1.5 Derivation of Binomial Probabilities
PMF of Binomial RV - Informal
Hence For x = 0, 1, 2, · · · , n
n x
P (X = x) = p (1 − p)n−x (2)
x
Number of subsets There are nx subsets of size x from {1, 2, · · · , n} and the
Hence For x = 0, 1, 2, · · · , n
n x
P (X = x) = p (1 − p)n−x
x
8
PDF[BinomialDistribution[4, 0.9], {0, 1, 2, 3, 4}]
{0.0001, 0.0036, 0.0486, 0.2916, 0.6561}
DiscretePlot[
Table[PDF[BinomialDistribution[40, p], k], {p, {0.1, 0.5, 0.7, 0.9}}] // Evaluate,
{k, 40}, PlotRange → All, PlotMarkers → Automatic, AxesLabel → {x, pmf}]
There are 4 Bernoulli trials with success being that the class member chosen
worked on this subject on the day prior to them being chosen.
The trials are independent since the spinner choices are independent and we
are told the probability is constant.
Hence,
P (X = 0) = 0.14 = 0.0001
P (X = 1) = 4 × 0.9 × 0.13 = 0.0036
4×3
P (X = 2) = × 0.92 × 0.12 = 0.0486
2
P (X = 3) = 4 × 0.93 × 0.1 = 0.2916
P (X = 4) = 0.94 = 0.6561
9
Figure 6: PMF’s n = 40, p=0.1,0.5,0.7,0.9, t=50
Note the top (and bottom) lines of the combination numbers in the numerator
add to the top (resp. bottom) line in the denominator
Samples Each sample is a subset of size n from the t lines of code, so there are
t
n samples
Sample lines improved There are xb ways to choose the x lines in the sample
10
Figure 7: Same n and p but t = 10,000
Capture-recapture
Calculations like this are used in practice. Unlike the code example, it is the
total population size, T , about which inference is needed. Bayes Theorem
can be used. Governments use these, or alternative frequentist, techniques for
monitoring population sizes and making policy decisions.
My travel time to work varies according to whether I drive early in the morning,
at peak hour, get dropped at the station, take tram and bus at peak hour or
take tram and bus outside peak hour. In the last case, a typical travel time is
45 minutes by tram and bus but it can be as little as 20 minutes by car early
in the morning. Over a two week period, my travel times were 45 min. ± a
departure time (min.) given by the following table:
Table of Departures from 45 Minutes
11
Day 1 2 3 4 5 6 7 8 9 10
Dep. (min.) +5 -5 -5 +5 +5 -25 +10 -25 -5 -20
Find the mean and empirical variance of the departures from my standard
travel time of 45 minutes.
Definitions
For our departures from the standard travel time of 40 minutes we have the
mean or average departure as
5 − 5 + · · · − 20
x̄ = = −6 (6)
10
12
Definition of Expectation
Repetitions In computing the sum, we could collect together all the outcomes s
which have the same value of X(s)
Travel Times there were three repetitions of -5, three reps. of +5
and 2 reps. of -25
This gives
X
E(X) = xP (X = x) (9)
x∈range(X)
Solution - Game
Definition Let Y be the random variable which gives the prize one time I play
the game.
Long Run Frequencies Over many plays of the game, the prize will be y¢ (y =
1, 5 or 35) with approximate fraction P (Y = y) of the
time.
Long Run Gain Hence, adding over a long sequence of games, the average amount
of money (in ¢) I win will get closer to
1 × P (Y = 1) + 5 × P (Y = 5) + 35 × P (Y = 35) = E(Y )
Comments - Game
Actual electronic games machines operate like this with more complicated chance
mechanisms and more elaborate prize scales.
Legislation Often limits the charge to the expected return (that is the expecta-
tion just calculated) plus a defined profit margin.
Example In New South Wales clubs, the return is legislated to be at least 85%
of the money input.
13
X(s) Y(s)
X u
roll 6 6 35
roll 5 5
roll 4 4
5
roll 3 3 1
roll 2 2
roll 1 1
S Y direct
Start with a different random variable, X, which is the number on the die so
that X has probability mass function P (X = x) = 16 for x = 1, 2, · · · , 6.
RV Y is obtained by applying the function u to X so that
X = u(Y )
where
u(1) = u(2) = u(3) = 1, u(4) = u(5) = 5, u(6) = 35
Diagram of X = u(Y)
Expectation of X
This can be equally found as:
X
E(Y ) = Y (s)P ({s}) (10)
s∈S
6
X
= u(x)P (X = x) (11)
x=1
X
= yP (Y = y) (12)
y=1,5or35
Aggregation at three levels in the three different ways in equations (10), (11),
(12) to compute E(Y ).
14
1 to 1 In this example, there was no aggregation from the sample space S to the
range of X - one to one correspondence between outcomes in the sample
space and results for Y .
But would not have had this if the sample space had two throws of the dice and
X recorded the outcome of the first throw - the 36 sample points aggregated
to 6 outcomes for X.
Aggregation from 6 outcomes in range of X via the function u to 3 prize values
for Y .
Right Hand Sides the same in equations (10), (11), (12) by the distributive law
Need X
E(|u(X)|) = |u(x)|P (X = x) < ∞
x
to be safe
Travel Time Example had Empirical Variance defined as the average of squared
deviations around the mean:
10
X 1
v= (xi − x̄)2 ×
x=1
n
15
Example - Variance of Game
Find the variance of the random variable Y in the simple game with the die
Problem is that µ = E(X) was needed to define the function u and hence to
calculate the variance of the random variable
Needed are some properties of expectation that will enable the calculation of
variance at the same time as the calculation of the mean
Demonstration
Constant Using the definition of expectation in (8), the fact that probabilities
of sample points add to one and the distributive law for numbers,
X X
E(c) = cP ({s}) = c P ({s}) = c
s∈S s∈S
16
Demonstration
Addition Using the definition of expectation in (8), and the distributive, com-
mutative and associative laws for numbers
X
E(X + Y ) = (X(s) + Y (s))P ({s})
s∈S
X X
= X(s)P ({s}) + Y (s)P ({s})
s∈S s∈S
= E(X) + E(Y )
Linear Follows from induction using the case n=2 and both the addition and
multiplication properties in order:
V ar(X) = E (X − µ)2
= E X 2 − 2µX + µ2
= E(X 2 ) − 2µE(X) + µ2
2
= E(X 2 ) − E(X)
(18)
Mean
1 2 3
E(X) = (1 + 5) × + (2 + 4) × + 3 × = 3
9 9 9
Intuitive because the PMF is symmetric about 3
17
pmf, f(x)
0.35
●
0.30
0.25
● ●
0.20
0.15
● ●
0.10
0.05
x
1 2 3 4 5
Mean Square
1 2 3 1
E(X 2 ) = (1 + 52 ) × + (22 + 42 ) × + 32 × = 10
9 9 9 3
Variance
2 1 1
V ar(X) = E(X 2 ) − E(X) = 10 − 9 = 1
3 3
= E (X − µ)2 + (b − µ)2
RHS is ≥ V ar(X) since the first term is the variance and the second is ≥ 0 and
0 if, and only if, b = µ
18
5 Ch 2.2 - Back to Mathematical Expectation
5.1 Example - Minimum Squared Deviation
Example - Mean Minimises Squared Deviations
Find the value of the number b which minimises E (X − b)2
RHS is ≥ V ar(X) since the first term is the variance and the second is ≥ 0 and
0 if, and only if, b = µ
For data, descriptive statistics likes to make a numerical summary of all the
values: data value = summary + residual
For data x1 , x2 , · · · , xn and any number b, this is xi = b + (xi − b)
Criterion: b should be chosen to minimise the residuals in total, for example to
minimise the distance of the residuals from the origin
Particular case of the Example, is the random variable,X, that chooses one of
the xi at random. The expected value of (X − b)2 , is related to the
Euclidean distance by
p
Euclidean distance = n ∗ E(X − b)2
19
y
Euclidean Distance
( x2 , y2 )
(x − x ) +(y − y )
2 2
y2 − y1
2 1 2 1
( x1, y1 ) x2 − x1
x1
b
xn
x2
1 2 !!!!! n i
Hence Euclidean distance of the residuals from the origin is minimised by choos-
ing b = x̄
Euclidean Distance takes the square root so that it is in the same units as the
measurements.
Standard Deviation of a random variable is the square root of V ar(X), often
denoted σ.
20
5.2 Example - Sampling with and without replacement
Example - Mean Number with a Disease
Find the mean number of people with a particular disease in a random
sample taken from a population with or without replacement. Assume that the
sample is size n and that the population has a proportion p of people with the
disease.
With Replacement makes the sample outcomes - diseased or not - the results of
Bernoulli trials with constant probability p.
Then using the fact that the orderings are equally likely, defining Xi (i = 1, 2, · · · , n)
to be 1 if the ith person in the sample has the disease and supposing there
are b out of the t people in the population with the disease
21
number of outcomes in [Xi = 1]
P (Xi = 1) =
total number of outcomes
b × (t − 1)!
=
t!
b
= =p
t
since whichever of the b people with the disease are chosen in position i in the
random ordering, there are (t − 1)! orderings for the other t − 1 positions in the
ordering.
22
Derivative M 0 (t) = 1/9 et + 2 × 2/9 e2t + 3 × 3/9 e3t + 4 × 2/9 e4t + 5 × 1/9 e5t
So M 0 (0) = 1/9 + 2 × 2/9 + 3 × 3/9 + 4 × 2/9 + 5 × 1/9 = 3
M 0 (t) = E(XetX )
Putting t = 0 gives
Differentiating again
Gives
E(X 2 ) = M 00 (0) (20)
So
In general
Differentiating k times k = 0, 1, 2, · · ·
where the brackets (k) in the numerator indicates the kth deriva-
tive
Note
1 = E(X 0 ) = M (t)
23
Solution - Finding Moments from MGF
Derivative
M 0 (t) = pet × n(q + pet )n−1
M 00 (t) = pet × n(q + pet )n−1 + p2 e2t × n(n − 1)(q + pet )n−2
In general if the MGF exists −h < t < h, h > 0, then the PMF can be found
from the MGF
If it is known that there are (say) 5 values in the range of the rv, then evaluating
the MGF at 5 different points will give 5 simultaneous equations in the 5
unknown probabilities that can be solved
More complicated for other random variables, for example if there are infinitely
many possible values
However, the mgf is always good for finding expectations of the random variable
to all powers can be found by repeated differentiation
24
pmf(k)
Skewness = -0.2
0.12 Kurtosis = 3.0
0.10
0.08
0.06
0.04
0.02
k
10 20 30 40
Demonstration
By linearity of expectation, the calculation formula for variance and the
main property for independent random variables
V ar(X + Y ) = E[(X + Y )2 ] − (E(X) + E(Y )))2
= E[X 2 + Y 2 + 2XY ] − (E(X) + E(Y ))2
= V ar(X) + V ar(Y ) + 2E(XY ) − 2E(X)E(Y ) (25)
= V ar(X) + V ar(Y )
just like Pythagoras’ theorem.
25
Variance of sum for non-independent random variables
Can be calculated using using equation (25) on the last slide since independence
only enters in using the Main Property (equation (23)) for independent
random variables
This will be discussed further in Module 4.
The variance for the number of successes in sampling without replacement is an
example - see later slides for pictures of the pmf in this case.
26
As n gets large, the variance of the sample mean gets small ie most values are
concentrated around the population mean, µ = E(X)
This is why the amount of information collected increases generally with the
square root of the sample size
In Module 5 we’ll study this relationship with sample size more
These connections are basic tools in practical statistical data science
27
pmf(k)
D = 0.00
0.015
0.005
k
900 950 1000 1050
Figure 13: Electorate=16m, p= 0.48 N ewsP oll 20 M arch 2017
Interpretation is that the spread of the distribution for the sample mean is small
in a sample of 2000, since the standard deviation is maximised
when p = 12 and is then 0.011.
When the sample is taken without replacement, the expectation is exact.
Further the variance and standard deviation will be approximately right since
the population size of enrolled voters is about 16 million and this is
much larger than the sample size.
Definition D in the pictures of the pmf’s with and without replacement is the
maximum difference in any probability computed with or without
replacement
Plot shows no difference for any probability in sampling with or without re-
placement for a population as large as 16 million, the size of the Australian
Electorate, when the sample size is 2000
On the other hand if the total size were just 2100 then there is a big difference
in probabilities with and without replacement, as the figure
shows:
28
pmf(k)
0.08 D = 0.62
0.06
Without Repl.
Out[217]=
0.04 With Repl.
0.02
k
900 950 1000 1050
Figure 14: Pop Size=2,100, p= 0.48 N ewsP oll 20 M arch 2017
29
pmf(k)
0.030 D = 0.25
0.025
0.020 Without Repl.
Out[229]=
0.015 With Repl.
0.010
0.005
k
900 950 1000 1050
Figure 15: Pop Size=3,100, p= 0.48 N ewsP oll 20 M arch 2017
pmf(k)
0.020 D = 0.05
0.015
Without Repl.
Out[241]=
0.010 With Repl.
0.005
k
900 950 1000 1050
Figure 16: Pop Size=10,100, p= 0.48 N ewsP oll 20 M arch 2017
30
pmf(z)
0.4
0.3
With Repl.
W'out Pop=2,100
Out[13]=
0.2 W'out Pop=3,100
W'out Pop=10,100
W'out Pop=16m
0.1
z
-3 -2 -1 1 2 3
Figure 17: Scaled pmf for p=0.48, with and w’out replacement, Pop Size varying
Because the units on the z axis increase by the reciprocal of the standard de-
viation, to preserve the probabilities adding to one, it is necessary to
scale the pmf by the standard deviation
Next figure shows the pmf for the standardized sample number with replacement,
and without replacement for population sizes 2,100, 3,100, 10,100 and
16,000,000
Two Outcomes Each trial has one of two possible outcomes success or failure
denoted S and F
Binomial RV Consider the rv, X, which is the number of trials that result in
success
31
PMF of Binomial RV
Follow , by the representation, (29) from the properties of the Sample Mean of
Independent Random Variables with the same Distribution
And
V ar(X) = np(1 − p)
M1 (t) = E(etX1 )
= et×1 P (X1 = 1) + et×0 P (X1 = 0)
= (pet + q)
where q = 1 − p
MGF for sum of independent rv’s is product of MGF’s
So
M (t) = E(etX )
= M1 (t)M2 (t) · · · Mn (t)
= (pet + q)n
32
9 Ch 2.5 - The Negative Binomial Distribution
9.1 PMF for Time till Success
Time till First Success in Bernoulli Trials
P (T = i) = P (X1 = 0, Xi−1 = 0, · · · , Xi = 1)
= P (F · · · F S)
= (1 − p)i−1 p, i = 1, 2, · · · (30)
Argument is similar for Tr , r = 1, 2, · · · which is the number of trials till the rth
success
Any pattern which has Tr = i has exactly r successes in the i trials with the rest
failures. Also, trial i must be a success for Tr = i. Otherwise, the trials for
the other r − 1 successes in the first i − 1 trials can be chosen freely.
i−1
There are r−1 ways to choose the trial numbers for the successes
So
i−1 r
P (Tr = i) = p (1 − p)i−r i = r, r + 1, · · ·
r−1
Geometric is the name for the distribution for the time to the first succcess in
Bernoulli trials
There is just one number p, the probability of a success on a trial, that deter-
mines the pmf
Negative Binomial is the name for the distribution of the time to the rth success
Negative Binomial has two numbers, r and p which determine the pmf
33
● p=0.9 ■ p=0.5 ◆ p=0.2 ▲ p=0.1
pmf(k)
●
0.8
0.6
■
0.4
■
0.2◆ ◆
◆
■
▲ ▲
● ◆
▲ ▲ ◆
▲
■ ◆
▲ ▲
◆ ▲
◆ ▲ ▲ ▲
■ ◆ ▲ ▲
k
■ ◆ ◆ ◆ ◆ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲ ▲
● ● ● ● ■
● ■
● ■
● ■
● ■
● ■
● ■
● ◆
■
● ◆
■
● ◆
■
● ◆
■
● ◆
■
● ◆
■
● ◆
■
● ◆
■
● ◆
■
● ▲
◆
■
● ▲
◆
■
● ▲
◆
■
●
5 10 15 20 25
0.6
0.4
■ ■
0.2 ●
■
◆ ◆ ◆
■ ◆ ◆
◆ ◆ ◆ ◆
◆ ▲
■
▲ ▲ ▲ ▲ ▲ ◆
▲ ◆
▲ ▲
◆ ▲ ▲ ▲ ▲
▲ ▲ ■ ◆ ◆ ▲ ▲ ▲ ▲
k
▲ ● ■ ◆ ◆ ◆ ◆ ▲ ▲ ▲ ▲
▲ ● ● ● ● ● ■
● ■
● ■
● ■
● ■
● ■
● ■
● ■
● ■
● ■
● ■
● ◆
■
● ◆
■
● ◆
■
● ◆
■
● ◆
■
● ◆
■
●
5 10 15 20 25
Figure 19: PMFs for Trial Number of 2nd Success in Bernoulli Trials
34
● p=0.9 ■ p=0.5 ◆ p=0.2 ▲ p=0.1
pmf(k)
0.35 ●●
0.30
0.25
0.20 ●
0.15
0.10 ■■
■■
●■ ■
■
■
0.05
■
■ ■
■
■ ◆◆◆◆◆◆◆◆◆◆◆
■● ■ ◆ ◆◆◆◆ ◆◆◆◆◆
■■ ◆◆◆◆ ◆◆
◆◆◆ ◆◆◆▲◆
■ ◆■◆ ▲▲▲▲◆▲◆ ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
▲◆
▲◆
k
● ◆◆
◆ ■■■■ ▲▲ ▲◆▲◆
▲◆ ▲◆
▲◆
▲
◆
■
■◆
▲◆
▲◆
▲◆
▲◆●
◆
▲◆
▲
▲◆
●
▲
●◆
◆
▲
●◆
▲
▲
●◆
▲
●
●◆
◆
▲
●◆
▲
▲
●◆
▲
●
●▲
●▲
●▲
▲
●●▲
●▲
●▲
●▲
▲
●■▲
●■▲
●●■▲
■▲
●●■▲
■▲
●●■▲
■▲
●●■▲
■▲
●●●■▲
■▲
■▲●●■▲
■▲
●●■▲
■▲
●●■▲
■▲
●●■▲
■▲
●●■▲
■▲
●■●
●■●
■●
■●
■●
■●
■●
■■
●■
●■
●■
●■
●■
●■
●■■◆
●●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■
●◆
■
●◆
■
●◆
■
●◆
■
●◆
■
●◆
■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■
●◆
■
●◆
■
●◆
■
●◆
■
●◆
■
●◆
■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●■◆
●●▲
▲
■◆
◆
■
●▲
◆
■
■
●
●▲
◆
■
●▲
▲
◆
◆
■
●▲
◆
■
■
●
●▲
◆
■
●▲
◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
▲
■◆
◆
■
●▲
◆
■
■
●
●▲
◆
■
●▲
▲
◆
◆
■
●▲
◆
■
■
●
●▲
◆
■
●▲
▲
◆
◆
■
●▲
◆
■
■
●
●▲
◆
■
●▲
◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
■◆
●▲
▲
■◆
◆
■
●▲
◆
■
■
●
●▲
◆
●▲
■◆
●▲
■◆
●▲
■◆▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
■◆
● ▲
▲
■◆
●◆
■
●▲
◆
■
■
●
●▲
◆▲
■◆
● ▲
■◆
●■
●
Figure 20: PMFs for Trial Number of 10th Success in Bernoulli Trials
To see shapes
Need to standardize as with Binomial and Hypergeometric pictures. Scale
X −µ
to rv Z = and scale the pmf of this so the area under the curve is 1.
σ
Figures 23, 24 and 25 show the shapes by displaying the scaled pmf for Z.
Conclusion
For p=0.1 and p=0.5, as r gets larger see same shape as for Binomial and
Hypergeometric
For p=0.9, the successes come more quickly and the shape is not so clear
35
p=0.9 p=0.7 p=0.5
pmf(k)
0.15
0.10
0.05
k
60 80 100 120
Figure 21: PMFs for Trial Number of 50th Success in Bernoulli Trials, High
Probs
p=0.2 p=0.1
pmf(k)
0.012
0.010
0.008
0.006
0.004
0.002
k
300 400 500 600 700
Figure 22: PMFs for Trial Number of 50th Success in Bernoulli Trials, Low
Probs
36
n=10 n=50 n=100
scaled pmf(z)
0.4
0.3
0.2
0.1
z
-3 -2 -1 1 2 3
0.3
0.2
0.1
z
-3 -2 -1 1 2 3
37
n=10 n=50 n=100
scaled pmf(z)
0.4
0.3
0.2
0.1
z
-3 -2 -1 1 2 3
Trial number of rth success is the sum of the times between the first r > 1
successes:
Tr = T1 + (T2 − T1 ) + · · · + (Tr − Tr−1 ) (33)
38
And the random variables in the sum are independent and each distributed as
the Geometric(p) distribution
Because building on the case r = 2 by induction, for i, j ≥ 1, letting q = 1 − p
and using independence of the Bernoulli trials,
P (T1 = i ∩ T2 − T1 = j) = P (T1 = i)P (T2 − T1 = j|T1 = i)
= P ((i − 1)F S)P ((j − 1)F S|(i − 1)F S)
= q i−1 pq j−1 p
= P (T1 = i)P (T1 = j)
General case follows from the fact that the random variables in (33) are inde-
pendent so:
r
E(Tr ) = rE(T1 ) =
p
r(1 − p)
V ar(Tr ) = rV ar(T1 ) = (37)
p2
39
Mathematica and R
Both use Tr −r, the number of failures before the rth success, rather than Tr
- affects values of times and means, but not variances and standard deviations,
since for any constant a and rv X with mean µX :
V ar(X + a) = E (X + a − µX+a )2
= E (X + a − (µX + a))2
= V ar(X) (38)
3. What is the mean and standard deviation of the time in years to the
(a) first
(b) fourth
accident?
2. the chance that the 4th accident occurs than 10 years from now is
40
Solution - Accidents in a Workplace Ctd
3. the mean and standard deviation of the time in years, by linearity prop-
erties of expectation, the mean and standard deviation divided by 12.
Hence
(a) the mean and standard deviation of the time
√ in years to√ the first
1 2 V ar(T1 ) 1−0.05
accident is E(T1 )/12 = 12×0.05 = 1 3 and 12 = 12×0.05 =
1.62447
(b) the mean and standard deviation of the time
√ in years√to the fourth
4 2 V ar(T4 ) 4×(1−0.05)
accident is E(T4 )/12 = 12×0.05 = 6 3 and 12 = 12×0.05 =
3.24893
If accidents were reviewed on a daily basis, the mean number of accidents per
day might be expected to be about 1/30 of the mean number in a month ie
0.05/30
If X is the number of accidents in a time period subdivided into n parts with
p the probability of an accident in each one of the parts, then for any A ⊆
{0, 1, 2, · · · }
X (np)i X n X (np)i
P (X ∈ A) − e−np = pi (1 − p)n−i − e−np
i! i i!
i∈A i∈A i∈A
<p (39)
e−λ λi
.
i!
41
● Poisson ■ Binomial
pmf(k) n =10
0.6●
■
p =5. × 10-2
D =1.18 × 10-2
0.5
0.4
0.3
■
●
0.2
0.1 ●
■
●
■
●
■
k
1 2 3 4
So the Poisson probabilities add to one: for any λ > 0 the sum of the Poisson
probabilities is:
∞ ∞
X e−λ λi X λi
= e−λ = e−λ eλ = 1 (41)
i=0
i! i=0
i!
Poisson pmf, f (i), i =, 1, 2, · · · with parameter λ > 0 is defined as the ith entry
of the series
42
● Poisson ■ Binomial
pmf(k) n =100
■
●
■
●
p =5. × 10-2
D =1.26 × 10-2
0.15 ●
■
●
■
■
0.10
●
●
■
●
■
0.05
● ●
■
■
●
■
●
■ ●
■
●
■ ●
■ ●
■ ●
■ ●
■
k
5 10 15
● Poisson ■ Binomial
pmf(k) n =250
■
●
p =5. × 10-2
■ ■
● ●
D =1.26 × 10-2
0.10 ■
●
■
●
0.08 ●
■
■
●
■
0.06
●
●
■
●
■
0.04 ●
■ ●
■
0.02 ●
■
●
■
●
■
●
■ ●
■
● ●
■
k
■ ●
■
●
■ ●
■ ●
■ ●
■ ●
■ ●
■ ●
■ ●
■ ●
■ ●
■ ●
■
5 10 15 20 25 30
43
If X has a Poisson pmf with parameter λ, then
M (t) = E(etX )
∞
X e−λ λi
= eti
i=0
i!
∞
X (et λ)i
= e−λ
i=0
i!
t t
= e−λ eλe = eλ(e −1)
(42)
So
t
E(X) = M 0 (0) = λet eλ(e −1) (0) = λ
Variance of Poisson
So
V ar(X) = M 00 (0) − λ2 = λ
Poisson Process
44
Cumulative Number of Events versus Time
5
4
Number of Events
3
2
1
0
1 2 3 4
Time of Event
Figure 29: Assumptions require that the jumps are all size one
45
Negative Binomial probabilities of 0.54036 and 0.131707 are very close, since
both are based on the Binomial and Poisson probabilities
which are close
Mean and variance for the number of events in a year are both the rate 0.62
Mean for the Binomial(12,0.05) distribution is 0.6, close to 0.62
Can match Binomial to Poisson by the mean or the probability of zero - see Lab
this week
46