[gnumeric] Add R.DST



commit b0117ad37dd792e62dadf8e5ccbeae03466d15a7
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Tue Oct 13 12:15:20 2009 -0600

    Add R.DST
    
    2009-10-13  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* generate: enable dst
    	* extra.c (dst): implement
    	(gnm_owent): add GNM_const
    	* plugin.xml.in: updated due to changes in generate
    	* functions.c: ditto

 NEWS                       |    2 +-
 plugins/fn-r/ChangeLog     |   12 ++++++++-
 plugins/fn-r/extra.c       |   50 ++++++++++++++++++++++---------------------
 plugins/fn-r/functions.c   |   32 ++++++++++++++++++++++++++++
 plugins/fn-r/generate      |   11 +++++----
 plugins/fn-r/plugin.xml.in |    1 +
 6 files changed, 76 insertions(+), 32 deletions(-)
---
diff --git a/NEWS b/NEWS
index 51cc611..3d8fff3 100644
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,7 @@ Gnumeric 1.9.15
 
 Andreas:
 	* Add RANDSNORM and RANDSTDIST. [#144717]
-	* Add R.PSNORM and R.DSNORM.
+	* Add R.PSNORM, R.DSNORM and R.DST.
 
 Jody:
 	* First steps towards a turnkey win32 build.
diff --git a/plugins/fn-r/ChangeLog b/plugins/fn-r/ChangeLog
index 9f75215..36122d1 100644
--- a/plugins/fn-r/ChangeLog
+++ b/plugins/fn-r/ChangeLog
@@ -1,3 +1,11 @@
+2009-10-13  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* generate: enable dst
+	* extra.c (dst): implement
+	(gnm_owent): add GNM_const
+	* plugin.xml.in: updated due to changes in generate
+	* functions.c: ditto
+
 2009-10-12  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* generate: handle *snorm and *st
@@ -14,8 +22,8 @@
 	(dst): new stub
 	(pst): new stub
 	(qst): new stub
-	(plugin.xml.in): updated due to changes in generate
-	(functions.c): ditto
+	* plugin.xml.in: updated due to changes in generate
+	* functions.c: ditto
 
 2009-10-11  Morten Welinder <terra gnome org>
 
diff --git a/plugins/fn-r/extra.c b/plugins/fn-r/extra.c
index 0d42bf6..d0604a2 100644
--- a/plugins/fn-r/extra.c
+++ b/plugins/fn-r/extra.c
@@ -66,26 +66,26 @@ qcauchy (gnm_float p, gnm_float location, gnm_float scale,
 static gnm_float
 gnm_owent (gnm_float h, gnm_float a)
 {
-	gnm_float weight[10] = { 0.0666713443086881375935688098933,
-				 0.149451349150580593145776339658,
-				 0.219086362515982043995534934228,
-				 0.269266719309996355091226921569,
-				 0.295524224714752870173892994651,
-				 0.295524224714752870173892994651,
-				 0.269266719309996355091226921569,
-				 0.219086362515982043995534934228,
-				 0.149451349150580593145776339658,
-				 0.0666713443086881375935688098933 };
-	gnm_float xtab[10] = {0.026093471482828279922035987916,
-			      0.134936633311015489267903311577,
-			      0.320590431700975593765672634885,
-			      0.566604605870752809200734056834,
-			      0.85112566101836878911517399887,
-			      1.148874338981631210884826001130,
-			      1.433395394129247190799265943166,
-			      1.679409568299024406234327365115,
-			      1.865063366688984510732096688423,
-			      1.973906528517171720077964012084};
+	gnm_float weight[10] = { GNM_const(0.0666713443086881375935688098933),
+				 GNM_const(0.149451349150580593145776339658),
+				 GNM_const(0.219086362515982043995534934228),
+				 GNM_const(0.269266719309996355091226921569),
+				 GNM_const(0.295524224714752870173892994651),
+				 GNM_const(0.295524224714752870173892994651),
+				 GNM_const(0.269266719309996355091226921569),
+				 GNM_const(0.219086362515982043995534934228),
+				 GNM_const(0.149451349150580593145776339658),
+				 GNM_const(0.0666713443086881375935688098933)};
+	gnm_float xtab[10] = {GNM_const(0.026093471482828279922035987916),
+			      GNM_const(0.134936633311015489267903311577),
+			      GNM_const(0.320590431700975593765672634885),
+			      GNM_const(0.566604605870752809200734056834),
+			      GNM_const(0.85112566101836878911517399887),
+			      GNM_const(1.148874338981631210884826001130),
+			      GNM_const(1.433395394129247190799265943166),
+			      GNM_const(1.679409568299024406234327365115),
+			      GNM_const(1.865063366688984510732096688423),
+			      GNM_const(1.973906528517171720077964012084)};
 	gnm_float hs, h2, as, rt;
 	int i;
 
@@ -182,10 +182,12 @@ dst (gnm_float x, gnm_float n, gnm_float shape, gboolean give_log)
 {
 	if (shape == 0.) 
 		return dt (x, n, give_log);
-	else if (give_log)
-		return 0.;
-	else
-		return 0.;
+	else {
+		gnm_float pdf = dt (x, n, give_log);
+		gnm_float cdf = pt (shape * x * gnm_sqrt ((n + 1)/(x * x + n)), 
+				    n + 1, TRUE, give_log);
+		return ((give_log) ? (gnm_log (2.) + pdf + cdf) : (2. * pdf * cdf));
+	}
 }
 
 
diff --git a/plugins/fn-r/functions.c b/plugins/fn-r/functions.c
index 5bf1630..ccce62b 100644
--- a/plugins/fn-r/functions.c
+++ b/plugins/fn-r/functions.c
@@ -1234,6 +1234,31 @@ gnumeric_r_psnorm (GnmFuncEvalInfo *ei, GnmValue const * const *args)
 
 /* ------------------------------------------------------------------------- */
 
+
+static GnmFuncHelp const help_r_dst[] = {
+	{ GNM_FUNC_HELP_NAME, F_("R.DST:probability density function of the skew-t distribution") },
+	{ GNM_FUNC_HELP_ARG, F_("x:observation") },
+	{ GNM_FUNC_HELP_ARG, F_("n:the number of degrees of freedom of the distribution") },
+	{ GNM_FUNC_HELP_ARG, F_("shape:the shape parameter of the distribution") },
+	{ GNM_FUNC_HELP_ARG, F_("give_log:if true, log of the result will be returned instead") },
+	{ GNM_FUNC_HELP_DESCRIPTION, F_("This function returns the probability density function of the skew-t distribution.") },
+	{ GNM_FUNC_HELP_SEEALSO, "" },
+	{ GNM_FUNC_HELP_END }
+};
+
+static GnmValue *
+gnumeric_r_dst (GnmFuncEvalInfo *ei, GnmValue const * const *args)
+{
+	gnm_float x = value_get_as_float (args[0]);
+	gnm_float n = value_get_as_float (args[1]);
+	gnm_float shape = value_get_as_float (args[2]);
+	gboolean give_log = args[3] ? value_get_as_checked_bool (args[3]) : FALSE;
+
+	return value_new_float (dst (x, n, shape, give_log));
+}
+
+/* ------------------------------------------------------------------------- */
+
 G_MODULE_EXPORT void
 go_plugin_init (GOPlugin *plugin, GOCmdContext *cc)
 {
@@ -1576,5 +1601,12 @@ GnmFuncDescriptor const stat_functions[] = {
 		gnumeric_r_psnorm, NULL, NULL, NULL, NULL,
 		GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE,
 	},
+	{
+		"r.dst",
+		"fff|b",
+		help_r_dst,
+		gnumeric_r_dst, NULL, NULL, NULL, NULL,
+		GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC, GNM_FUNC_TEST_STATUS_NO_TESTSUITE,
+	},
 	{ NULL }
 };
diff --git a/plugins/fn-r/generate b/plugins/fn-r/generate
index a8cc3bf..00cc73b 100644
--- a/plugins/fn-r/generate
+++ b/plugins/fn-r/generate
@@ -146,11 +146,12 @@ my %argoverride = ();
 	 ({ 'location' => "the location parameter $of",
 	    @common })];
 
-#    $funcs{'dst'} = $funcs{'pst'} = $funcs{'qst'} =
-#	[\&distribution,
-#	 'skew-t',
-#	 ({ 'n' => "the number of degrees of freedom $of",
-#	    @common })];
+    $funcs{'dst'} = 
+#$funcs{'pst'} = $funcs{'qst'} =
+	[\&distribution,
+	 'skew-t',
+	 ({ 'n' => "the number of degrees of freedom $of",
+	    @common })];
 }
 
 
diff --git a/plugins/fn-r/plugin.xml.in b/plugins/fn-r/plugin.xml.in
index 79662be..b5ee8c3 100644
--- a/plugins/fn-r/plugin.xml.in
+++ b/plugins/fn-r/plugin.xml.in
@@ -25,6 +25,7 @@
 				<function name="r.dnorm"/>
 				<function name="r.dpois"/>
 				<function name="r.dsnorm"/>
+				<function name="r.dst"/>
 				<function name="r.dt"/>
 				<function name="r.dweibull"/>
 				<function name="r.pbeta"/>



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