Post Reply 
(12C) Chi Square Statistic
06-14-2019, 11:00 AM
Post: #4
RE: (12C) Chi Square Statistic
I had a go at the chi-sq distribution (the probability distribution as opposed to the statistic itself that I calculated above which follows this probability distribution if all assumptions in it are met). It is significantly more complicated (and accurate!) than I require but it was good to give it a go anyway and see could I modify the HP-25 program successfully. The program required some significant modification in registers as R5-R7 don't allow register arithmetic in HP-12C and the conditionals are x>=y the opposite of it too (no NOP instruction and a few other things) . Got it all working and versions A and B are in the code below.

I haven't changed or improved the program at all using the more expanded program memory and registers of the HP-12C. It works exactly as per the HP-25 but as it was limited to 7 registers the HP-12C could use and 8th for the output rather than using R7 for counter j as well as the output (j is the integer part and the right tail probability or the result is the fractional part of the register entry). Also the variable input is cumbersome as pre-calculations have to be done on them before starting the program but that is simple enough with the RPN stack on the HP's!

To run the program (use manual version with pause first to check it is working):
f CLEAR REG (this is very important as it took me some time to figure out!)
Z: chi-sq statistic/2
Y: degrees freedom/2 - 1 (df must be even as this has to be an integer)
X: eccentricity/2
R/S

For the paused version it will pause and show the result at each i (the outer variable) and this accumulates in the fractional part of R7.

Use chi-sq = 18.307; df = 10 (also called nu) & eccent. = 3.71 and check the outputs against the values in his paper pg. 26.

Note: this can only deal with df being even and in our example earlier it was odd (5). The paper proposes either simple or more complex interpolation for odd df's. For the standard chi-sq distribution (as in normal tables of it) I think eccent. =0.

I suspect it can be done much more simply if I only want accuracy to 2 decimal places. I'll hunt around for a solution if I get time.

Code:

// Chi-sq Distribution (eccentric - normal RV's which make up the chi-sq not necessarily mu=0)
// Modified for HP-12C by Joe_H 2019 
// from 'Programs on HP-25 Desk Calculator of Mathematical Functions for use in Statistics' E. Sverdrup 1976 pgs. 25-27

01 STO 7            
02 CHS                
03 e^x                
04 STO 4
05 Rv
06 STO 3
07 Rv
08 STO 5
09 CHS
10 e^x
11 STO 0
12 STO +2
13 RCL 1
14 RCL 3
15 x<=y?
16 g GTO 26
17 1
18 STO +1
19 RCL 1
20 INTG
21 STO /0
22 RCL 5
23 STO *0
24 RCL 0
25 g GTO 12
26 RCL 2
27 STO -2
28 RCL 4
29 *
30 STO +1
31 g PSE                // replace this line with g GTO 45 for the automated version up to m terms (below)
32 g PSE
33 RCL 3
34 STO -1
35 1
36 STO +3
37 RCL 6
38 +
39 STO 6
40 STO /4
41 RCL 7
42 STO *4
43 RCL 5
44 g GTO 09
45 RCL 6
46 3                    // replace these with the number you want: here it is m=30 but can be any number
47 0
48 x<=y?
49 g GTO 00
50 g GTO 33
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(12C) Chi Square Statistic - Joe_H - 06-12-2019, 10:18 PM
RE: (12C) Chi Square Statistic - SlideRule - 06-13-2019, 12:56 AM
RE: (12C) Chi Square Statistic - Joe_H - 06-13-2019, 03:30 PM
RE: (12C) Chi Square Statistic - Joe_H - 06-14-2019 11:00 AM
RE: (12C) Chi Square Statistic - Joe_H - 06-14-2019, 11:10 AM



User(s) browsing this thread: 1 Guest(s)