pwrball is based on a program in the lottery-0.2.0 package. It is used in the datagen package to illustrate the chi-square test.
pwrball contains the following programs:
Lottery | Program | Description |
---|---|---|
Powerball | combo.c | Subroutine to Calculate Combinations |
getpb.c | Subroutine to Calculate Probability | |
pwrball.c | Plays the lottery |
By reading the source code in getpb.c, you can learn how to calculate the probability of each prize in the lottery. combo.c contains the textbook definition of the combination function C(n,r). The logic in getpb.c is based on the Chao reference, below.
pwrball allows you to play the lottery to see how often you win each prize. This program has one parameter, the number of times you want the program to play the lottery. For example,
pwrball 100000
In this example, the program plays the lottery 100 thousand times and then prints the totals and the chi-square test for the run.
Normally, you buy a lottery ticket, and then wait for the drawing to see if you win. In this program, you first create the drawing, and then buy 100 thousand tickets to see if you "would have" won the lottery, had you chosen the right numbers. In a program, you can do this and still maintain your integrity, because the program is not conscious of the winning numbers when it computes the 100 thousand trials.
By playing the lottery with pwrball, you can see how many times you have to play just to break even. Even if you win 10 thousand dollars in one test, you may lose 90 thousand dollars in the next test. By purchasing 100 thousand tickets, over and over again, you lose 90 thousand dollars each time you play, most of the time.
Notice the last line 0 0 before the total line. This line shows you how often you do not win any prize, at all. It is roughly 97 percent of the time.
Notice that you lost roughly 90 thousand dollars in this test.
The first line of the test is the drawing. The powerball is the last number on the right, after the dash.
The first column is Matches. This tells you which prize you won. The number on the left is the number of balls that you matched, but not the powerball. The number on the right tells you wether you matched the powerball.
The Wins column tells you how many times out of 100 thousand tickets that you won each prize.
The Prize column tells you how much money you won for each prize.
The Expected column tells you how many times you are expected to win each prize, considering the number of tickets that you "bought".
The Odds column tells you the probability for winning each prize.
The Total Wins tells you how many tickets you purchased.
The Total Prize tells you how much money you won, overall.
The Total Cost is simply one dollar times the number of tickets. If the price changes, this calculation will change in a new version of the program.
The Net Income is usually negative. It tells you how many dollars you won, minus the number of dollars that you spent.
The Chi-square number should fit within the Range 95 percent of the time.
The calculation of probabilities for each lottery prize is based on an example in the following book:
Lincoln L. Chao
Statistics for Management
2nd Edition
Palo Alto: The Scientific Press, 1984
Chapter 4, Events and Probabilities
Section 3, Computing Probability
Example 4-13, Part 2
Lincoln L. Chao published his book while at California State University, Long Beach.
The chi-square test is similar to:
Chapter 12, Chi-square Tests
Section 3, Testing for Goodness of Fit
Formula 12-3
Example 12-4
In Table 12-3, each category in the chi-square test has a different expected frequency. This corresponds to the different expected frequencies for each prize in the lottery.
In the lottery, there are 10 categories for the chi-square test. The 95 percent range for the chi-square test is based on 9 degrees of freedom.