ROWLABELS=LAYER works
[pspp] / src / language / stats / means-calc.c
index 7e5142fd7809e72c6b88a77330fd6beca66d1e81..6aabbf50cbad1b8448eb3de326b882f43ce2f02e 100644 (file)
 #define _(msgid) gettext (msgid)
 #define N_(msgid) (msgid)
 
+/* A base struct for all statistics.  */
 struct statistic
 {
 };
 
+/* Statistics which accumulate a single value.  */
 struct statistic_simple
 {
   struct statistic parent;
   double acc;
 };
 
+/* Statistics based on moments.  */
 struct statistic_moment
 {
   struct statistic parent;
   struct moments1 *mom;
 };
 
+
 static struct statistic *
 default_create (struct pool *pool)
 {
@@ -77,6 +81,8 @@ default_destroy (struct statistic *stat)
   moments1_destroy (pvd->mom);
 }
 
+
+/* Simple statistics have nothing to destroy.  */
 static void
 simple_destroy (struct statistic *stat UNUSED)
 {
@@ -85,7 +91,7 @@ simple_destroy (struct statistic *stat UNUSED)
 \f
 
 /* HARMONIC MEAN: The reciprocal of the sum of the reciprocals:
-   1 / ( 1/(x_0) + 1/(x_1) + ... + 1/(x_{n-1}) ) */
+   1 / (1/(x_0) + 1/(x_1) + ... + 1/(x_{n-1})) */
 
 struct harmonic_mean
 {
@@ -163,6 +169,10 @@ geometric_get (const struct statistic *pvd)
 
 \f
 
+/* The getters for moment based statistics simply calculate the
+   moment.    The only exception is Std Dev. which needs to call
+   sqrt as well.  */
+
 static double
 sum_get (const struct statistic *pvd)
 {
@@ -211,9 +221,6 @@ stddev_get (const struct statistic *pvd)
   return sqrt (variance_get (pvd));
 }
 
-
-\f
-
 static double
 skew_get (const struct statistic *pvd)
 {
@@ -333,6 +340,8 @@ struct range
   double max;
 };
 
+/* Initially min and max are set to their most (inverted) extreme possible
+   values.  */
 static struct statistic *
 range_create (struct pool *pool)
 {
@@ -344,6 +353,8 @@ range_create (struct pool *pool)
   return (struct statistic *) r;
 }
 
+/* On each update, set min and max to X or leave unchanged,
+   as appropriate.  */
 static void
 range_update (struct statistic *pvd, double w UNUSED, double x)
 {
@@ -356,6 +367,7 @@ range_update (struct statistic *pvd, double w UNUSED, double x)
     r->min = x;
 }
 
+/*  Get the difference between min and max.  */
 static double
 range_get (const struct statistic *pvd)
 {
@@ -423,29 +435,29 @@ first_get (const struct statistic *pvd)
 
 /* Table of cell_specs */
 const struct cell_spec cell_spec[n_MEANS_STATISTICS] = {
-  {N_("Mean"),           "MEAN",      PIVOT_RC_OTHER,   default_create,   default_update,   arithmean_get, default_destroy},
+  {N_("Mean"),           "MEAN",      NULL          ,   default_create,   default_update,   arithmean_get, default_destroy},
   {N_("N"),              "COUNT",     PIVOT_RC_COUNT,   default_create,   default_update,   n_get,         default_destroy},
-  {N_("Std. Deviation"), "STDDEV",    PIVOT_RC_OTHER,   default_create,   default_update,   stddev_get,    default_destroy},
+  {N_("Std. Deviation"), "STDDEV",    NULL          ,   default_create,   default_update,   stddev_get,    default_destroy},
 #if 0
-  {N_("Median"),         "MEDIAN",    PIVOT_RC_OTHER,   default_create,   default_update,   NULL,          default_destroy},
-  {N_("Group Median"),   "GMEDIAN",   PIVOT_RC_OTHER,   default_create,   default_update,   NULL,          default_destroy},
+  {N_("Median"),         "MEDIAN",    NULL          ,   default_create,   default_update,   NULL,          default_destroy},
+  {N_("Group Median"),   "GMEDIAN",   NULL          ,   default_create,   default_update,   NULL,          default_destroy},
 #endif
-  {N_("S.E. Mean"),      "SEMEAN",    PIVOT_RC_OTHER,   default_create,   default_update,   semean_get,    default_destroy},
-  {N_("Sum"),            "SUM",       PIVOT_RC_OTHER,   default_create,   default_update,   sum_get,       default_destroy},
-  {N_("Minimum"),        "MIN",       PIVOT_RC_OTHER,   min_create,       min_update,       min_get,       simple_destroy},
-  {N_("Maximum"),        "MAX",       PIVOT_RC_OTHER,   max_create,       max_update,       max_get,       simple_destroy},
-  {N_("Range"),          "RANGE",     PIVOT_RC_OTHER,   range_create,     range_update,     range_get,     simple_destroy},
+  {N_("S.E. Mean"),      "SEMEAN",    NULL          ,   default_create,   default_update,   semean_get,    default_destroy},
+  {N_("Sum"),            "SUM",       NULL          ,   default_create,   default_update,   sum_get,       default_destroy},
+  {N_("Minimum"),        "MIN",       NULL          ,   min_create,       min_update,       min_get,       simple_destroy},
+  {N_("Maximum"),        "MAX",       NULL          ,   max_create,       max_update,       max_get,       simple_destroy},
+  {N_("Range"),          "RANGE",     NULL          ,   range_create,     range_update,     range_get,     simple_destroy},
   {N_("Variance"),       "VARIANCE",  PIVOT_RC_OTHER,   default_create,   default_update,   variance_get,  default_destroy},
   {N_("Kurtosis"),       "KURT",      PIVOT_RC_OTHER,   default_create,   default_update,   kurt_get,      default_destroy},
   {N_("S.E. Kurt"),      "SEKURT",    PIVOT_RC_OTHER,   default_create,   default_update,   sekurt_get,    default_destroy},
   {N_("Skewness"),       "SKEW",      PIVOT_RC_OTHER,   default_create,   default_update,   skew_get,      default_destroy},
   {N_("S.E. Skew"),      "SESKEW",    PIVOT_RC_OTHER,   default_create,   default_update,   seskew_get,    default_destroy},
-  {N_("First"),          "FIRST",     PIVOT_RC_OTHER,   first_create,     first_update,     first_get,     simple_destroy},
-  {N_("Last"),           "LAST",      PIVOT_RC_OTHER,   last_create,      last_update,      last_get,      simple_destroy},
+  {N_("First"),          "FIRST",     NULL          ,   first_create,     first_update,     first_get,     simple_destroy},
+  {N_("Last"),           "LAST",      NULL          ,   last_create,      last_update,      last_get,      simple_destroy},
 #if 0
   {N_("Percent N"),      "NPCT",      PIVOT_RC_PERCENT, default_create,   default_update,   NULL,          default_destroy},
   {N_("Percent Sum"),    "SPCT",      PIVOT_RC_PERCENT, default_create,   default_update,   NULL,          default_destroy},
 #endif
-  {N_("Harmonic Mean"),  "HARMONIC",  PIVOT_RC_OTHER,   harmonic_create,  harmonic_update,  harmonic_get,  simple_destroy},
-  {N_("Geom. Mean"),     "GEOMETRIC", PIVOT_RC_OTHER,   geometric_create, geometric_update, geometric_get, simple_destroy}
+  {N_("Harmonic Mean"),  "HARMONIC",  NULL          ,   harmonic_create,  harmonic_update,  harmonic_get,  simple_destroy},
+  {N_("Geom. Mean"),     "GEOMETRIC", NULL          ,   geometric_create, geometric_update, geometric_get, simple_destroy}
 };