Chapter 7 Binomial Deviates


MPD78
10-06-2009, 08:53 AM
Hello all,

In Jay L. Devore's book "Probability and Statistics for Engineering and the Sciences" 3rd Edition, there is a set of tables for the cumulative binomial probabilites and numerous other probabilities.

Can the Binomialdev::dev() function be used to recreate the cumulative binomial probabilities table?

For example,

(This is a paraphrased version of Example 3.31 on page 108 of Devore's book.)

20% of all copies of a textbook fail a binding strength test. There are 15 randomly selected copies that fail. X has a binomial distribution with n=15 and p=0.2.

Find the probability that at most 8 fail.

Soution

From the tables with x = 8, n=15, and p=0.2 the probability is 0.999.

Here is my attempt.

#include "ran.h"

Int pause; // Dummy variable to keep the output screen visible
Int myans; // binomial deviates answer

int main()
{
Binomialdev mybinomial(15,0.2,8);
myans = mybinomial.dev();
cout << myans << endl;

cin >> pause;

return 0;
}


Obviously, I have something incorrect because the return type of dev() is an Int when I am looking for a Doub return type. Correct?

Also, the returned answer is 7 not 0.999.

I think I am off in space cadet camp ...

Any help would be appreciated.

Thanks
Matt

davekw7x
10-06-2009, 11:22 AM
...
Can the Binomialdev::dev() function be used to recreate the cumulative binomial probabilities table?...

Not by calling the dev() function one time as you did in your program. See Footnote.

The member function dev() is designed return one sample from a binomial-distribution population having parameters n and p.

So, how can we use Binomialdev to learn something about the stated problem?

Given that the probability of failure is 0.2, for a run of 15 books, we want to estimate the probability that the number of failures is less than or equal to 8.

Here is one approach:

Get a large number of samples from a population that has binomial distribution with n = 15 and p = 0.2


Count the number of samples whose value is less than or equal to 8.


Divide that number by the total number of samples. That would be an estimate of the probability that the number of failures in a 15-book sample is less than or equal to eight (i.e. not greater than eight)


For example:

#include "../code/nr3.h"
#include "../code/ran.h"
#include "../code/gamma.h"
#include "../code/deviates.h"
int main()
{
Int myans;
Ullong seed = time(0);

Ullong leq = 0; // The number of sample values less than or equal to cutoff
Ullong num_samples = 1000000;

Int n = 15;
Doub p = 0.2;
Int cutoff = 8;

Binomialdev mybinomial(n, p, seed);

for (Ullong i = 0; i < num_samples; i++) {
myans = mybinomial.dev();
if (myans <= cutoff) {
++leq;
}
}
cout << "For " << num_samples << " samples from Binomialdev"
<< ", with n = " << n << ", and p = " << p << "," << endl
<< "the number of samples with value less than or equal to " << cutoff
<< " is " << leq << endl << endl
<< "I estimate that the probability that the number of failures is" << endl
<< "less than or equal to " << cutoff
<< " is " << Doub(leq)/Doub(num_samples) << endl;

return 0;
}



Output

For 1000000 samples from Binomialdev, with n = 15, and p = 0.2,
the number of samples with value less than or equal to 8 is 999281

I estimate that the probability that the number of failures is
less than or equal to 8 is 0.999281


Regards,

Dave

Footnote: If you want to reproduce the table, you don't have to estimate the probabilities. You can use the pdf of the binomial distribution to calculate the values directly:
\Pr (X \leq k) = \sum_{i=0}^{k}{{n}\choose{i}} p^i (1-p)^{n-i}

I get something like 0.999215014608897 for n = 15, k = 8, p = 0.2

However if you want to see how Binomialdev works, you can use the example program.

MPD78
10-06-2009, 12:36 PM
Dave,

Thanks for the help. Now I have a much clearer (but still slightly blurry) vision of how these routines work.

I don't work in the field of statistics, but I do find it very interesting, so I figure I will learn these routines as best as I can. I like using these simple problems from Devore's book, they make grasping this subject much easier.

Thanks
Matt