Additional statistical work (#1088)
* Merge branch 'master' of C:\Projects\PHPOffice\PHPSpreadsheet\develop with conflicts. * More statistical tests * Further statistical tests * Unit tests for some of the trend functions * resolve scrutiniser objections * Fix order of @return types :-(
This commit is contained in:
parent
f1e82a212f
commit
6d739f1fe6
|
@ -596,11 +596,7 @@ class Statistical
|
|||
}
|
||||
// Is it a numeric value?
|
||||
if ((is_numeric($arg)) && (!is_string($arg))) {
|
||||
if ($returnValue === null) {
|
||||
$returnValue = $arg;
|
||||
} else {
|
||||
$returnValue += $arg;
|
||||
}
|
||||
++$aCount;
|
||||
}
|
||||
}
|
||||
|
@ -643,11 +639,7 @@ class Statistical
|
|||
} elseif (is_string($arg)) {
|
||||
$arg = 0;
|
||||
}
|
||||
if ($returnValue === null) {
|
||||
$returnValue = $arg;
|
||||
} else {
|
||||
$returnValue += $arg;
|
||||
}
|
||||
++$aCount;
|
||||
}
|
||||
}
|
||||
|
@ -821,7 +813,7 @@ class Statistical
|
|||
* @param float $probability Probability of success on each trial
|
||||
* @param bool $cumulative
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*
|
||||
* @todo Cumulative distribution function
|
||||
*/
|
||||
|
@ -863,7 +855,7 @@ class Statistical
|
|||
* @param float $value Value for the function
|
||||
* @param float $degrees degrees of freedom
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function CHIDIST($value, $degrees)
|
||||
{
|
||||
|
@ -896,7 +888,7 @@ class Statistical
|
|||
* @param float $probability Probability for the function
|
||||
* @param float $degrees degrees of freedom
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function CHIINV($probability, $degrees)
|
||||
{
|
||||
|
@ -955,7 +947,7 @@ class Statistical
|
|||
* @param float $stdDev Standard Deviation
|
||||
* @param float $size
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function CONFIDENCE($alpha, $stdDev, $size)
|
||||
{
|
||||
|
@ -985,7 +977,7 @@ class Statistical
|
|||
* @param mixed $yValues array of mixed Data Series Y
|
||||
* @param null|mixed $xValues array of mixed Data Series X
|
||||
*
|
||||
* @return float
|
||||
* @return float|string
|
||||
*/
|
||||
public static function CORREL($yValues, $xValues = null)
|
||||
{
|
||||
|
@ -1513,7 +1505,7 @@ class Statistical
|
|||
* @param mixed $yValues array of mixed Data Series Y
|
||||
* @param mixed $xValues of mixed Data Series X
|
||||
*
|
||||
* @return float
|
||||
* @return bool|float|string
|
||||
*/
|
||||
public static function FORECAST($xValue, $yValues, $xValues)
|
||||
{
|
||||
|
@ -1692,7 +1684,7 @@ class Statistical
|
|||
/**
|
||||
* GROWTH.
|
||||
*
|
||||
* Returns values along a predicted emponential Trend
|
||||
* Returns values along a predicted exponential Trend
|
||||
*
|
||||
* @param mixed[] $yValues Data Series Y
|
||||
* @param mixed[] $xValues Data Series X
|
||||
|
|
|
@ -109,6 +109,86 @@ class StatisticalTest extends TestCase
|
|||
return require 'data/Calculation/Statistical/BETAINV.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerBINOMDIST
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testBINOMDIST($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::BINOMDIST(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerBINOMDIST()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/BINOMDIST.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerCHIDIST
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testCHIDIST($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::CHIDIST(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerCHIDIST()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/CHIDIST.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerCHIINV
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testCHIINV($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::CHIINV(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerCHIINV()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/CHIINV.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerCONFIDENCE
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testCONFIDENCE($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::CONFIDENCE(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerCONFIDENCE()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/CONFIDENCE.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerCORREL
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testCORREL($expectedResult, array $xargs, array $yargs)
|
||||
{
|
||||
$result = Statistical::CORREL($xargs, $yargs);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerCORREL()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/CORREL.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerCOUNTIF
|
||||
*
|
||||
|
@ -141,6 +221,38 @@ class StatisticalTest extends TestCase
|
|||
return require 'data/Calculation/Statistical/COUNTIFS.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerCOVAR
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testCOVAR($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::COVAR(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerCOVAR()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/COVAR.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerFORECAST
|
||||
*
|
||||
* @param mixed $expectedResult
|
||||
*/
|
||||
public function testFORECAST($expectedResult, ...$args)
|
||||
{
|
||||
$result = Statistical::FORECAST(...$args);
|
||||
self::assertEquals($expectedResult, $result, '', 1E-12);
|
||||
}
|
||||
|
||||
public function providerFORECAST()
|
||||
{
|
||||
return require 'data/Calculation/Statistical/FORECAST.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerMAXIFS
|
||||
*
|
||||
|
|
|
@ -45,4 +45,9 @@ return [
|
|||
[2012, 2012, 2013, 2011, 2011, 2010],
|
||||
"<2013",
|
||||
],
|
||||
[
|
||||
14000,
|
||||
[7000, 14000, 'Hello World', 21000, 28000],
|
||||
"<23000",
|
||||
],
|
||||
];
|
||||
|
|
|
@ -9,4 +9,8 @@ return [
|
|||
0.598190307617,
|
||||
7.5, 8, 9, 5, 10,
|
||||
],
|
||||
[
|
||||
0.685470581054,
|
||||
2, 8, 10, 1, 3,
|
||||
],
|
||||
];
|
||||
|
|
|
@ -9,4 +9,8 @@ return [
|
|||
7.761240188783,
|
||||
0.75, 8, 9, 5, 10,
|
||||
],
|
||||
[
|
||||
2.0,
|
||||
0.685470581055, 8, 10, 1, 3,
|
||||
],
|
||||
];
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
0.706399436132,
|
||||
3, 8, 0.35, true,
|
||||
],
|
||||
[
|
||||
0.538748204875,
|
||||
50, 125, 0.4, true,
|
||||
],
|
||||
[
|
||||
0.278585779062,
|
||||
3, 8, 0.35, false,
|
||||
],
|
||||
[
|
||||
0.205078125,
|
||||
6, 10, 0.5, false,
|
||||
],
|
||||
];
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
0.964294972685,
|
||||
3, 9,
|
||||
],
|
||||
[
|
||||
0.4837673815536,
|
||||
7.5, 8,
|
||||
],
|
||||
[
|
||||
0.050000589092,
|
||||
18.307, 10,
|
||||
],
|
||||
];
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
8.383430828608,
|
||||
0.3, 7,
|
||||
],
|
||||
[
|
||||
6.737200771955,
|
||||
0.75, 10,
|
||||
],
|
||||
[
|
||||
18.30697345702,
|
||||
0.050001, 10,
|
||||
],
|
||||
];
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
0.692951912734,
|
||||
0.05, 2.5, 50,
|
||||
],
|
||||
];
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
0.997054485502,
|
||||
[3, 2, 4, 5, 6],
|
||||
[9, 7, 12, 15, 17],
|
||||
],
|
||||
];
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
5.2,
|
||||
[3, 2, 4, 5, 6],
|
||||
[9, 7, 12, 15, 17],
|
||||
],
|
||||
[
|
||||
1.25,
|
||||
[[1, 2], [3, 4]],
|
||||
[[5, 6], [7, 8]],
|
||||
]
|
||||
];
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
10.607253086419,
|
||||
30,
|
||||
[6, 7, 9, 15, 21],
|
||||
[20, 28, 31, 38, 40],
|
||||
],
|
||||
[
|
||||
11.8937852010975,
|
||||
5,
|
||||
[10.5, 7.2, 200, 5.4, 8.1],
|
||||
[-3, 4, 120, 2, 7.5],
|
||||
],
|
||||
[
|
||||
20.032698660553,
|
||||
10,
|
||||
[10.5, 7.2, 200, 5.4, 8.1],
|
||||
[-3, 4, 120, 2, 7.5],
|
||||
],
|
||||
[
|
||||
5.0,
|
||||
8,
|
||||
[1, 2, 3],
|
||||
[4, 5, 6],
|
||||
],
|
||||
[
|
||||
10.657142857143,
|
||||
7,
|
||||
[5.8, -1],
|
||||
[2, -5],
|
||||
],
|
||||
[
|
||||
-5.0,
|
||||
50,
|
||||
[-1, -2, -3, -4],
|
||||
[10, 20, 30, 40],
|
||||
],
|
||||
];
|
Loading…
Reference in New Issue