cvs: pear /Math_Stats/examples ex_stats_cummulative_data.php ex_stats_simple.php
| From: | Jesus M. Castagnetto | Date: | Thu, 16 May 2002 04:44:58 +0000 |
| Subject: | cvs: pear /Math_Stats/examples ex_stats_cummulative_data.php ex_stats_simple.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-3849@lists.php.net to get a copy of this message | ||
jmcastagnetto Thu May 16 00:44:58 2002 EDT
Added files:
/pear/Math_Stats/examples ex_stats_cummulative_data.php
ex_stats_simple.php
Log:
Examples of using the Math_Stats class
Index: pear/Math_Stats/examples/ex_stats_cummulative_data.php
+++ pear/Math_Stats/examples/ex_stats_cummulative_data.php
<?php
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt.
|
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: ex_stats_cummulative_data.php,v 1.1 2002/05/16 04:44:58 jmcastagnetto Exp $
//
/**
* @package Math_Stats
*/
//require_once "Math/Stats.php";
require_once "../Stats.php";
// making some cummulative data sets
$data = array("3"=>4, "2.333"=>5, "1.22"=>6,
"0.5"=>3, "0.9"=>2, "2.4"=>7);
$dnulls = array("3"=>4, "caca"=>2, "bar is not foo"=>6,
"0.5"=>3, "0.9"=>2, "2.4"=>7);
// instantiate a Math_Stats object
$s = new Math_Stats();
$s->setData($data, STATS_DATA_CUMMULATIVE);
echo "*** Original cummulative data set\n";
print_r($data);
// let's print some simple statistics
echo "Simple stats from cummulative data, note the count\n";
print_r($s->calcBasic());
// now, lets generate an error by using the $dnulls array
echo "\n*** Another cummulative data set\n";
print_r($dnulls);
echo "Generating an error by using data with nulls\n";
print_r($s->setData($dnulls, STATS_DATA_CUMMULATIVE));
// let's ignore nulls
echo "Ignoring the nulls and trying again\n";
$s->setNullOption(STATS_IGNORE_NULL);
$s->setData($dnulls, STATS_DATA_CUMMULATIVE);
print_r($s->calcBasic());
// let's assume null == zero
echo "Assuming that nulls are zero\n";
$s->setNullOption(STATS_USE_NULL_AS_ZERO);
$s->setData($dnulls, STATS_DATA_CUMMULATIVE);
print_r($s->calcFull());
?>
Index: pear/Math_Stats/examples/ex_stats_simple.php
+++ pear/Math_Stats/examples/ex_stats_simple.php
<?php
//
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt.
|
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net> |
// +----------------------------------------------------------------------+
//
// $Id: ex_stats_simple.php,v 1.1 2002/05/16 04:44:58 jmcastagnetto Exp $
//
/**
* @package Math_Stats
*/
//require_once "Math/Stats.php";
require_once "../Stats.php";
// making some data sets
$data = array (2,2.3,4.5,2,2,3.2,5.3,3,4,5,1,6);
$dnulls = array (1.1650,null, "foo",0.6268, 0.6268, 0.0751, 0.3516, -0.6965);
// instantiating a Math_Stats object
$s = new Math_Stats();
echo "*** Original data set\n";
print_r($data);
$s->setData($data);
echo "Basic statistics\n";
print_r($s->calcBasic());
echo "\n*** A data set with nulls\n";
print_r($dnulls);
echo "Let's generate an error\n";
print_r($s->setData($dnulls));
echo "Ignoring nulls and trying again\n";
$s->setNullOption(STATS_IGNORE_NULL);
$s->setData($dnulls);
echo "---> data after ignoring (removing) nulls\n";
print_r($s->getData());
echo "---> stats\n";
print_r($s->calcBasic());
echo "Assuming nulls are zeros and doing a full stats calculation\n";
$s->setNullOption(STATS_USE_NULL_AS_ZERO);
$s->setData($dnulls);
echo "---> data after setting nulls to zero\n";
print_r($s->getData());
echo "---> stats\n";
print_r($s->calcFull());
?>