Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > SERVER SIDE CODING > PHP TUTORIALS > TAKE WEB DATA ANALYSIS TO THE NEXT LEVEL WITH PHP


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

Take Web Data Analysis To The Next Level With PHP
By Paul Meagher - 2003-12-22 Page:  1 2 3 4 5 6 7 8 9 10 11 12 13

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

<?php

class ChiSquare1D {     

  function ChiSquare1D($ObsFreq, $Alpha=0.05, $ExpProb=FALSE) {   
    $this->ObsFreq    = $ObsFreq;        
    $this->ExpProb    = $ExpProb;            
    $this->Alpha      = $Alpha;
    $this->NumCells   = count($this->ObsFreq);        
    $this->DF         = $this->NumCells - 1;        
    $this->Total      = $this->getTotal(); 
    $this->ExpFreq    = $this->getExpFreq();
    $this->ChiSqObt   = $this->getChiSqObt();    
    $this->ChiSqCrit  = $this->getChiSqCrit();    
    $this->ChiSqProb  = $this->getChiSqProb();     
    return true;  
  }

}

?>

Four noteworthy aspects of the constructor method are:

  1. The constructor accepts an array of observed frequencies, an alpha probability cutoff score, and an optional array of expected probabilities.
  2. The first six lines involve relatively simple assignments and computed values that are recorded so a complete result object is available to calling scripts.
  3. The final four lines do the bulk of the work in obtaining the Chi Square statistics you are most interested in.
  4. 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).



View Take Web Data Analysis To The Next Level With PHP Discussion

Page:  1 2 3 4 5 6 7 8 9 10 11 12 13 Next Page: Handle Output Issues

First published by IBM developerWorks


Copyright 2004-2017 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.