aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-06-05 20:36:22 +0000
committerPJ Fanning <fanningpj@apache.org>2022-06-05 20:36:22 +0000
commit1bae0a43bfa4393715143c8e0db41ad5201fae5d (patch)
tree76b708d6514ec56d7fae8c09e29d5f2de3a86603 /poi
parent41dfbd67c5900ef313149c2090dc92e40b4a95d0 (diff)
downloadpoi-1bae0a43bfa4393715143c8e0db41ad5201fae5d.tar.gz
poi-1bae0a43bfa4393715143c8e0db41ad5201fae5d.zip
add PEARSON function
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1901688 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java2
-rw-r--r--poi/src/test/java/org/apache/poi/ss/formula/functions/TestCorrel.java24
2 files changed, 25 insertions, 1 deletions
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java b/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java
index 5e00aaff03..c544d4680a 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java
@@ -292,7 +292,7 @@ public final class FunctionEval {
// 309: FORECAST
// 310: FTEST
retval[311] = new Intercept();
- // 312: PEARSON
+ retval[312] = Correl.instance;
// 313: RSQ
// 314: STEYX
retval[315] = new Slope();
diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestCorrel.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestCorrel.java
index 384cbdf561..3be25d2c23 100644
--- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestCorrel.java
+++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestCorrel.java
@@ -48,6 +48,18 @@ final class TestCorrel {
}
}
+ //https://support.microsoft.com/en-us/office/pearson-function-0c3e30fc-e5af-49c4-808a-3ef66e034c18
+ @Test
+ void testPearsonExample1() throws IOException {
+ try (HSSFWorkbook wb = initWorkbook2()) {
+ HSSFSheet sheet = wb.getSheetAt(0);
+ HSSFRow row = sheet.getRow(0);
+ HSSFCell cell = row.createCell(100);
+ HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb);
+ assertDouble(fe, cell, "CORREL(A2:A6,B2:B6)", 0.699379, 0.0000005);
+ assertDouble(fe, cell, "PEARSON(A2:A6,B2:B6)", 0.699379, 0.0000005);
+ }
+ }
@Test
void testBlankValue() throws IOException {
try (HSSFWorkbook wb = initWorkbook1(null)) {
@@ -97,4 +109,16 @@ final class TestCorrel {
addRow(sheet, 5, 6, 17);
return wb;
}
+
+ private HSSFWorkbook initWorkbook2() {
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFSheet sheet = wb.createSheet();
+ addRow(sheet, 0, "Independent values", "Dependent values");
+ addRow(sheet, 1, 9, 10);
+ addRow(sheet, 2, 7, 6);
+ addRow(sheet, 3, 5, 1);
+ addRow(sheet, 4, 3, 5);
+ addRow(sheet, 5, 1, 3);
+ return wb;
+ }
}