[gnumeric] LEVERAGE: move from fn-math to fn-stat



commit 7ce8040a9397a13b8efb2c1aee69504e23f1f086
Author: Morten Welinder <terra gnome org>
Date:   Fri Jan 18 14:53:23 2013 -0500

    LEVERAGE: move from fn-math to fn-stat

 doc/C/func.defs               |    8 ++++++
 doc/C/functions.xml           |   30 +++++++++++++++++++++
 plugins/fn-math/functions.c   |   57 -----------------------------------------
 plugins/fn-math/plugin.xml.in |    1 -
 plugins/fn-stat/functions.c   |   57 +++++++++++++++++++++++++++++++++++++++++
 plugins/fn-stat/plugin.xml.in |    1 +
 6 files changed, 96 insertions(+), 58 deletions(-)
---
diff --git a/doc/C/func.defs b/doc/C/func.defs
index c1877a0..2a099e0 100644
--- a/doc/C/func.defs
+++ b/doc/C/func.defs
@@ -4655,6 +4655,14 @@ GROWTH returns an array having one column and a row for each data point in @{new
 @SEEALSO=PERCENTILE,PERCENTRANK,QUARTILE,SMALL
 
 @CATEGORY=Statistics
+ FUNCTION=LEVERAGE
+ SHORTDESC=calculate regression leverage
+ SYNTAX=LEVERAGE(A)
+ ARGUMENTDESCRIPTION=@{A}: a matrix
+ DESCRIPTION=Returns the diagonal of @{A} (@{A}^T @{A})^-1 @{A}T as a column vector.
+ NOTE=If the matrix is singular, #VALUE! is returned.
+
+ CATEGORY=Statistics
 @FUNCTION=LINEST
 @SHORTDESC=multiple linear regression coefficients and statistics
 @SYNTAX=LINEST(known_ys,known_xs,affine,stats)
diff --git a/doc/C/functions.xml b/doc/C/functions.xml
index 4d546f6..e92e9d7 100644
--- a/doc/C/functions.xml
+++ b/doc/C/functions.xml
@@ -16087,6 +16087,36 @@
       </para>
       </refsect1>
     </refentry>
+    <refentry id="gnumeric-function-LEVERAGE">
+      <refmeta>
+        <refentrytitle>
+          <function>LEVERAGE</function>
+        </refentrytitle>
+      </refmeta>
+      <refnamediv>
+        <refname>
+          <function>LEVERAGE</function>
+        </refname>
+        <refpurpose>
+        calculate regression leverage
+      </refpurpose>
+      </refnamediv>
+      <refsynopsisdiv>
+        <synopsis><function>LEVERAGE</function>(<parameter>A</parameter>)</synopsis>
+      </refsynopsisdiv>
+      <refsect1>
+        <title>Arguments</title>
+        <para><parameter>A</parameter>: a matrix</para>
+      </refsect1>
+      <refsect1>
+        <title>Description</title>
+        <para>Returns the diagonal of <parameter>A</parameter> (<parameter>A</parameter>^T <parameter>A</parameter>)^-1 <parameter>A</parameter>T as a column vector.</para>
+      </refsect1>
+      <refsect1>
+        <title>Note</title>
+        <para>If the matrix is singular, #VALUE! is returned.</para>
+      </refsect1>
+    </refentry>
     <refentry id="gnumeric-function-LINEST">
       <refmeta>
         <refentrytitle>
diff --git a/plugins/fn-math/functions.c b/plugins/fn-math/functions.c
index 174f330..cd0bf1e 100644
--- a/plugins/fn-math/functions.c
+++ b/plugins/fn-math/functions.c
@@ -2869,60 +2869,6 @@ out:
 
 /***************************************************************************/
 
-static GnmFuncHelp const help_leverage[] = {
-        { GNM_FUNC_HELP_NAME, F_("LEVERAGE:calculate regression leverage")},
-        { GNM_FUNC_HELP_ARG, F_("A:a matrix")},
-	{ GNM_FUNC_HELP_DESCRIPTION,
-	  F_("Returns the diagonal of @{A} (@{A}^T @{A})^-1 @{A}T as a column vector.") },
-	{ GNM_FUNC_HELP_NOTE, F_("If the matrix is singular, #VALUE! is returned.") },
-        { GNM_FUNC_HELP_END}
-};
-
-
-static GnmValue *
-gnumeric_leverage (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
-{
-	GnmMatrix *A = NULL;
-	GnmValue *res = NULL;
-	GORegressionResult regres;
-	gnm_float *x;
-
-	A = gnm_matrix_from_value (argv[0], &res, ei->pos);
-	if (!A) goto out;
-
-	if (gnm_matrix_is_empty (A)) {
-		res = value_new_error_VALUE (ei->pos);
-		goto out;
-	}
-
-	x = g_new (gnm_float, A->rows);
-
-	regres = gnm_linear_regression_leverage (A->data, x, A->rows, A->cols);
-
-	if (regres != GO_REG_ok && regres != GO_REG_near_singular_good) {
-		res = value_new_error_NUM (ei->pos);
-	} else {
-		int x_rows = A->rows, x_cols = 1;
-		int c, r;
-
-		res = value_new_array_non_init (x_cols, x_rows);
-		for (c = 0; c < x_cols; c++) {
-			res->v_array.vals[c] = g_new (GnmValue *, x_rows);
-			for (r = 0; r < x_rows; r++)
-				res->v_array.vals[c][r] =
-					value_new_float (x[r]);
-		}
-	}
-
-	g_free (x);
-
-out:
-	if (A) gnm_matrix_free (A);
-	return res;
-}
-
-/***************************************************************************/
-
 static GnmFuncHelp const help_linsolve[] = {
         { GNM_FUNC_HELP_NAME, F_("LINSOLVE:solve linear equation")},
         { GNM_FUNC_HELP_ARG, F_("mat:a matrix")},
@@ -3555,9 +3501,6 @@ GnmFuncDescriptor const math_functions[] = {
 	{ "minverse","A",      help_minverse,
 	  gnumeric_minverse, NULL, NULL, NULL,
 	  GNM_FUNC_RETURNS_NON_SCALAR, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
-	{ "leverage", "A",  help_leverage,
-	  gnumeric_leverage, NULL, NULL, NULL,
-	  GNM_FUNC_RETURNS_NON_SCALAR, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
 	{ "linsolve", "AA",  help_linsolve,
 	  gnumeric_linsolve, NULL, NULL, NULL,
 	  GNM_FUNC_RETURNS_NON_SCALAR, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
diff --git a/plugins/fn-math/plugin.xml.in b/plugins/fn-math/plugin.xml.in
index e266b6d..457df3e 100644
--- a/plugins/fn-math/plugin.xml.in
+++ b/plugins/fn-math/plugin.xml.in
@@ -54,7 +54,6 @@
 				<function name="hypot"/>
 				<function name="int"/>
 				<function name="lcm"/>
-				<function name="leverage"/>
 				<function name="linsolve"/>
 				<function name="ln"/>
 				<function name="ln1p"/>
diff --git a/plugins/fn-stat/functions.c b/plugins/fn-stat/functions.c
index 2a3c0bf..eedbece 100644
--- a/plugins/fn-stat/functions.c
+++ b/plugins/fn-stat/functions.c
@@ -3129,6 +3129,60 @@ gnumeric_frequency (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 
 /***************************************************************************/
 
+static GnmFuncHelp const help_leverage[] = {
+        { GNM_FUNC_HELP_NAME, F_("LEVERAGE:calculate regression leverage")},
+        { GNM_FUNC_HELP_ARG, F_("A:a matrix")},
+	{ GNM_FUNC_HELP_DESCRIPTION,
+	  F_("Returns the diagonal of @{A} (@{A}^T @{A})^-1 @{A}T as a column vector.") },
+	{ GNM_FUNC_HELP_NOTE, F_("If the matrix is singular, #VALUE! is returned.") },
+        { GNM_FUNC_HELP_END}
+};
+
+
+static GnmValue *
+gnumeric_leverage (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
+{
+	GnmMatrix *A = NULL;
+	GnmValue *res = NULL;
+	GORegressionResult regres;
+	gnm_float *x;
+
+	A = gnm_matrix_from_value (argv[0], &res, ei->pos);
+	if (!A) goto out;
+
+	if (gnm_matrix_is_empty (A)) {
+		res = value_new_error_VALUE (ei->pos);
+		goto out;
+	}
+
+	x = g_new (gnm_float, A->rows);
+
+	regres = gnm_linear_regression_leverage (A->data, x, A->rows, A->cols);
+
+	if (regres != GO_REG_ok && regres != GO_REG_near_singular_good) {
+		res = value_new_error_NUM (ei->pos);
+	} else {
+		int x_rows = A->rows, x_cols = 1;
+		int c, r;
+
+		res = value_new_array_non_init (x_cols, x_rows);
+		for (c = 0; c < x_cols; c++) {
+			res->v_array.vals[c] = g_new (GnmValue *, x_rows);
+			for (r = 0; r < x_rows; r++)
+				res->v_array.vals[c][r] =
+					value_new_float (x[r]);
+		}
+	}
+
+	g_free (x);
+
+out:
+	if (A) gnm_matrix_free (A);
+	return res;
+}
+
+/***************************************************************************/
+
 /* Notes for now, to be incorporated into help when it actually works:
  *
  * Entered as linest(Yrange, [Xrange, [Intercept, [Stat]]]). Intercept and Stat
@@ -5029,6 +5083,9 @@ GnmFuncDescriptor const stat_functions[] = {
 	  help_large, gnumeric_large, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE + GNM_FUNC_AUTO_FIRST,
 	  GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
+	{ "leverage", "A",  help_leverage,
+	  gnumeric_leverage, NULL, NULL, NULL,
+	  GNM_FUNC_RETURNS_NON_SCALAR, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE },
 	{ "linest",       "A|Abb",
 	  help_linest, gnumeric_linest, NULL, NULL, NULL,
 	  GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
diff --git a/plugins/fn-stat/plugin.xml.in b/plugins/fn-stat/plugin.xml.in
index 020db5b..b8b1f5f 100644
--- a/plugins/fn-stat/plugin.xml.in
+++ b/plugins/fn-stat/plugin.xml.in
@@ -59,6 +59,7 @@
 				<function name="landau"/>
 				<function name="laplace"/>
 				<function name="large"/>
+				<function name="leverage"/>
 				<function name="linest"/>
 				<function name="lkstest"/>
 				<function name="logest"/>



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