Introduction to the Negative Binomial Distribution Negative Binomial Distribution in R Relationship with Geometric distribution MGF, Expected Value and Variance Relationship with other distributions Thanks! Negative Binomial Distribution Andre Archer, Ayoub Belemlih, Peace Madimutsa Macalester College November 30, 2016 1/??
71
Embed
Negative Binomial Distribution · 2016. 12. 2. · Negative Binomial Distribution in R Relationship with Geometric distribution MGF, Expected Value and Variance Relationship with
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Negative Binomial Distribution
Andre Archer, Ayoub Belemlih, Peace MadimutsaMacalester College
November 30, 2016
1/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Outline1 Introduction to the Negative Binomial Distribution
Defining the Negative Binomial DistributionExample 1Example 2: The Banach Match ProblemTransformation of PdfWhy so Negative?CDF of X
2 Negative Binomial Distribution in RR CodeExample 3
3 Relationship with Geometric distribution4 MGF, Expected Value and Variance
Moment Generating FunctionExpected Value and Variance
5 Relationship with other distributionsPossion Distribution
6 Thanks!2/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Introduction to the Negative Binomial Distribution
Introduction to the NegativeBinomial Distribution
3/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Defining the Negative Binomial Distribution
X ∼ NB(r , p)
Given a sequence of r Bernoulli trials with probability of success p,X follows a negative binomial distribution if X = k is the numberof trials needed to get to the rth success.
Pdf of X
P(X = k) =
(k − 1
r − 1
)pr (1− p)k−r
where X = r , r + 1, · · ·
4/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Defining the Negative Binomial Distribution
Pdf of X
P(X = k) =
(k − 1
r − 1
)pr (1− p)k−r
where X = r , r + 1, · · ·
P(X = k) = P(rth on kth trial)
5/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Defining the Negative Binomial Distribution
Pdf of X
P(X = k) =
(k − 1
r − 1
)pr (1− p)k−r
where X = r , r + 1, · · ·
P(X = k) = P(rth on kth trial)
= P(r-1th on k-1 trials) · P(success on kth trial)
6/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Defining the Negative Binomial Distribution
Pdf of X
P(X = k) =
(k − 1
r − 1
)pr (1− p)k−r
where X = r , r + 1, · · ·
P(X = k) = P(rth on kth trial)
= P(r-1th on k-1 trials) · P(success on kth trial)
=
(k − 1
r − 1
)pr−1(1− p)k−1−(r−1) · p
7/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Defining the Negative Binomial Distribution
Pdf of X
P(X = k) =
(k − 1
r − 1
)pr (1− p)k−r
where X = r , r + 1, · · ·
P(X = k) = P(rth on kth trial)
= P(r-1th on k-1 trials) · P(success on kth trial)
=
(k − 1
r − 1
)pr−1(1− p)k−1−(r−1) · p
=
(k − 1
r − 1
)pr−1(1− p)k−r · p
8/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Defining the Negative Binomial Distribution
Pdf of X
P(X = k) =
(k − 1
r − 1
)pr (1− p)k−r
where X = r , r + 1, · · ·
P(X = k) = P(rth on kth trial)
= P(r-1th on k-1 trials) · P(success on kth trial)
=
(k − 1
r − 1
)pr−1(1− p)k−1−(r−1) · p
=
(k − 1
r − 1
)pr−1(1− p)k−r · p
=
(k − 1
r − 1
)pr (1− p)k−r
9/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Example 1
A door-to-door encyclopediasalesperson is required to doc-ument five in-home visits eachday. Suppose that she has a 30%chance of being invited into anygiven home, with each addressrepresenting an independent trial.What is the probability that sherequires fewer than eight housesto achieve her fifth success? (pg.269)
10/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Example 2: The Banach Match Problem
Suppose that an absent-mindedprofessor (is there any otherkind?) has m matches in his rightpocket and m matches in his leftpocket. When he needs a matchto light his pipe, he is equallylikely to choose a match from ei-ther pocket. We want to computethe probability density function ofthe random variable W that givesthe number of matches remainingwhen the professor first discoversthat one of the pockets is empty.- math.utah.edu Steven Banach
1892 - 1945
11/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Transformation of Pdf
Pdf of X
We can also express the pdf in terms a discrete rv, Y = thenumber of failures.
P(Y = k) =
(k + r − 1
k
)pr (1− p)k
where Y = 0, 1, · · ·
12/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Transformation of Pdf
P(X = x) =
(x − 1
r − 1
)pr (1− p)x−r
13/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Transformation of Pdf
P(X = x) =
(x − 1
r − 1
)pr (1− p)x−r
Let x = r + y
P(X = r + y) =
(y + r − 1
r − 1
)pr (1− p)y+r−r
14/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Transformation of Pdf
P(X = x) =
(x − 1
r − 1
)pr (1− p)x−r
Let x = r + y
P(X = r + y) =
(y + r − 1
r − 1
)pr (1− p)y+r−r
P(X − r = y) =
(y + r − 1
r − 1
)pr (1− p)y
15/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Transformation of Pdf
P(X = x) =
(x − 1
r − 1
)pr (1− p)x−r
Let x = r + y
P(X = r + y) =
(y + r − 1
r − 1
)pr (1− p)y+r−r
P(X − r = y) =
(y + r − 1
r − 1
)pr (1− p)y
P(Y = y) =
(y + r − 1
r − 1
)pr (1− p)y
16/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Transformation of Pdf
P(X = x) =
(x − 1
r − 1
)pr (1− p)x−r
Let x = r + y
P(X = r + y) =
(y + r − 1
r − 1
)pr (1− p)y+r−r
P(X − r = y) =
(y + r − 1
r − 1
)pr (1− p)y
P(Y = y) =
(y + r − 1
r − 1
)pr (1− p)y
We can use(y+r−1
r−1)
=(y+r−1
y
).
17/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Transformation of Pdf
P(X = x) =
(x − 1
r − 1
)pr (1− p)x−r
Let x = r + y
P(X = r + y) =
(y + r − 1
r − 1
)pr (1− p)y+r−r
P(X − r = y) =
(y + r − 1
r − 1
)pr (1− p)y
P(Y = y) =
(y + r − 1
r − 1
)pr (1− p)y
Since(y+r−1
r−1)
=(y+r−1
y
),
P(Y = y) =
(y + r − 1
y
)pr (1− p)y
18/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Why so Negative?
Pdf of Y
P(Y = k) =
(k + r − 1
k
)pr (1− p)k
where Y = 1, 2, · · ·
The binomial coefficient in the pdf may be rearranged as follows:(k + r − 1
k
)=
(k + r − 1) · (k + r − 2) · · · rk!
= (−1)k(−r − (k − 1)) · (r − (k − 2)) · · · (−r)
k!
= (−1)k(−r) · · · (r − (k − 2)) · (−r − (k − 1))
k!
= (−1)k(−rk
)19/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
CDF of X
Cdf of X
F (X ≤ k) =k∑
j=r
(j − 1
r − 1
)pr (1− p)j−r
20/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Negative Binomial Distribution in R
Negative Binomial Distributionin R
21/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
R Code
Probability Density of NB(r=size,p=prob)
1 dnbinom ( x , s i z e , prob , mu, l o g = FALSE)
22/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
R Code
Probability Density of NB(r=size,p=prob)
1 dnbinom ( x , s i z e , prob , mu, l o g = FALSE)
Using Example 1,
1 dnbinom (7−5 , s i z e =5, prob =0.3)2 ## [ 1 ] 0 .017860534 dnbinom (5−5 , s i z e =5, prob =0.3) + dnbinom (6−5 , s i z e =5,
prob =0.3) + dnbinom (7−5 , s i z e =5, prob =0.3)5 ## [ 1 ] 0 .0287955
23/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
R Code
Cumulative Density of NB(r=size,p=prob)
1 pnbinom ( q , s i z e , prob , mu, l o w e r . t a i l = TRUE, l o g . p =FALSE)
24/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
R Code
Cumulative Density of NB(r=size,p=prob)
1 pnbinom ( q , s i z e , prob , mu, l o w e r . t a i l = TRUE, l o g . p =FALSE)
Using Example 1,
1 dpnbinom ( 2 , s i z e =5, prob =0.3)2 ## [ 1 ] 0 .0287955
25/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Example 3
Darryl statistics homework lastnight was to flip a fair coin andrecord the toss, X, when headsappeared for the second time.The experiment was to berepeated a total of one hundredtimes. The following are the onehundred values for X that Darrylturned in this morning. Do youthink that he actually did theassignment? Explain. (pg. 269)
26/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Example 3
1 #Second Example2 k <− 2 : 1 03 p r o b a b i l i t i e s <− c ( )4 f o r ( i i n k ) {5 p r o b a b i l i t i e s <− c ( p r o b a b i l i t i e s , dnbinom ( i −2, s i z e =2,
prob =0.5) )6 }7 e x p e c t e d v a l u e s <− c ( )8 f o r ( j i n p r o b a b i l i t i e s ) {9 e x p e c t e d v a l u e s <− c ( e x p e c t e d v a l u e s , round (100 ∗ j ,
d i g i t s =0) )10 }11 o b s e r v e d v a l u e s <−c ( 2 4 , 2 6 , 1 9 , 1 3 , 8 , 5 , 3 , 1 , 1 )1213 t b l <− data . f rame ( k , p r o b a b i l i t i e s , o b s e r v e d v a l u e s ,
e x p e c t e d v a l u e s )14 t b l
27/??
Introduction to theNegative BinomialDistribution
Negative BinomialDistribution in R
Relationship withGeometric distribution
MGF, Expected Valueand Variance
Relationship with otherdistributions
Thanks!
Example 3
1 > t b l2 ## k p r o b a b i l i t i e s o b s e r v e d v a l u e s e x p e c t e d v a l u e s3 ## 1 2 0.250000000 24 254 ## 2 3 0.250000000 26 255 ## 3 4 0.187500000 19 196 ## 4 5 0.125000000 13 127 ## 5 6 0.078125000 8 88 ## 6 7 0.046875000 5 59 ## 7 8 0.027343750 3 3