13 foreach ($array1 as
$key => $value) {
14 if ((is_bool($value)) || (is_string($value)) || ($value === null)) {
15 unset($array1[
$key], $array2[$key]);
22 if (!is_array($array1)) {
25 if (!is_array($array2)) {
32 self::filterTrendValues($array1, $array2);
33 self::filterTrendValues($array2, $array1);
36 $array1 = array_merge($array1);
37 $array2 = array_merge($array2);
42 $yValueCount = count($yValues);
43 $xValueCount = count($xValues);
45 if (($yValueCount === 0) || ($yValueCount !== $xValueCount)) {
47 } elseif ($yValueCount === 1) {
62 public static function CORREL($yValues, $xValues = null)
64 if (($xValues === null) || (!is_array($yValues)) || (!is_array($xValues))) {
69 self::checkTrendArrays($yValues, $xValues);
70 self::validateTrendArrays($yValues, $xValues);
72 return $e->getMessage();
77 return $bestFitLinear->getCorrelation();
90 public static function COVAR($yValues, $xValues)
93 self::checkTrendArrays($yValues, $xValues);
94 self::validateTrendArrays($yValues, $xValues);
96 return $e->getMessage();
101 return $bestFitLinear->getCovariance();
116 public static function FORECAST($xValue, $yValues, $xValues)
122 self::checkTrendArrays($yValues, $xValues);
123 self::validateTrendArrays($yValues, $xValues);
125 return $e->getMessage();
130 return $bestFitLinear->getValueOfYForX($xValue);
145 public static function GROWTH($yValues, $xValues = [], $newValues = [], $const =
true)
153 if (empty($newValues)) {
154 $newValues = $bestFitExponential->getXValues();
158 foreach ($newValues as $xValue) {
159 $returnArray[0][] = [$bestFitExponential->getValueOfYForX($xValue)];
178 self::checkTrendArrays($yValues, $xValues);
179 self::validateTrendArrays($yValues, $xValues);
181 return $e->getMessage();
186 return $bestFitLinear->getIntersect();
202 public static function LINEST($yValues, $xValues = null, $const =
true,
$stats =
false)
206 if ($xValues === null) {
211 self::checkTrendArrays($yValues, $xValues);
212 self::validateTrendArrays($yValues, $xValues);
214 return $e->getMessage();
222 $bestFitLinear->getSlope(),
223 $bestFitLinear->getIntersect(),
226 $bestFitLinear->getSlopeSE(),
227 ($const ===
false) ?
Functions::NA() : $bestFitLinear->getIntersectSE(),
230 $bestFitLinear->getGoodnessOfFit(),
231 $bestFitLinear->getStdevOfResiduals(),
234 $bestFitLinear->getF(),
235 $bestFitLinear->getDFResiduals(),
238 $bestFitLinear->getSSRegression(),
239 $bestFitLinear->getSSResiduals(),
245 $bestFitLinear->getSlope(),
246 $bestFitLinear->getIntersect(),
263 public static function LOGEST($yValues, $xValues = null, $const =
true,
$stats =
false)
267 if ($xValues === null) {
272 self::checkTrendArrays($yValues, $xValues);
273 self::validateTrendArrays($yValues, $xValues);
275 return $e->getMessage();
278 foreach ($yValues as $value) {
289 $bestFitExponential->getSlope(),
290 $bestFitExponential->getIntersect(),
293 $bestFitExponential->getSlopeSE(),
294 ($const ===
false) ?
Functions::NA() : $bestFitExponential->getIntersectSE(),
297 $bestFitExponential->getGoodnessOfFit(),
298 $bestFitExponential->getStdevOfResiduals(),
301 $bestFitExponential->getF(),
302 $bestFitExponential->getDFResiduals(),
305 $bestFitExponential->getSSRegression(),
306 $bestFitExponential->getSSResiduals(),
312 $bestFitExponential->getSlope(),
313 $bestFitExponential->getIntersect(),
328 public static function RSQ($yValues, $xValues)
331 self::checkTrendArrays($yValues, $xValues);
332 self::validateTrendArrays($yValues, $xValues);
334 return $e->getMessage();
339 return $bestFitLinear->getGoodnessOfFit();
352 public static function SLOPE($yValues, $xValues)
355 self::checkTrendArrays($yValues, $xValues);
356 self::validateTrendArrays($yValues, $xValues);
358 return $e->getMessage();
363 return $bestFitLinear->getSlope();
376 public static function STEYX($yValues, $xValues)
379 self::checkTrendArrays($yValues, $xValues);
380 self::validateTrendArrays($yValues, $xValues);
382 return $e->getMessage();
387 return $bestFitLinear->getStdevOfResiduals();
402 public static function TREND($yValues, $xValues = [], $newValues = [], $const =
true)
410 if (empty($newValues)) {
411 $newValues = $bestFitLinear->getXValues();
415 foreach ($newValues as $xValue) {
416 $returnArray[0][] = [$bestFitLinear->getValueOfYForX($xValue)];
static FORECAST($xValue, $yValues, $xValues)
FORECAST.
static STEYX($yValues, $xValues)
STEYX.
static validateTrendArrays(array $yValues, array $xValues)
static TREND($yValues, $xValues=[], $newValues=[], $const =true)
TREND.
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
static calculate($trendType=self::TREND_BEST_FIT, $yValues=[], $xValues=[], $const =true)
static INTERCEPT($yValues, $xValues)
INTERCEPT.
static LINEST($yValues, $xValues=null, $const =true, $stats=false)
LINEST.
static RSQ($yValues, $xValues)
RSQ.
static CORREL($yValues, $xValues=null)
CORREL.
static checkTrendArrays(&$array1, &$array2)
static GROWTH($yValues, $xValues=[], $newValues=[], $const =true)
GROWTH.
static validateFloat($value)
static SLOPE($yValues, $xValues)
SLOPE.
static COVAR($yValues, $xValues)
COVAR.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
static LOGEST($yValues, $xValues=null, $const =true, $stats=false)
LOGEST.
static filterTrendValues(array &$array1, array &$array2)