The Museum of HP Calculators


Chi-Square Distribution for the HP-67

This program is Copyright © 1976 by Hewlett-Packard and is used here by permission. This program was originally published in the HP-67 Stat Pac 1.

This program is supplied without representation or warranty of any kind. The author and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Card Labels
Chi-Square Distribution
Shift          
Label Start P? v→Γ(v/2) x→f(x) x→P(x)
Key A B C D E

Overview

This program evaluates the chi-square density

f(x) = (1/(2v/2Γ(v/2))) xv/2-1e-x/2

where x ≥ 0 and v is the degrees of freedom.

Series approximation is used to evaluate the cumulative distribution

P(x) = (0..x)f(t) dt =

(x/2)v/2(e-x/2/Γ((v+2)/2))[1 + (k=1..infinity) xk/((v+2)(v+4)...(v+2k))]

The program computes successive partial sums of the above series. When two consecutive partial sums are equal, the value is used as the sum of the series.

Notes

  1. Program requires v < 141. If v > 141, erroneous overflow will result.
  2. If both x and v are large, f(x) may overflow the machine.
  3. If v is even,
          Γ(v/2) = (v/2 -1)!
    If v is odd.
          Γ(v/2) = (v/2 - 1)(v/2 - 2) ... (1/2)γ(1/2)
  4. Γ(1/2) = √π

Reference

Abramowitz and Stegun, Handbook of Mathematical Functions, National Bureau of Standards, 1970.

Instructions

Step Instructions Input Data/Units Keys Output Data/Units
1 Load side 1 and side 2.      
2 Initialize   A 0.00
3 To set print mode*   B 1.00
 4 Input degrees of freedom v v C Γ(v/2)
  Optional: Step 5      
5 Input x to compute f(x) x D f(x)
6 Input x to compute P(x) x E P(x)
  For a new case with the same v, go to 5 or 6      
  For a new case with different v, go to 2      
         
  *Note: to clear print mode press→   CLF 0  

Examples

If degrees of freedom v = 20, find f(x), P(x) for x = 9.6 and x = 15.

Keystrokes                         Outputs
A                                     0.00
B                                     1.00
20 C                                 20.00 ***
                                 362880.00 *** (Γ(20/2))

9.6 D                                 9.60 ***
                                      0.02 *** (f(9.6))

9.6 E                                 9.60 ***
                                      0.03 *** (P(9.6))

15 E                                 15.00 ***
                                      0.22 *** (P(15))

15 D                                 15.00 ***
                                      0.06 *** (f(15))

If v = 3, find f(x) and P(x) for x = 7.82.

Keystrokes                         Outputs
A                                    0.00
B                                    1.00
3 C                                  3.00 ***
                                     0.89 *** (Γ(3/2))

7.82 D                               7.82 ***
                                     0.02 *** (f(7.82))

7.82 E                               7.82 ***
                                     0.95 *** (P(7.82))

The Program

LINE  KEYS
001  *LBL A
002   CL REG    Initialize
003   CF 0
004   CF 1
005   0
006   RTN
007  *LBL B     Set flag for print.
008   SF 0
009   1
010   RTN
011  *LBL C
012   GSB 9     Input v.
013   1
014   STO 3
015   X⇔Y       Calculate Γ(v/2)
016   2
017   ÷
018   STO 1
019   INT
020   LST X
021   X≠Y?
022   GTO 1
023   1
024   -
025   N!
026   GSB 9
027   GSB 8
028   STO 3
029   R/S
030  *LBL 1
031   .
032   5
033   X=Y?
034   GTO 2
035   X⇔Y
036   1
037   -
038   STO x 3
039   GTO 1
040  *LBL 2
041   π
042   √x
043   RCL 3
044   ×
045   STO 3
046   GSB 9
047   GSB 8
048   R/S
049  *LBL D
050   SF 1
051  *LBL e     Input x, calculate f(x)
052   GSB 9
053   STO 2
054   RCL 1
055   1
056   -
057   YX
058   RCL 2
059   2
060   ÷
061   CHS
062   ex
063   ×
064   2
065   RCL 1
066   YX
067   ÷
068   RCL 3
069   ÷
070   STO 5
071   F1?
072   GSB 9
073   F1?
074   GSB 8
075   CF 1
076   RTN
077  *LBL E
078   GSB e     Input x, calculate P(x).
079   RCL 2
080   RCL 1
081   ÷
082   STO x 5
083   2
084   RCL 1
085   ×
086   STO 6
087   1
088   STO 4
089  *LBL 3
090   RCL 2
091   RCL 6
092   2
093   +
094   STO 6
095   ÷
096   RCL 4
097   ×
098   STO 4
099   +
100   X≠Y?
101   GTO 3
102   RCL 5
103   ×
104   GSB 9
105   GSB 8
106   RTN
107  *LBL 9     Subroutine for print.
108   F0?
109   PRTX
110   RTN
111  *LBL 8
112   F0?       Subroutine for space.
113   PRT SPC
114   RTN

Register Use

R1  v/2
R2  x
R3  1, Γ(v/2)
R4  used
R5  f(x)
R6  Used

Go back to the software library
Go back to the main exhibit hall