ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Deviations.php
Go to the documentation of this file.
1<?php
2
4
6
8{
21 public static function sumSquares(...$args)
22 {
23 $aArgs = Functions::flattenArrayIndexed($args);
24
25 $aMean = Averages::average($aArgs);
26 if (!is_numeric($aMean)) {
27 return Functions::NAN();
28 }
29
30 // Return value
31 $returnValue = 0.0;
32 $aCount = -1;
33 foreach ($aArgs as $k => $arg) {
34 // Is it a numeric value?
35 if (
36 (is_bool($arg)) &&
37 ((!Functions::isCellValue($k)) ||
39 ) {
40 $arg = (int) $arg;
41 }
42 if ((is_numeric($arg)) && (!is_string($arg))) {
43 $returnValue += ($arg - $aMean) ** 2;
44 ++$aCount;
45 }
46 }
47
48 return $aCount === 0 ? Functions::VALUE() : $returnValue;
49 }
50
63 public static function kurtosis(...$args)
64 {
65 $aArgs = Functions::flattenArrayIndexed($args);
66 $mean = Averages::average($aArgs);
67 if (!is_numeric($mean)) {
68 return Functions::DIV0();
69 }
70 $stdDev = StandardDeviations::STDEV($aArgs);
71
72 if ($stdDev > 0) {
73 $count = $summer = 0;
74
75 foreach ($aArgs as $k => $arg) {
76 if ((is_bool($arg)) && (!Functions::isMatrixValue($k))) {
77 } else {
78 // Is it a numeric value?
79 if ((is_numeric($arg)) && (!is_string($arg))) {
80 $summer += (($arg - $mean) / $stdDev) ** 4;
81 ++$count;
82 }
83 }
84 }
85
86 if ($count > 3) {
87 return $summer * ($count * ($count + 1) /
88 (($count - 1) * ($count - 2) * ($count - 3))) - (3 * ($count - 1) ** 2 /
89 (($count - 2) * ($count - 3)));
90 }
91 }
92
93 return Functions::DIV0();
94 }
95
108 public static function skew(...$args)
109 {
110 $aArgs = Functions::flattenArrayIndexed($args);
111 $mean = Averages::average($aArgs);
112 if (!is_numeric($mean)) {
113 return Functions::DIV0();
114 }
115 $stdDev = StandardDeviations::STDEV($aArgs);
116 if ($stdDev === 0.0 || is_string($stdDev)) {
117 return Functions::DIV0();
118 }
119
120 $count = $summer = 0;
121 // Loop through arguments
122 foreach ($aArgs as $k => $arg) {
123 if ((is_bool($arg)) && (!Functions::isMatrixValue($k))) {
124 } elseif (!is_numeric($arg)) {
125 return Functions::VALUE();
126 } else {
127 // Is it a numeric value?
128 if ((is_numeric($arg)) && (!is_string($arg))) {
129 $summer += (($arg - $mean) / $stdDev) ** 3;
130 ++$count;
131 }
132 }
133 }
134
135 if ($count > 2) {
136 return $summer * ($count / (($count - 1) * ($count - 2)));
137 }
138
139 return Functions::DIV0();
140 }
141}
An exception for terminatinating execution or to throw for unit testing.
static flattenArrayIndexed($array)
Convert a multi-dimensional array to a simple 1-dimensional array, but retain an element of indexing.
Definition: Functions.php:616
static getCompatibilityMode()
Return the current Compatibility Mode.
Definition: Functions.php:93