-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chi squared inverse left tailed (#1964)
* Implementation of the CHISQ.INV() method for ChiSquared distribution left-tail
- Loading branch information
Mark Baker
authored
Mar 28, 2021
1 parent
e2ff14f
commit e68978f
Showing
5 changed files
with
234 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ChiInvLeftTailTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical; | ||
|
||
use PhpOffice\PhpSpreadsheet\Calculation\Functions; | ||
use PhpOffice\PhpSpreadsheet\Calculation\Statistical; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ChiInvLeftTailTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); | ||
} | ||
|
||
/** | ||
* @dataProvider providerCHIINV | ||
* | ||
* @param mixed $expectedResult | ||
* @param mixed $probability | ||
* @param mixed $degrees | ||
*/ | ||
public function testCHIINV($expectedResult, $probability, $degrees): void | ||
{ | ||
$result = Statistical\Distributions\ChiSquared::inverseLeftTail($probability, $degrees); | ||
if (!is_string($expectedResult)) { | ||
$reverse = Statistical\Distributions\ChiSquared::distributionLeftTail($result, $degrees, true); | ||
self::assertEqualsWithDelta($probability, $reverse, 1E-12); | ||
} | ||
self::assertEqualsWithDelta($expectedResult, $result, 1E-12); | ||
} | ||
|
||
public function providerCHIINV() | ||
{ | ||
return require 'tests/data/Calculation/Statistical/CHIINVLeftTail.php'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
return [ | ||
[ | ||
4.671330448981, | ||
0.3, 7, | ||
], | ||
[ | ||
12.548861396889, | ||
0.75, 10, | ||
], | ||
[ | ||
3.283020286760, | ||
0.93, 1, | ||
], | ||
[ | ||
1.832581463748, | ||
0.6, 2, | ||
], | ||
[ | ||
0.454936423120, | ||
0.5, 1, | ||
], | ||
[ | ||
4.351460191096, | ||
0.5, 5, | ||
], | ||
[ | ||
1.323303696932, | ||
0.75, 1, | ||
], | ||
[ | ||
0.210721031316, | ||
0.1, 2, | ||
], | ||
[ | ||
3.218875824869, | ||
0.8, 2, | ||
], | ||
[ | ||
1.212532903046, | ||
0.25, 3, | ||
], | ||
[ | ||
'#VALUE!', | ||
'NaN', 3, | ||
], | ||
[ | ||
'#VALUE!', | ||
0.25, 'NaN', | ||
], | ||
'Probability < 0' => [ | ||
'#NUM!', | ||
-0.1, 3, | ||
], | ||
'Probability > 1' => [ | ||
'#NUM!', | ||
1.1, 3, | ||
], | ||
'Freedom > 1' => [ | ||
'#NUM!', | ||
0.1, 0.5, | ||
], | ||
]; |