The Constructor: Backbone of the Chi Square test
Listing 4 looks at the Chi Square constructor code which forms the backbone of the Chi Square test.Listing 4. The Chi Square constructor
Four noteworthy aspects of the constructor method are:
- The constructor accepts an array of observed frequencies, an alpha probability cutoff score, and an optional array of expected probabilities.
- The first six lines involve relatively simple assignments and computed values that are recorded so a complete result object is available to calling scripts.
- The final four lines do the bulk of the work in obtaining the Chi Square statistics you are most interested in.
- The class implements only the Chi Square test logic. No output methods are associated with this class.
You can examine the class methods included in the code download for this article to find out more about how each result object value is computed (see Resources).