@@ -42,9 +42,9 @@ discard block |
||
42 | 42 | print_r($dnulls); |
43 | 43 | echo "Let's generate an error\n"; |
44 | 44 | try { |
45 | - print_r($s->setData($dnulls)); |
|
45 | + print_r($s->setData($dnulls)); |
|
46 | 46 | } catch (\Exception $e) { |
47 | - echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
47 | + echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | echo "Ignoring nulls and trying again\n"; |
@@ -54,9 +54,9 @@ discard block |
||
54 | 54 | print_r($s->getData()); |
55 | 55 | echo "---> stats\n"; |
56 | 56 | try { |
57 | - print_r($s->calcBasic()); |
|
57 | + print_r($s->calcBasic()); |
|
58 | 58 | } catch (\Exception $e) { |
59 | - echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
59 | + echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | echo "Assuming nulls are zeros and doing a full stats calculation\n"; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | print_r($s->getData()); |
67 | 67 | echo "---> stats\n"; |
68 | 68 | try { |
69 | - print_r($s->calcFull()); |
|
69 | + print_r($s->calcFull()); |
|
70 | 70 | } catch (\Exception $e) { |
71 | - echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
71 | + echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
72 | 72 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | //require_once 'Math/Stats.php'; |
3 | - require_once __DIR__ . '/../../vendor/autoload.php'; |
|
3 | + require_once __DIR__ . '/../../vendor/autoload.php'; |
|
4 | 4 | |
5 | 5 | |
6 | 6 | $data = array(); |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | try { |
20 | 20 | $stats = $s ->calcFull(); |
21 | 21 | |
22 | - //print_r($stats); |
|
22 | + //print_r($stats); |
|
23 | 23 | echo "Using Math_Stats:\n" |
24 | 24 | . "mean = {$stats['mean']}\n" |
25 | 25 | . "SEmean = {$stats['std_error_of_mean']}\n" |
@@ -41,8 +41,8 @@ discard block |
||
41 | 41 | . "max = 41\n" |
42 | 42 | . "count = 4255666\n"; |
43 | 43 | |
44 | - //Name,Mean,SEMean,StDev,Q1,Median,Q3,Min,Max,N |
|
45 | - //SPSS,2.8627,0.0005,1.0630,2,3,4,1,41,4255666 |
|
44 | + //Name,Mean,SEMean,StDev,Q1,Median,Q3,Min,Max,N |
|
45 | + //SPSS,2.8627,0.0005,1.0630,2,3,4,1,41,4255666 |
|
46 | 46 | } catch (\Exception $e) { |
47 | 47 | echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
48 | 48 | } |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | print_r($dnulls); |
47 | 47 | echo "Generating an error by using data with nulls\n"; |
48 | 48 | try { |
49 | - print_r($s->setData($dnulls, \PEAR\Math\Stats::STATS_DATA_CUMMULATIVE)); |
|
49 | + print_r($s->setData($dnulls, \PEAR\Math\Stats::STATS_DATA_CUMMULATIVE)); |
|
50 | 50 | } catch (\Exception $e) { |
51 | - echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
51 | + echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | $s->setNullOption( \PEAR\Math\Stats::STATS_IGNORE_NULL); |
58 | 58 | $s->setData($dnulls, \PEAR\Math\Stats::STATS_DATA_CUMMULATIVE); |
59 | 59 | try { |
60 | - print_r($s->calcBasic()); |
|
60 | + print_r($s->calcBasic()); |
|
61 | 61 | } catch (\Exception $e) { |
62 | - echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
62 | + echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | // let's assume null == zero |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $s->setNullOption( \PEAR\Math\Stats::STATS_USE_NULL_AS_ZERO); |
68 | 68 | $s->setData($dnulls, \PEAR\Math\Stats::STATS_DATA_CUMMULATIVE); |
69 | 69 | try { |
70 | - print_r($s->calcFull()); |
|
70 | + print_r($s->calcFull()); |
|
71 | 71 | } catch (\Exception $e) { |
72 | - echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
72 | + echo "\n\t Exception: ".$e->getMessage()."\n\n"; |
|
73 | 73 | } |
@@ -4,8 +4,8 @@ discard block |
||
4 | 4 | |
5 | 5 | // let's generate some values; |
6 | 6 | for ($i=0; $i < 100; $i++) { |
7 | - $a['x'][$i] = rand(-1,6); |
|
8 | - $a['y'][$i] = rand(-1,6); |
|
7 | + $a['x'][$i] = rand(-1,6); |
|
8 | + $a['y'][$i] = rand(-1,6); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | $h = new \PEAR\Histogram\Histogram3D(); |
@@ -18,12 +18,12 @@ discard block |
||
18 | 18 | |
19 | 19 | // now, let's change the options a wee bit |
20 | 20 | $h->setBinOptions( |
21 | - array( |
|
22 | - 'low' => array( 'x' => 0, 'y' => 0), |
|
23 | - 'high' => array( 'x' => 5, 'y' => 5), |
|
24 | - 'nbins' => array( 'x' => 5, 'y' => 5) |
|
25 | - ) |
|
26 | - ); |
|
21 | + array( |
|
22 | + 'low' => array( 'x' => 0, 'y' => 0), |
|
23 | + 'high' => array( 'x' => 5, 'y' => 5), |
|
24 | + 'nbins' => array( 'x' => 5, 'y' => 5) |
|
25 | + ) |
|
26 | + ); |
|
27 | 27 | $h->setType(\PEAR\Histogram\AbstractHistogram::HISTOGRAM_CUMMULATIVE); |
28 | 28 | $h->calculate(); |
29 | 29 | // and print the whole histogram info, not the different |
@@ -4,21 +4,21 @@ |
||
4 | 4 | |
5 | 5 | // let's generate some data |
6 | 6 | for ($i=0; $i < 100; $i++) { |
7 | - $a['x'][$i] = rand(0,4); |
|
8 | - $a['y'][$i] = rand(0,4); |
|
9 | - $a['z'][$i] = rand(0,4); |
|
7 | + $a['x'][$i] = rand(0,4); |
|
8 | + $a['y'][$i] = rand(0,4); |
|
9 | + $a['z'][$i] = rand(0,4); |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | // and create a histogram from the data |
13 | 13 | // with specific options |
14 | 14 | $h = new \PEAR\Histogram\Histogram4D(); |
15 | 15 | $h->setBinOptions( |
16 | - array( |
|
17 | - 'low' => array( 'x' => 0, 'y' => 0, 'z'=>0), |
|
18 | - 'high' => array( 'x' => 4.0, 'y' => 4.0, 'z'=>4.0), |
|
19 | - 'nbins' => array( 'x' => 4, 'y' => 4, 'z'=>4) |
|
20 | - ) |
|
21 | - ); |
|
16 | + array( |
|
17 | + 'low' => array( 'x' => 0, 'y' => 0, 'z'=>0), |
|
18 | + 'high' => array( 'x' => 4.0, 'y' => 4.0, 'z'=>4.0), |
|
19 | + 'nbins' => array( 'x' => 4, 'y' => 4, 'z'=>4) |
|
20 | + ) |
|
21 | + ); |
|
22 | 22 | $h->setData($a); |
23 | 23 | $h->calculate(); |
24 | 24 | // now we print out a comma separated set |
@@ -4,10 +4,10 @@ discard block |
||
4 | 4 | |
5 | 5 | // create a boring array |
6 | 6 | $vals = array( |
7 | - 1.5,2,3,4,0,3.2,0.1,0,0,5,3,2,3,4,1,2,4,5,1,3,2,4,5,2,3,4,1,2, |
|
8 | - 1.5,2,3,4,0,3.2,0.1,0,0,5,3,2,3,4,1,2,4,5,1,3,2,4,5,2,3,4,1,2, |
|
9 | - 1.5,2,3,4,0,3.2,0.1,0,0,5,3,2,3,4,1,2,4,5,1,3,2,4,5,2,3,4,1,2 |
|
10 | - ); |
|
7 | + 1.5,2,3,4,0,3.2,0.1,0,0,5,3,2,3,4,1,2,4,5,1,3,2,4,5,2,3,4,1,2, |
|
8 | + 1.5,2,3,4,0,3.2,0.1,0,0,5,3,2,3,4,1,2,4,5,1,3,2,4,5,2,3,4,1,2, |
|
9 | + 1.5,2,3,4,0,3.2,0.1,0,0,5,3,2,3,4,1,2,4,5,1,3,2,4,5,2,3,4,1,2 |
|
10 | + ); |
|
11 | 11 | |
12 | 12 | // create an instance |
13 | 13 | $h = new \PEAR\Histogram\Histogram(); |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | // let us read a bigger data set: |
25 | 25 | $data = array(); |
26 | 26 | foreach(file(__DIR__."/../../tests/_data/ex_histogram.data") as $item) |
27 | - $data[] = floatval(trim($item)); |
|
27 | + $data[] = floatval(trim($item)); |
|
28 | 28 | |
29 | 29 | // let's do a simple histogram |
30 | 30 | $h->setType(\PEAR\Histogram\AbstractHistogram::HISTOGRAM_SIMPLE); |
@@ -31,7 +31,7 @@ |
||
31 | 31 | { |
32 | 32 | |
33 | 33 | $this->setType($type); |
34 | - try { |
|
34 | + try { |
|
35 | 35 | $this->setBinOptions($binOptions); |
36 | 36 | } catch (\PEAR_Exception $e) { |
37 | 37 | // Falling back to default options |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | */ |
19 | 19 | const STATS_BASIC = 1; |
20 | 20 | /** |
21 | - * STATS_FULL to generate also higher moments, mode, median, etc. |
|
22 | - */ |
|
21 | + * STATS_FULL to generate also higher moments, mode, median, etc. |
|
22 | + */ |
|
23 | 23 | const STATS_FULL = 2; |
24 | 24 | |
25 | 25 | // Constants describing the data set format |
@@ -29,11 +29,11 @@ discard block |
||
29 | 29 | */ |
30 | 30 | const STATS_DATA_SIMPLE = 0; |
31 | 31 | /** |
32 | - * STATS_DATA_CUMMULATIVE for an associative array of frequency values, |
|
33 | - * where in each array entry, the index is the data point and the |
|
34 | - * value the count (frequency): |
|
35 | - * e.g. $data = array(3=>4, 2.3=>5, 1.25=>6, 0.5=>3) |
|
36 | - */ |
|
32 | + * STATS_DATA_CUMMULATIVE for an associative array of frequency values, |
|
33 | + * where in each array entry, the index is the data point and the |
|
34 | + * value the count (frequency): |
|
35 | + * e.g. $data = array(3=>4, 2.3=>5, 1.25=>6, 0.5=>3) |
|
36 | + */ |
|
37 | 37 | const STATS_DATA_CUMMULATIVE = 1; |
38 | 38 | |
39 | 39 | // Constants defining how to handle nulls |
@@ -43,14 +43,14 @@ discard block |
||
43 | 43 | */ |
44 | 44 | const STATS_REJECT_NULL = -1; |
45 | 45 | /** |
46 | - * STATS_IGNORE_NULL, ignore null values and prune them from the data. |
|
47 | - * Any non-numeric value is considered a null in this context. |
|
48 | - */ |
|
46 | + * STATS_IGNORE_NULL, ignore null values and prune them from the data. |
|
47 | + * Any non-numeric value is considered a null in this context. |
|
48 | + */ |
|
49 | 49 | const STATS_IGNORE_NULL = -2; |
50 | 50 | /** |
51 | - * STATS_USE_NULL_AS_ZERO, assign the value of 0 (zero) to null values. |
|
52 | - * Any non-numeric value is considered a null in this context. |
|
53 | - */ |
|
51 | + * STATS_USE_NULL_AS_ZERO, assign the value of 0 (zero) to null values. |
|
52 | + * Any non-numeric value is considered a null in this context. |
|
53 | + */ |
|
54 | 54 | const STATS_USE_NULL_AS_ZERO = -3; |
55 | 55 | |
56 | 56 | // properties |
@@ -2,88 +2,88 @@ |
||
2 | 2 | |
3 | 3 | function normsdist( $x ) { |
4 | 4 | |
5 | - // Returns the standard normal cumulative distribution |
|
6 | - // --------------------------------------- |
|
5 | + // Returns the standard normal cumulative distribution |
|
6 | + // --------------------------------------- |
|
7 | 7 | |
8 | - // Load tabulated values in an array |
|
9 | - include "ndist_tabulated.php" ; |
|
8 | + // Load tabulated values in an array |
|
9 | + include "ndist_tabulated.php" ; |
|
10 | 10 | |
11 | - // Discriminate upon the absolute value, then the sign of $x |
|
12 | - $x = number_format( $x, 2 ) ; |
|
13 | - if ( abs( $x ) >= 3.09 ) { |
|
11 | + // Discriminate upon the absolute value, then the sign of $x |
|
12 | + $x = number_format( $x, 2 ) ; |
|
13 | + if ( abs( $x ) >= 3.09 ) { |
|
14 | 14 | |
15 | - $output = 0 ; |
|
15 | + $output = 0 ; |
|
16 | 16 | |
17 | - } elseif ( $x==0 ) { |
|
17 | + } elseif ( $x==0 ) { |
|
18 | 18 | |
19 | - $output = 0.5 ; |
|
19 | + $output = 0.5 ; |
|
20 | 20 | |
21 | - } elseif ( $x<0 ) { |
|
21 | + } elseif ( $x<0 ) { |
|
22 | 22 | |
23 | - // find higher boundary (next highest value with 2 decimals) |
|
24 | - $x2 = number_format( ceil( 100*$x )/100, 2 ) ; |
|
25 | - $x2 = (string)$x2 ; |
|
23 | + // find higher boundary (next highest value with 2 decimals) |
|
24 | + $x2 = number_format( ceil( 100*$x )/100, 2 ) ; |
|
25 | + $x2 = (string)$x2 ; |
|
26 | 26 | |
27 | - // find lower boundary |
|
28 | - $x1 = number_format( $x2-0.01, 2 ) ; |
|
29 | - $x1 = (string)$x1 ; |
|
27 | + // find lower boundary |
|
28 | + $x1 = number_format( $x2-0.01, 2 ) ; |
|
29 | + $x1 = (string)$x1 ; |
|
30 | 30 | |
31 | - // linear interpolate |
|
32 | - $output = $values[$x1] + ( $values[$x2] - $values[$x1] )/0.01*( $x - $x1 ) ; |
|
31 | + // linear interpolate |
|
32 | + $output = $values[$x1] + ( $values[$x2] - $values[$x1] )/0.01*( $x - $x1 ) ; |
|
33 | 33 | |
34 | - } else { // if x>0 |
|
34 | + } else { // if x>0 |
|
35 | 35 | |
36 | - $output = 1 - normsdist( -$x ) ; |
|
36 | + $output = 1 - normsdist( -$x ) ; |
|
37 | 37 | |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - return number_format( $output, 4 ) ; |
|
40 | + return number_format( $output, 4 ) ; |
|
41 | 41 | |
42 | 42 | } |
43 | 43 | |
44 | 44 | |
45 | 45 | function normsinv( $y ) { |
46 | 46 | |
47 | - // Returns the inverse standard normal cumulative distribution ( 0<y<1 ) |
|
48 | - // --------------------------------------- |
|
47 | + // Returns the inverse standard normal cumulative distribution ( 0<y<1 ) |
|
48 | + // --------------------------------------- |
|
49 | 49 | |
50 | - // Load tabulated values in an array |
|
51 | - include "ndist_tabulated.php" ; |
|
50 | + // Load tabulated values in an array |
|
51 | + include "ndist_tabulated.php" ; |
|
52 | 52 | |
53 | - // Discriminate upon whether $y is between 0 and 1, then upon its position relative to 0.5 |
|
54 | - $y = number_format( $y, 4 ) ; |
|
55 | - if ( $y<=0 || $y>=1 ) { |
|
53 | + // Discriminate upon whether $y is between 0 and 1, then upon its position relative to 0.5 |
|
54 | + $y = number_format( $y, 4 ) ; |
|
55 | + if ( $y<=0 || $y>=1 ) { |
|
56 | 56 | |
57 | - $output = FALSE ; |
|
57 | + $output = FALSE ; |
|
58 | 58 | |
59 | - } elseif ( $y<=0.5 ) { |
|
59 | + } elseif ( $y<=0.5 ) { |
|
60 | 60 | |
61 | - // find the largest index which value is smaller than $y: |
|
61 | + // find the largest index which value is smaller than $y: |
|
62 | 62 | |
63 | - // filter array for values higher than $y |
|
64 | - $smaller = array() ; |
|
65 | - while ( list( $key, $value ) = each( $values ) ) { |
|
66 | - if ( $value <= $y ) { |
|
67 | - $smaller[$key] = $value ; |
|
68 | - } |
|
69 | - } |
|
70 | - // order $values in decreasing terms of the $values |
|
71 | - krsort( $smaller, SORT_NUMERIC ) ; |
|
72 | - reset( $smaller ) ; |
|
63 | + // filter array for values higher than $y |
|
64 | + $smaller = array() ; |
|
65 | + while ( list( $key, $value ) = each( $values ) ) { |
|
66 | + if ( $value <= $y ) { |
|
67 | + $smaller[$key] = $value ; |
|
68 | + } |
|
69 | + } |
|
70 | + // order $values in decreasing terms of the $values |
|
71 | + krsort( $smaller, SORT_NUMERIC ) ; |
|
72 | + reset( $smaller ) ; |
|
73 | 73 | |
74 | - $x1 = (string)key( $smaller ) ; |
|
75 | - $x2 = (string)( $x1+0.01 ) ; |
|
74 | + $x1 = (string)key( $smaller ) ; |
|
75 | + $x2 = (string)( $x1+0.01 ) ; |
|
76 | 76 | |
77 | - // interpolate |
|
78 | - $output = $x1 + ( $y - $values[$x1] )/( $values[$x2] - $values[$x1] )*0.01 ; |
|
77 | + // interpolate |
|
78 | + $output = $x1 + ( $y - $values[$x1] )/( $values[$x2] - $values[$x1] )*0.01 ; |
|
79 | 79 | |
80 | - } else { // meaning $x between 0.5 and 1 |
|
80 | + } else { // meaning $x between 0.5 and 1 |
|
81 | 81 | |
82 | - $output = - normsinv( 1 - $y ) ; |
|
82 | + $output = - normsinv( 1 - $y ) ; |
|
83 | 83 | |
84 | - } |
|
84 | + } |
|
85 | 85 | |
86 | - return number_format( $output, 4 ) ; |
|
86 | + return number_format( $output, 4 ) ; |
|
87 | 87 | |
88 | 88 | } |
89 | 89 |