[gnumeric] TDIST: fix problem with negative x.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] TDIST: fix problem with negative x.
- Date: Fri, 9 Apr 2010 13:23:43 +0000 (UTC)
commit d79d15242d61956209dd760195366719cfa46122
Author: Morten Welinder <terra gnome org>
Date: Fri Apr 9 09:13:08 2010 -0400
TDIST: fix problem with negative x.
doc/C/func.defs | 14 ++++++++------
doc/C/functions.xml | 20 ++++++++++++++------
plugins/fn-stat/functions.c | 27 ++++++++++++++++++++++-----
3 files changed, 44 insertions(+), 17 deletions(-)
---
diff --git a/doc/C/func.defs b/doc/C/func.defs
index ef29a89..beaaa0a 100644
--- a/doc/C/func.defs
+++ b/doc/C/func.defs
@@ -2889,7 +2889,7 @@ If any argument is zero, the result is zero.
@SYNTAX=MATCH(seek,vector,type)
@ARGUMENTDESCRIPTION= {seek}: value to find
@{vector}: n by 1 or 1 by n range to be searched
- {type}: +1 to find the largest value â?¤ @{seek}, 0 to find the first value = @{seek}, or-1 to find the smallest value â?¥ @{seek}
+ {type}: +1 (the default) to find the largest value â?¤ @{seek}, 0 to find the first value = @{seek}, or-1 to find the smallest value â?¥ @{seek}
@DESCRIPTION=MATCH searches @{vector} for @{seek} and returns the 1-based index.
@NOTE= For @{type} = -1 the data must be sorted in descending order; for @{type} = +1 the data must be sorted in ascending order. If @{seek} could not be found, #N/A is returned. If @{vector} is neither n by 1 nor 1 by n, #N/A is returned.
@SEEALSO=LOOKUP
@@ -4798,7 +4798,7 @@ If the data set does not contain any duplicates this function returns a #N/A err
@ARGUMENTDESCRIPTION= {x}: total number of objects
@{y}: number of selected objects
@NOTE=If both @{x} and @{y} equal 0, PERMUTATIONA returns 1. If @{x} < 0 or @{y} < 0, PERMUTATIONA returns #NUM! If @{x} or @{y} are not integers, they are truncated
- ODF=This function is ODF compatible.
+ ODF=This function is OpenFormula compatible.
@SEEALSO=POWER
@CATEGORY=Statistics
@@ -5586,7 +5586,7 @@ Numbers, text and logical values are included in the calculation too. If the cel
@SYNTAX=TDIST(x,dof,tails)
@ARGUMENTDESCRIPTION= {x}:
@{dof}: number of degrees of freedom
- {tails}: 1 or 2. If this is 2, @{x} is replaced by the absolute value and the returned value is multiplied by 2
+ {tails}: 1 or 2.
@DESCRIPTION=The survival function is 1 minus the cumulative distribution function.
This function is Excel compatible for non-negative @{x}.
@NOTE=If @{dof} < 1 this function returns a #NUM! error. If @{tails} is neither 1 or 2 this function returns a #NUM! error. The parameterization of this function is different from what is used for, e.g., NORMSDIST. This is a common source of mistakes, but necessary for compatibility.
@@ -5695,13 +5695,15 @@ Numbers, text and logical values are included in the calculation too. If the cel
@CATEGORY=Statistics
@FUNCTION=ZTEST
- SHORTDESC=p-value of a 2-tailed z-test for a population mean
+ SHORTDESC=the probability of observing a sample mean as large as or larger than the mean of the given sample
@SYNTAX=ZTEST(ref,x,stddev)
- ARGUMENTDESCRIPTION=@{ref}: data set
- {x}: mean as given in the null hypothesis
+ ARGUMENTDESCRIPTION=@{ref}: data set (sample)
+ {x}: population mean
@{stddev}: population standard deviation, defaults to the sample standard deviation
+ DESCRIPTION=ZTEST calulates the probability of observing a sample mean as large as or larger than the mean of the given sample for samples drawn from a normal distribution with mean @{x} and standard deviation @{stddev}.
@NOTE=If @{ref} contains less than two data items ZTEST returns #DIV/0! error.
@EXCEL=This function is Excel compatible.
+ ODF=This function is OpenFormula compatible.
@SEEALSO=CONFIDENCE,NORMDIST,NORMINV,NORMSDIST,NORMSINV,STANDARDIZE
@CATEGORY=String
diff --git a/doc/C/functions.xml b/doc/C/functions.xml
index 00cdfc7..65a286b 100644
--- a/doc/C/functions.xml
+++ b/doc/C/functions.xml
@@ -9481,7 +9481,7 @@
<title>Arguments</title>
<para><parameter>seek</parameter>: value to find</para>
<para><parameter>vector</parameter>: n by 1 or 1 by n range to be searched</para>
- <para><parameter>type</parameter>: +1 to find the largest value â?¤ <parameter>seek</parameter>, 0 to find the first value = <parameter>seek</parameter>, or-1 to find the smallest value â?¥ <parameter>seek</parameter></para>
+ <para><parameter>type</parameter>: +1 (the default) to find the largest value â?¤ <parameter>seek</parameter>, 0 to find the first value = <parameter>seek</parameter>, or-1 to find the smallest value â?¥ <parameter>seek</parameter></para>
</refsect1>
<refsect1>
<title>Description</title>
@@ -16631,7 +16631,7 @@
</refsect1>
<refsect1>
<title>OpenDocument Format (ODF) Compatibility</title>
- <para>This function is ODF compatible.</para>
+ <para>This function is OpenFormula compatible.</para>
</refsect1>
<refsect1>
<title>See also</title>
@@ -19168,7 +19168,7 @@
<title>Arguments</title>
<para><parameter>x</parameter>: </para>
<para><parameter>dof</parameter>: number of degrees of freedom</para>
- <para><parameter>tails</parameter>: 1 or 2. If this is 2, <parameter>x</parameter> is replaced by the absolute value and the returned value is multiplied by 2</para>
+ <para><parameter>tails</parameter>: 1 or 2.</para>
</refsect1>
<refsect1>
<title>Description</title>
@@ -19552,7 +19552,7 @@
<function>ZTEST</function>
</refname>
<refpurpose>
- p-value of a 2-tailed z-test for a population mean
+ the probability of observing a sample mean as large as or larger than the mean of the given sample
</refpurpose>
</refnamediv>
<refsynopsisdiv>
@@ -19560,11 +19560,15 @@
</refsynopsisdiv>
<refsect1>
<title>Arguments</title>
- <para><parameter>ref</parameter>: data set</para>
- <para><parameter>x</parameter>: mean as given in the null hypothesis</para>
+ <para><parameter>ref</parameter>: data set (sample)</para>
+ <para><parameter>x</parameter>: population mean</para>
<para><parameter>stddev</parameter>: population standard deviation, defaults to the sample standard deviation</para>
</refsect1>
<refsect1>
+ <title>Description</title>
+ <para><function>ZTEST</function> calulates the probability of observing a sample mean as large as or larger than the mean of the given sample for samples drawn from a normal distribution with mean <parameter>x</parameter> and standard deviation <parameter>stddev</parameter>.</para>
+ </refsect1>
+ <refsect1>
<title>Note</title>
<para>If <parameter>ref</parameter> contains less than two data items <function>ZTEST</function> returns #DIV/0! error.</para>
</refsect1>
@@ -19573,6 +19577,10 @@
<para>This function is Excel compatible.</para>
</refsect1>
<refsect1>
+ <title>OpenDocument Format (ODF) Compatibility</title>
+ <para>This function is OpenFormula compatible.</para>
+ </refsect1>
+ <refsect1>
<title>See also</title>
<para><link linkend="gnumeric-CONFIDENCE"><function>CONFIDENCE</function></link>,
<link linkend="gnumeric-NORMDIST"><function>NORMDIST</function></link>,
diff --git a/plugins/fn-stat/functions.c b/plugins/fn-stat/functions.c
index 8a19108..2e8930b 100644
--- a/plugins/fn-stat/functions.c
+++ b/plugins/fn-stat/functions.c
@@ -1188,8 +1188,7 @@ static GnmFuncHelp const help_tdist[] = {
{ GNM_FUNC_HELP_NAME, F_("TDIST:survival function of the Student t-distribution")},
{ GNM_FUNC_HELP_ARG, F_("x:")},
{ GNM_FUNC_HELP_ARG, F_("dof:number of degrees of freedom")},
- { GNM_FUNC_HELP_ARG, F_("tails:1 or 2. If this is 2, @{x} is replaced by the absolute value and "
- "the returned value is multiplied by 2")},
+ { GNM_FUNC_HELP_ARG, F_("tails:1 or 2.")},
{ GNM_FUNC_HELP_DESCRIPTION, F_("The survival function is 1 minus the cumulative distribution function.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{dof} < 1 this function returns a #NUM! error.") },
{ GNM_FUNC_HELP_NOTE, F_("If @{tails} is neither 1 or 2 this function returns a #NUM! error.") },
@@ -1210,11 +1209,29 @@ gnumeric_tdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
gnm_float x = value_get_as_float (argv[0]);
gnm_float dof = value_get_as_float (argv[1]);
int tails = value_get_as_int (argv[2]);
+ gnm_float p;
- if (x < 0 || dof < 1 || (tails != 1 && tails != 2))
- return value_new_error_NUM (ei->pos);
+ if (dof < 1)
+ goto bad;
+
+ if (tails == 1) {
+ gboolean lower_tail = FALSE;
+ if (x < 0) {
+ lower_tail = TRUE;
+ x = -x;
+ }
+ p = pt (x, dof, lower_tail, FALSE);
+ } else if (tails == 2) {
+ if (x < 0)
+ goto bad;
+ p = 2 * pt (x, dof, FALSE, FALSE);
+ } else
+ goto bad;
+
+ return value_new_float (p);
- return value_new_float (tails * pt (x, dof, FALSE, FALSE));
+ bad:
+ return value_new_error_NUM (ei->pos);
}
/***************************************************************************/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]