The "MA206" HP-48G Series program was written at some time during or preceding the 1998-1999 academic year to consolidate the various HP-48G Series programs in use supporting MA206. The individual sub-programs were written by a number of different authors; Major Jim Gigrich wrote the menu driven program documented here, which consolidated the existing programs.
This article describes that program. It was written as an aid to understanding the structure and usage of the program, from the perspective that one must understand a program in order to be able to use it. As a result, this article may be read in either of two ways. It can be read by looking at the description of the program structure, to understand the program itself, followed by examining the usage. Or it can be read to understand what needs to be done and how to do it (the usage), followed by a study of how the program is written to accomplish it.
This article was written with the MA206 instructor as the target audience. In addition to providing information of general interest to any user of the MA206 calculator program, this article makes a number of comments about programming choices embodied in the program, and discusses possible changes and extensions to the program. While there is nothing included here which students should not be allowed to see, much of this additional discussion is somewhat beyond the needs of the average student and may tend to confuse rather than clarify. This additional material is primarily aimed at providing a deeper understanding of the program with a view towards allowing instructors (including the author) to understand the program, diagnose student difficulties with the program, and (potentially) modify or extend the program.
However, this article is not beyond the student who expresses an interest in the techniques of programming the HP-48G Series, and could be profitably shared with such students.
The MA206 program provides a single HP-48G Series program which automates many of the calculations required in the Probability and Statistics course. In particular, the MA206 program permits the user to calculate:
Binomial interval probabilities. Calculate the probability that a random variable following a binomial distribution lies in a user specified interval.
Poisson interval probabilities. Calculate the probability that a Poisson distributed random variable lies in a user supplied interval.
Hypergeometric interval probabilities. Calculate the probability that a random variable from a hypergeometric distribution lies in a user supplied interval.
Uniform interval probabilities.
Exponential interval probabilities.
Lower tail Normal probabilities.
Upper tail Normal probabilities and critical values.
Upper tail Student's T probabilities and critical values.
Upper tail Chi-Squared probabilities and critical values.
Clean up stored intermediate variables.
The three functions which compute upper tail probabilities and critical values use the HP-48G Series SOLVE application, with the result that any of the parameters of the distribution, the critical value, and the upper tail probability can be computed if the remaining values are known.
The MA206 program is invoked by pressing the user menu key corresponding to the screen label MA206. This label will be visible when the current directory is set to the directory in which the MA206 program is installed, and user variables are selected. If user variables are not visible, pressing the VAR key will cause them to be visible.
After the MA206 key is pressed, a user selection box labeled MA206 PROGRAMS will appear, showing the first four functions. To scroll to the other functions, use the cursor arrow keys. Note that when the top of the list is visible, a "down arrow" will appear in the lower right of the box, indicating that there are more selections available below those visible. When the middle of the list is displayed, arrows will appear in both the bottom and top of the dialog box.
Even when the top or bottom of the list is displayed, you can scroll in both directions. If you scroll up off of the list, the selection moves to the bottom of the list and vice versa. This can be convenient if you know that the desired item is near the bottom of the list.
Once the desired item is highlighted, select ENTER.
This option calculates the probability that a random variable following a binomial distribution lies in a user specified interval.
When the Binomial option is selected, the screen will display a data entry form labeled BINOMIAL DIST. X~BIN(N,P), with spaces for the distribution's parameters and the endpoints of the desired interval.
The four values to be entered are:
The number of binomial trials. By the definition of the binomial distribution, this must be a positive integer.
The probability of success on each trial. By the definition of the binomial distribution this must be a probability.
The lower limit of the desired interval. This value is included in the interval. This number should be a non-negative integer, less than or equal to X2, and less than or equal to N.
The upper limit of the desired interval. This value should be a non-negative integer, greater than or equal to X1 and less than or equal to N.
Once you have filled in the values appropriate to your problem, select OK and the probability will be calculated. The probability distribution, including its parameter values is displayed on stack level 3. The probability statement (including the selected interval) is shown on stack level 2, and the probability itself is shown on stack level 1.
If you enter values in the variables which do not satisfy the conditions described above, the results are not easily predictable, and will in any case be unlikely to have any practical value.
This option allows you to calculate the probability that a Poisson distributed random variable lies in an interval you supply.
When the Poisson option is selected, the screen will display a data entry form labeled POISSON DIST. X~P(λ), λ>0, with spaces for the distribution's parameters and the (inclusive) end points of the interval. The three variables are:
The rate parameter of the Poisson distribution. By definition, this must be greater than zero.
The lower limit of the desired interval. This value is included in the interval. This number should be a non-negative integer, less than or equal to X2.
The upper limit of the desired interval. This value should be a non-negative integer, greater than or equal to X1.
Once you have filled in the values appropriate to your problem, select OK and the probability will be calculated. The probability distribution, with its parameter value, and the interval selected are displayed for your reference on levels 3 and 2 of the stack, and the probability it redisplayed on level 1 for use in further calculations.
If you enter values in the variables which do not satisfy the conditions described above, the results are not easily predictable, and will in any case be unlikely to have any practical value.
This option allows you to calculate the probability that a raandom variable from a hypergeometric distribution falls in an interval you define.
This sub-program was originally written by Major Dennis Day.
After you select the Hypergeometric option, a user input form labeled HYPERGEOMETRIC DIST. will appear. This form has spaces for the distribution's parameters and the endpoints of the desired interval:
The number of possible successes of the hypergeometric distribution. By definition, this must be a non-negative integer.
The population size. By definition, this must be a non-negative integer, greater than or equal to "Small 'N'".
The number of items drawn. By definition, this must be a non-negative integer, less than or equal to N.
The lower limit of the desired interval. This value is included in the interval. This number should be a non-negative integer, less than or equal to X2, and less than or equal to n.
The upper limit of the desired interval. This value should be a non-negative integer, greater than or equal to X1.
Once you have filled in the values appropriate to your problem, select OK and the probability will be calculated. The probability distribution, including its parameter values is displayed on stack level 3. The probability statement (including the selected interval) is shown on stack level 2, and the probability itself is shown on stack level 1.
If you enter values in the variables which do not satisfy the conditions described above, the results are not easily predictable, and will in any case be unlikely to have any practical value.
The MA206 option allows you to compute the probability that a random variable uniformly distributed on a defined interval lies in an interval you supply.
After the Uniform option is selected, a user input form labeled UNIFORM DIST. X~UNF(A,B). The input form has spaces for the distribution's parameters and the endpoints of the interval:
The lower limit of the interval on which the uniform distribution has non-zero probability. A may be any real number less than B.
The upper limit of the interval on which the uniform distribution has non-zero probability. B may be any real number greater than A.
The lower limit of the desired interval. This value is included in the interval. This number should be greater than or equal to A and less than both X2 and B.
The upper limit of the desired interval. This value should be greater than or equal to X1 and less than B.
Once you have filled in the values appropriate to your problem, select OK and the probability will be calculated. The probability distribution, including its parameter values is displayed on stack level 3. The probability statement (including the selected interval) is shown on stack level 2, and the probability itself is shown on stack level 1.
If you enter values in the variables which do not satisfy the conditions described above, the results are not easily predictable, and will in any case be unlikely to have any practical value.
In particular, you should be cautious about the relationships between the interval [A, B] and the interval [X1, X2]. If X1 and X2 are not contained in [A, B], the returned probability will be numerically incorrect, although the program will appear to have returned correctly.
This option allows you to compute the proabability that an exponentially distributed random variable lies in an interval you supply.
After the Exponential option is selected, a user input form labeled EXPONENTIAL DIST. X~EXP(λ). The input form has spaces for the distribution's parameters and the endpoints of the interval:
The rate parameter of the exponential distribution. λ should be a non-negative real number.
The lower limit of the desired interval. This value is included in the interval. This number should be greater than or equal to zero.
The upper limit of the desired interval. This value should be greater than or equal to X1.
Once you have filled in the values appropriate to your problem, select OK and the probability will be calculated. The probability distribution, including its parameter values is displayed on stack level 3. The probability statement (including the selected interval) is shown on stack level 2, and the probability itself is shown on stack level 1.
If you enter values in the variables which do not satisfy the conditions described above, the results are not easily predictable, and will in any case be unlikely to have any practical value.
The Normal optional allows you to evaluate the CDF of the Normal distribution, effectively replacing the standard Normal tables.
Once you select the Normal option, a window will appear reminding you that this is the NORMAL DISTRIBUTION P(X≤x). Press the ENTER key and the user input form will appear.
This input form allows you to set the parameters of the distribution and the value of the random variable at which you want to evaluate the CDF.
The value at which you want to evaluate the CDF.
The mean of the Normal distribution.
The standard deviation of the Normal distribution.
Once you have filled in the values appropriate to your problem, select OK and the probability will be calculated. The probability distribution, including its parameter values is displayed on stack level 3. The probability statement (including the selected interval) is shown on stack level 2, and the probability itself is shown on stack level 1.
The SOLVE application is one of the standard HP-48G Series applications. It allows the user to specify the values of all but one of the variables in an equation or expression, and solve for the remaining unknown value. (In the case of an expression, the root of the expressions is found.)
The next three of the MA206 functions use the SOLVE to let you find values associated with the upper tail probabilities of the Normal, Student's T, and Chi-Squared distributions.
Use the cursor keys to move the highlight to each known variable in turn, enter the value, and then press ENTER. The highlight will jump to the next variable; if this is not the one you want, you can again use the cursor keys to move. Once all known values are entered, more the highlight to the unknown value and press OK. After it is done calculating, the HP-48G Series will fill in the value for the unknown variable. If you then press ENTER, you will be returned to the normal stack view, with the value on level 1.
Figure 1 [TBR] shows the cursor in the first variable position, ready to enter the upper tail probability.
For additional information on using the SOLVE application, see the [HP 48 User's Guide].
The top level structure of the program is a CHOOSE box which allows the user to select among the various functions used in MA206.
1 << 2 " MA206 PROGRAMs" 3 { { "Binomial" 1} 4 { "Poisson" 2} 5 { "Hypergeometric" 3} 6 { "Uniform" 4} 7 { "Exponential" 5 } 8 { "Normal" 6 } 9 { "Normal Find" 7 } 10 { "T-Distribution" 8 } 11 { "Chi-Squared" 9 } 12 { "Clear Garbage" 10 } } 13 1 CHOOSE DROP -> c |
The remainder of the program is a CASE statement which executes the various options.
The first choice is the binomial distribution, structured as an INFORM block to solicit the user's input, followed by a loop which calculates the binomial distribution. Finally the variables used in the calculation are PURGEed.
There is no error checking on the user input parameters, either for the distribution or for the interval.
1 << 2 CASE 'c==1' 3 THEN 4 "BINOMIAL DIST. X~BIN(n,p)" 5 { { } { } 6 { "n:" "Enter Number of trials" 0 } 7 { "p:" "Enter Probability" 0 } 8 { } { } 9 { "X1:" "Input Lower Limit" 0 } 10 { "X2" "Input Upper Limit" 0 } 11 } { 2 } { } { } 12 INFORM DROP OBJ-> 13 DROP 14 'X2' STO 15 'X1' STO 16 'p' STO 17 'n' STO 18 "X~Binomial(" 19 n ->STR + "," + p ->STR + ")" 20 + '[sum](X=X1,X2,COMB(n,X)*p^X*(1-p)^(n-X))' 21 ->NUM 'ANS' STO 22 ANS 4 RND 23 ->STR 24 "P(" X1 ->STR + "≤X≤" + X2 ->STR + ")=" 25 + SWAP + ANS 26 'X1' PURGE 27 'X2' PURGE 28 'n' PURGE 29 'p' PURGE 30 'ANS' PURGE 31 END |
This section computes the probability that a Poisson distributed random variable lies in a user-specified interval.
The second section deals with the Poisson distribution. As with the binomial distribution, the basic calculation is a loop over the integers contained in the user supplied interval. We get the user inputs via an INFORM box, and after the computations are complete we PURGE the variables we use.
There is no error checking to establish that the endpoints of the interval are non-negative, which is required by the definition of the Poisson distribution.
1 'c==2' THEN 2 "POISSON DIST. X~P(λ), λ>0" 3 { { } { } 4 { "λ:" "input the rate: λ >0" 0 } 5 { } { } { } 6 { "x1:" "input lower Limit" 0 } 7 { "X2:" "Input upper Limit" 0 } 8 } { 2 } { } { } 9 INFORM DROP OBJ-> DROP 'X2' STO 10 'X1' STO 11 'λ' STO 12 "X~POISSON(λ=" λ ->STR + ")" + 13 '[sum](X= X1,X2,EXP(-λ)*λ^X/X!)' 14 ->NUM 'ANS' STO 15 ANS 4 RND ->STR 16 "P(" X1 ->STR + "≤X≤" + X2 ->STR + ")=" + 17 SWAP + ANS 18 'X1' PURGE 19 X2' PURGE 20 'λ' PURGE 21 'ANS' PURGE 22 END |
The hypergeometric distribution follows the pattern of the other discrete distributions. We get the user's input via an INFORM box, loop over the relevant integers, and then PURGE the variables used.
There is no error checking on the parameters of the distribution or on the interval over which the probability is requested.
1 'c==3' THEN
2 "HYPERGEOMETRIC DIST."
3 { { "M:" "number of possible successes" 0 }
4 { "N:" "population size" 0 }
5 { "Small 'n':" "total number of items drawn" 0 }Notice
that despite the used of the lower case "n" here, it will appear
uppercased in the INFORM box, as do all letters.
6 { } { } { }
7 { "X1:" "LOWER # of desired successes" 0}
8 { "X2:" "UPPER # of desired successes" 0} }
9 { 2 } { } { }
10 INFORM DROP OBJ-> DROP
11 'X2' STO
12 'X1' STO
13 'n' STO
14 'N' STO
15 'M' STO
16 "X~Hyp(x:" n ->STR +
17 "," + M ->,STR + "," +
18 N ->STR + ")" +
19 '[sum](X=X1,X2, COMB(M,X) *COMB(N-M,n-X)/COMB(N,n))'
20 ->NUM 'ANS' STO ANS 4 RND ->STR "P(" X1 ->STR + "≤X≤" + X2 ->STR + ")=" + SWAP + ANS
21 'ANS' PURGE
22 'X1' PURGE
23 'X2' PURGE
24 'n' PURGE
25 'M' PURGE
26 'N' PURGE
27 END |
This section computes the probability that a uniformly distributed random variable lies in a specific interval.
The uniform distribution is the first of the continuous distributions dealt with in this program. The structure of the program is similar to the preceding discrete sections, except that in the computation section we are able to compute the desired interval probability directly in a single expression.
There appears to be no error checking to ensure that the interval over which the probability is desired is contained in the interval over which the probability is non-zero, although the computational formula employed assumes that this is so.
1 'c==4' THEN 2 "UNIFORM DIST. X~UNF(a,b)" 3 { { } { } 4 { "A:" "Enter A" 0 } 5 { "B:" "Enter B" 0 } 6 { } { } 7 { "X1:" "Enter Lower limit" 0 } 8 { "X2:" "Enter upper limit" 0 } 9 } { 2 } { } { } 10 INFORM DROP OBJ-> DROP 11 'X2' STO 12 'X1' STO 13 'B' STO 14 'A' STO 15 "X~Uniform(x;" A ->STR + 16 "," + B ->STR + ")" + 17 '[integral](X1, X2, 1/(B-A), X)' 18 ->NUM 'ANS' STO 19 "P(" X1 ->STR + "≤X≤" + X2 ->STR + ")=" + ANS 4 RND ->STR + ANS 20 'X1' PURGE 21 'X2' PURGE 22 'A' PURGE 23 'B' PURGE 24 'ANS' PURGE 25 'IERR' PURGE 26 END |
Similar in concept to the uniform distribution, this subprogram uses an INFORM box to get the user's input, stores the results in named variables, computes the relevant probability, and PURGEs the variables before it exits.
In this case, the computational section evaluates the probability in question by directly integrating the PDF over the user supplied interval.
There is no error checking on the parameter of the distribution (which must be non-negative), or the user-supplied interval.
1 'c==5' THEN 2 "Exponential DIST.x~exp(λ)" 3 { { } { } 4 { "λ:" "Enter the rate: λ>0" 0 } 5 { } { } { } 6 { "X1:" "Enter the LOWER limit" 0 } 7 { "X2:" "Enter the UPPER limit" 0 } 8 } { 2 } { } { } 9 INFORM DROP OBJ-> 10 DROP 11 'X2' STO 12 'X1' STO 13 'λ' STO 14 '[integral](X1, X2, λ *EXP(-λ*X), X)' 15 ->NUM 16 'ANS' STO 17 "X~EXP(x:" λ ->STR + ")" + "P(" X1 ->STR 18 + "≤X≤" + X2 ->STR + ")=" + ANS 4 RND->STR + ANS 19 'X1' PURGE 20 'X2' PURGE 21 'λ' PURGE 22 'ANS' PURGE 23 END |
This subprogram finds the lower tail probabilities associated with the Normal distribution. In other words, it evaluates the Normal CDF.
The general form of the subprogram is similar to the majority of the other subprograms; an INFORM dialog is used to obtain the user's input, the relevant values are stored in named variables, the computation is performed, and the stored variables are cleared.
The computational section uses the built-in HP-48G Series function UTPN (Upper Tail Probability Normal).
The program performs no error checking.
1 'c==6' THEN 2 " NORMAL DISTRIBUTION P(X≤x)" 3 MSGBOX CLEAR 4 "Normal (lower tail) X~n(µ,σ)" 5 { { } { } 6 { "x:" "Enter X" 0 } 7 { } { } 8 { "µ:" "input the mean" 0 } 9 { "σ:" "input the Standard Deviation" 0 } 10 } { 2 } { } { } 11 INFORM DROP OBJ-> DROP 12 'σ' STO 13 'µ' STO 14 'σ^2' EVAL 15 x UTPN 'ANS' STO 16 "X~Normal(x;" 17 µ->STR + "," + σ ->STR + ")" 18 + "P(X≤" x ->STR + ")=" + '1-ANS' ->NUM 4 RND ->STR 19 + '1-ANS' EVAL 20 'x' PURGE 21 'µ' PURGE 22 'σ' PURGE 23 'ANS' PURGE 24 END |
This program allows the user to compute values associates with the upper tail (survival) probabilities of the Normal distribution.
In contract to the preceding subprograms, this program defines an appropriate equation and then invokes the HP-48G Series SOLVE application. The user interaction is delegated to the SOLVE application, as is the display of the answer (and, for the matter, the choice of which answer the user is seeking).
1 'c==7' THEN 2 " NORMAL DISTRIBUTION (Upper Tail)" MSGBOX 3 << 4 UPPER µ σ2 X UTPN - 5 >> 6 STEQ # 737281d LIBEVAL 7 END |
This subprogram allows the user to compute values associated with the upper tail of Student's T distribution.
As with the upper tail Normal subprogram, this subprogram invokes the SOLVE application to obtain user input and perform the relevant calculations.
1 'c==8' THEN 2 "t-DISTRIBUTION 3 (Upper Tail)" MSGBOX 4 << 5 UPPER df T UTPT - 6 >> 7 STEQ 8 # 737281d LIBEVAL END |
This subprogram allows the user to obtain values associated with the upper tail of the Chi-Squared distribution.
Similar in implementation to the other upper tail subprograms, this section uses the HP-48G Series SOLVE application.
1 'c==9' THEN 2 " Chi-Squared DISTRIBUTION 3 (Upper Tail)" MSGBOX 4 <<UPPER df X2 UTPC - 5 >> STEQ 6 # 737281d LIBEVAL END |
This subprogram PURGEs the variables which may be left in the user's directory by the other subprograms.
No error checking is done before purging these variables. Indeed, it is difficult to see how error checking could be performed, given the overall structure of the MA206 program. This issue is further discussed below, as it is a general design issue for the program, not just this subprogram.
1 'c==10' THEN
2 'EXPR' PURGE
3 'EQ' PURGE
4 'UPPER' PURGE
5 'df' PURGE
6 'T' PURGE'
7 'X2' PURGE
8 'µ' PURGE
9 'σ2' PURGE
10 'X' PURGE
11 'X1' PURGE
12 'n' PURGE
13 'p' PURGE
14 'ANS' PURGE
15 'λ' PURGE
16 'M' PURGE
17 'N' PURGE
18 'A' PURGE
19 'B' PURGE
20 'λ' PURGE This second PURGE
of λ appears to be redundant.
21 'x' PURGE
22 'σ' PURGE
23 'IERR' PURGE
24 END
25 END
26 >>
27 >> |
A consequence of this is that if any of these variables are used other than as temporary variables in the MA206 program, the MA206 program may overwrite or delete them without warning. Since a number of the variables were chosen to have mnemonic value matching the names of variables commonly used in the subject area.... [TBR]
As it is used in this program, the INFORM programming construct causes a program error if the user selects CANCEL from within the INFORM screen. This occurs because when the user exits INFORM, the routine returns a status value, which is DROPped without examination in the existing program, and the resulting stack does not contain the right number or type of values.
Causing the program to exit with an error is not catastrophic. The error occurs if the user selects CANCEL, and results in program termination. Since the user presumably wants out of the program if they select CANCEL, the actual result matches reasonably with the user's expectation. However, creating a program error (and thus displaying an apparently unrelated error message) is bad programming style because it may be confusing, especially to an unsophisticated user.
Jay L. Devore, Probability and Statistics for Engineering and the Sciences, 4th ed., Duxbury Press, 1995.
Hewlett Packard, HP 48G Series User's Guide, HP 48 User's Guide, 5th ed., Hewlett Packard, 1993, 00048-90126.
Hewlett Packard, HP 48G Series Advanced User's Reference Manual, 4th ed., Hewlett Packard, 1994, 00048-90136.
Department of Mathematical Sciences, USMA, MA206 Probability and Statistics Study Guide: STAP 98-3, United States Military Academy, 1998.
EduCALC, Writing Your First HP 48 Program: EduCALC Technical Notes, Accessed 7/27/98, 1845, http://www.educalc.com/TZ/tn052c.htm.
An introduction to programming the HP-48G Series and its "object orientation", physical organization, and program entry.
EduCALC, Writing Your Second HP 48 Program: EduCALC Technical Notes, Accessed 7/27/98, 1845, http://www.educalc.com/TZ/tn054c.htm.
Continuing the series of class programming handouts, this technical note introduces basic input mechanisms and stack manipulation under program control.
EduCALC, Writing Your Third HP 48 Program: EduCALC Technical Notes, Accessed 7/27/98, 1846, http://www.educalc.com/TZ/tn055c.htm.
Third in the series of class programming handouts, this technical note introduces basic output display mechanisms and program sizing.
EduCALC, Writing Your Fourth HP 48 Program: EduCALC Technical Notes, Accessed 7/27/98, 1846, http://www.educalc.com/TZ/tn056c.htm.
Continuing the series of HP-48G Series programming lessons by introducing the concepts of program-controled variable storage and moularity (calling other programs as part of a system).
EduCALC, INPUT - By Example: EduCALC Technical Notes, Accessed 7/27/98, 1843, http://www.educalc.com/TZ/tn050c.htm.
An introduction to using the HP-48G Series INPUT command.