(12C) Chi Square Statistic

06122019, 10:18 PM
Post: #1




(12C) Chi Square Statistic
The Chisq statistic is very widely used in many disciplines not least in finance. It is used to test if there is a significant difference between the expected frequency of occurrence of an event and the actual frequency of occurrence (e.g. rolling a dice 60 times and getting 30 1's 30 2'sand nothing else would intuitively be suspicious  I'll calculate this below) It would be useful to be able to calculate the statistic quickly from a series of observations. Tony Hutchins did this in a simple interactive program of only 8 lines but I have completely changed it to a more convenient and faster form. I don't want an interactive program as it doesn't suit how I'm going to set up the calculator but also you can't check if you made a data entry error as values get rolled up as the sum is calculated. Also in his program the expected frequency has to be entered each time but I wanted a work around when it is common to avoid reentering it.
The following program calculates the Chisq statistic where the observation counts and expected counts are placed in the cashflow registers. CFj is used for the Obs and Nj for the Expt values in each category. Where there is a common Expt (as example below) then don't enter them and instead enter the Expt in X before calling the program. If Expt is entered in the cashflow then set X to zero before calling the program. n is used and should be correctly set after inputting the values (don't use CF0 set n to 0  better yet clear all reg before inputting the data) and start first values at n=1 (this will be automatic if set n=0 before start data entry). PMT is used as the common/individual Expt flag. Note n will be 0 after the computation and needs to be reset. Could save and reset it for a few extra lines. Code:
Examples: Hutchins dice roll Rolling a dice 120 times produced the following numbers 1  25 2  17 3  15 4  23 5  24 6  16 A fair dice should on average produce 20 of each number for 120 throws (Expt in this example). Is this dice fair? f Clear Reg 25 g CFi (don't bother with Nj as only one Expt but enter it now if different for categories) 17 g CFi ditto for other 4; n=6 now 20 (place common Expt in X) R/S Answer = 5 and from chisq tables the probability with 5 degrees of freedom (1 less than n) and alpha of 5% (i.e. 95% certainty) chisq is 11.07. As 5 is less than this the dice is fair to 95% certainty. My example of 60 throws enter as before (I'll make 3 to 6 1 each to avoid any problems with 0 entry). Expt is 10 (60/6). Chisq calculates as 97.2. Clearly this is much greater than 11.07 so at 95% confidence level we know there's a problem with my dice. Individual Expt values just are different in data entry (use the Nj's) and set X to 0 every thing after that is identical. I will look into doing the probability values if I can find a simple approximation for the chisq probability distribution. 

« Next Oldest  Next Newest »

Messages In This Thread 
(12C) Chi Square Statistic  Joe_H  06122019 10:18 PM
RE: (12C) Chi Square Statistic  SlideRule  06132019, 12:56 AM
RE: (12C) Chi Square Statistic  Joe_H  06132019, 03:30 PM
RE: (12C) Chi Square Statistic  Joe_H  06142019, 11:00 AM
RE: (12C) Chi Square Statistic  Joe_H  06142019, 11:10 AM

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