ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Variances.php
Go to the documentation of this file.
1 <?php
2 
4 
6 
7 class Variances extends VarianceBase
8 {
21  public static function VAR(...$args)
22  {
23  $returnValue = Functions::DIV0();
24 
25  $summerA = $summerB = 0.0;
26 
27  // Loop through arguments
28  $aArgs = Functions::flattenArray($args);
29  $aCount = 0;
30  foreach ($aArgs as $arg) {
31  $arg = self::datatypeAdjustmentBooleans($arg);
32 
33  // Is it a numeric value?
34  if ((is_numeric($arg)) && (!is_string($arg))) {
35  $summerA += ($arg * $arg);
36  $summerB += $arg;
37  ++$aCount;
38  }
39  }
40 
41  if ($aCount > 1) {
42  $summerA *= $aCount;
43  $summerB *= $summerB;
44 
45  return ($summerA - $summerB) / ($aCount * ($aCount - 1));
46  }
47 
48  return $returnValue;
49  }
50 
63  public static function VARA(...$args)
64  {
65  $returnValue = Functions::DIV0();
66 
67  $summerA = $summerB = 0.0;
68 
69  // Loop through arguments
70  $aArgs = Functions::flattenArrayIndexed($args);
71  $aCount = 0;
72  foreach ($aArgs as $k => $arg) {
73  if ((is_string($arg)) && (Functions::isValue($k))) {
74  return Functions::VALUE();
75  } elseif ((is_string($arg)) && (!Functions::isMatrixValue($k))) {
76  } else {
77  // Is it a numeric value?
78  if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) & ($arg != '')))) {
79  $arg = self::datatypeAdjustmentAllowStrings($arg);
80  $summerA += ($arg * $arg);
81  $summerB += $arg;
82  ++$aCount;
83  }
84  }
85  }
86 
87  if ($aCount > 1) {
88  $summerA *= $aCount;
89  $summerB *= $summerB;
90 
91  return ($summerA - $summerB) / ($aCount * ($aCount - 1));
92  }
93 
94  return $returnValue;
95  }
96 
109  public static function VARP(...$args)
110  {
111  // Return value
112  $returnValue = Functions::DIV0();
113 
114  $summerA = $summerB = 0.0;
115 
116  // Loop through arguments
117  $aArgs = Functions::flattenArray($args);
118  $aCount = 0;
119  foreach ($aArgs as $arg) {
120  $arg = self::datatypeAdjustmentBooleans($arg);
121 
122  // Is it a numeric value?
123  if ((is_numeric($arg)) && (!is_string($arg))) {
124  $summerA += ($arg * $arg);
125  $summerB += $arg;
126  ++$aCount;
127  }
128  }
129 
130  if ($aCount > 0) {
131  $summerA *= $aCount;
132  $summerB *= $summerB;
133 
134  return ($summerA - $summerB) / ($aCount * $aCount);
135  }
136 
137  return $returnValue;
138  }
139 
152  public static function VARPA(...$args)
153  {
154  $returnValue = Functions::DIV0();
155 
156  $summerA = $summerB = 0.0;
157 
158  // Loop through arguments
159  $aArgs = Functions::flattenArrayIndexed($args);
160  $aCount = 0;
161  foreach ($aArgs as $k => $arg) {
162  if ((is_string($arg)) && (Functions::isValue($k))) {
163  return Functions::VALUE();
164  } elseif ((is_string($arg)) && (!Functions::isMatrixValue($k))) {
165  } else {
166  // Is it a numeric value?
167  if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) & ($arg != '')))) {
168  $arg = self::datatypeAdjustmentAllowStrings($arg);
169  $summerA += ($arg * $arg);
170  $summerB += $arg;
171  ++$aCount;
172  }
173  }
174  }
175 
176  if ($aCount > 0) {
177  $summerA *= $aCount;
178  $summerB *= $summerB;
179 
180  return ($summerA - $summerB) / ($aCount * $aCount);
181  }
182 
183  return $returnValue;
184  }
185 }
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
Definition: Functions.php:583
static flattenArrayIndexed($array)
Convert a multi-dimensional array to a simple 1-dimensional array, but retain an element of indexing...
Definition: Functions.php:616