home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / ex_stats_simple.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  2.2 KB  |  62 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net>                |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: ex_stats_simple.php,v 1.3 2003/01/04 11:55:39 mj Exp $
  20. //
  21.  
  22. /**
  23.  * @package    Math_Stats
  24.  */
  25.  
  26. require_once "Math/Stats.php";
  27.  
  28. // making some data sets
  29. $data = array (2,2.3,4.5,2,2,3.2,5.3,3,4,5,1,6);
  30. $dnulls = array (1.1650,null, "foo",0.6268, 0.6268, 0.0751, 0.3516, -0.6965);
  31.  
  32. // instantiating a Math_Stats object
  33. $s = new Math_Stats();
  34.  
  35. echo "*** Original data set\n";
  36. print_r($data);
  37. $s->setData($data);
  38. echo "Basic statistics\n";
  39. print_r($s->calcBasic());
  40.  
  41. echo "\n*** A data set with nulls\n";
  42. print_r($dnulls);
  43.  
  44. echo "Let's generate an error\n";
  45. print_r($s->setData($dnulls));
  46. echo "Ignoring nulls and trying again\n";
  47. $s->setNullOption(STATS_IGNORE_NULL);
  48. $s->setData($dnulls);
  49. echo "---> data after ignoring (removing) nulls\n";
  50. print_r($s->getData());
  51. echo "---> stats\n";
  52. print_r($s->calcBasic());
  53.  
  54. echo "Assuming nulls are zeros and doing a full stats calculation\n";
  55. $s->setNullOption(STATS_USE_NULL_AS_ZERO);
  56. $s->setData($dnulls);
  57. echo "---> data after setting nulls to zero\n";
  58. print_r($s->getData());
  59. echo "---> stats\n";
  60. print_r($s->calcFull());
  61. ?>
  62.