Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does pgeom n parameter value need to be one less than I expected?

Tags:

r

There is an example question in the book Head First Statistics:

20% of cereal packets contain a free toy. What’s the probability you’ll need to open fewer than 4 cereal packets before finding your first toy?

The worked solution is given as:

P(X ≤ 3) 
= 1 - q^r
= 1 - 0.8^3
= 1 - 0.512 
= 0.488

I would have expected to use the following R statement:

> pgeom(3, 0.2)
[1] 0.5904

But as you can see the answer isn't as expected. The correct value for the n parameter is 2 as can be seen below:

> pgeom(2, 0.2)
[1] 0.488

Can someone explain why this is the case and where I am thinking about this incorrectly?

like image 648
Chris Snow Avatar asked Dec 25 '22 06:12

Chris Snow


1 Answers

I just ran into this. My text book and pgeom use different density functions. From the documentation, pgeom uses p(x) = p*(1-p)^x, my book uses p(x) = p*(1-p)^(x-1). Presumably Head First uses the latter formula too.

like image 190
Geoff Breemer Avatar answered Dec 26 '22 21:12

Geoff Breemer