[gnumeric] Fix CHITEST for rectangular ranges. [#615920]



commit 33205aac7ababef7469822c5356f236f2867f3d2
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Fri Apr 16 21:54:53 2010 -0600

    Fix CHITEST for rectangular ranges. [#615920]
    
    2010-04-16  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* functions.c (gnumeric_chitest): correct df in rectangular case
    	(help_chitest): change docs to reflect changed df

 NEWS                        |    3 +++
 plugins/fn-stat/ChangeLog   |    5 +++++
 plugins/fn-stat/functions.c |   11 ++++++-----
 3 files changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/NEWS b/NEWS
index 389f8d3..ecca0c9 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 Gnumeric 1.10.3
 
+Andreas:
+	* Fix CHITEST for rectangular ranges. [#615920]
+
 --------------------------------------------------------------------------
 Gnumeric 1.10.2
 
diff --git a/plugins/fn-stat/ChangeLog b/plugins/fn-stat/ChangeLog
index ee54e45..f04f1d1 100644
--- a/plugins/fn-stat/ChangeLog
+++ b/plugins/fn-stat/ChangeLog
@@ -1,3 +1,8 @@
+2010-04-16  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* functions.c (gnumeric_chitest): correct df in rectangular case
+	(help_chitest): change docs to reflect changed df
+
 2010-04-16  Morten Welinder <terra gnome org>
 
 	* Release 1.10.2
diff --git a/plugins/fn-stat/functions.c b/plugins/fn-stat/functions.c
index 5435bf4..ae5c3a8 100644
--- a/plugins/fn-stat/functions.c
+++ b/plugins/fn-stat/functions.c
@@ -1031,7 +1031,10 @@ static GnmFuncHelp const help_chitest[] = {
 	{ GNM_FUNC_HELP_ARG, F_("actual_range:observed data")},
 	{ GNM_FUNC_HELP_ARG, F_("theoretical_range:expected values")},
 	{ GNM_FUNC_HELP_NOTE, F_("If the actual range is not an n by 1 or 1 by n range, "
-				 "the returned value appears to have no sensible meaning.")},
+				 "but an n by m range, then CHITEST uses (n-1) times (m-1) as "
+				 "degrees of freedom. This is useful if the expected values "
+				 "were calculated from the observed value in a test of "
+				 "independence or test of homogeneity.")},
 	{ GNM_FUNC_HELP_EXCEL, F_("This function is Excel compatible.") },
 	{ GNM_FUNC_HELP_ODF, F_("CHITEST is the OpenFormula function LEGACY.CHITEST.") },
 	{ GNM_FUNC_HELP_SEEALSO, "CHIDIST,CHIINV"},
@@ -1103,10 +1106,8 @@ gnumeric_chitest (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 	if (chisq == -1)
 		return value_new_error_NUM (ei->pos);
 
-	/* FIXME : XL docs claim df = (r-1)(c-1) not (r-1),
-	 * However, that makes no sense.
-	 */
-	df = (h0 == 1 ? w0 - 1 : h0 - 1);
+	df = (w0-1) * (h0-1);
+	df = (df == 0 ? w0 * h0 - 1 : df);
 	return value_new_float (pchisq (chisq, df, FALSE, FALSE));
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]