more summary testing
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 15 Aug 2022 01:03:09 +0000 (18:03 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 15 Aug 2022 01:03:09 +0000 (18:03 -0700)
src/language/stats/ctables.c
tests/language/stats/ctables.at

index d087e000cf17ae071a570dcbec0ec15cf0c2787d..b2274f3e44d2d3abc2f5644086385eba27ce4b93 100644 (file)
@@ -2551,11 +2551,14 @@ ctables_summary_init (union ctables_summary *s,
       break;
 
     case CTSF_MEAN:
+    case CTSF_SUM:
+    case CTSF_areaPCT_SUM:
+      s->moments = moments1_create (MOMENT_MEAN);
+      break;
+
     case CTSF_SEMEAN:
     case CTSF_STDDEV:
-    case CTSF_SUM:
     case CTSF_VARIANCE:
-    case CTSF_areaPCT_SUM:
       s->moments = moments1_create (MOMENT_VARIANCE);
       break;
 
@@ -2714,11 +2717,15 @@ ctables_summary_add (union ctables_summary *s,
     case CTSF_STDDEV:
     case CTSF_SUM:
     case CTSF_VARIANCE:
-    case CTSF_areaPCT_SUM:
       if (!is_scale_missing)
         moments1_add (s->moments, value->f, ss->weighted ? e_weight : 1.0);
       break;
 
+    case CTSF_areaPCT_SUM:
+      if (!is_missing && !is_scale_missing)
+        moments1_add (s->moments, value->f, ss->weighted ? e_weight : 1.0);
+      break;
+
     case CTSF_MEDIAN:
     case CTSF_MODE:
     case CTSF_PTILE:
@@ -3726,8 +3733,8 @@ ctables_table_add_section (struct ctables_table *t, enum pivot_axis_type a,
             for (size_t i = 0; i < nest->n; i++)
               hmap_init (&s->occurrences[a][i]);
         }
-      for (size_t i = 0; i < N_CTATS; i++)
-        hmap_init (&s->areas[i]);
+      for (enum ctables_area_type at = 0; at < N_CTATS; at++)
+        hmap_init (&s->areas[at]);
     }
 }
 
@@ -5189,8 +5196,8 @@ ctables_section_uninit (struct ctables_section *s)
     }
 
   hmap_destroy (&s->cells);
-  for (size_t i = 0; i < N_CTATS; i++)
-    hmap_destroy (&s->areas[i]);
+  for (enum ctables_area_type at = 0; at < N_CTATS; at++)
+    hmap_destroy (&s->areas[at]);
 }
 
 static void
index d2776d42a49dc94fe81480bea1aca38b4b43ae06..6643abf84ef8341dc434d6031088284bac0ea314 100644 (file)
@@ -4883,13 +4883,8 @@ for a in 1 2 9; do
     done
 done > ctables.txt
 
-AT_DATA([ctables.sps],
-[[DATA LIST LIST NOTABLE FILE='ctables.txt'
-    /w (F5.0) a b c (f2.0).
-VAR LEVEL w c (SCALE) a b (NOMINAL).
-MISSING VALUES a b (9).
-
-* Use SPLIT FILE with FREQUENCIES to generate output equivalent to
+AT_DATA([analysis.sps],
+[[* Use SPLIT FILE with FREQUENCIES to generate output equivalent to
   CTABLES later, to make the results easier to verify.
 SPLIT FILE BY a b.
 FREQUENCIES
@@ -4903,6 +4898,24 @@ CTABLES
     /SLABELS POSITION=ROW
     /CATEGORIES VARIABLES=a b MISSING=INCLUDE.
 ]])
+
+AT_DATA([ctables.sps],
+[[DATA LIST LIST NOTABLE FILE='ctables.txt'
+    /w (F5.0) a b c (f2.0).
+VAR LEVEL w c (SCALE) a b (NOMINAL).
+MISSING VALUES a b (9).
+
+INCLUDE 'analysis.sps'.
+
+WEIGHT BY w.
+INCLUDE 'analysis.sps'.
+
+* Same as original analysis using unweighted versions of summaries.
+CTABLES
+    /TABLE c[UVALIDN, UMISSING, UMEAN F8.2, USEMEAN F8.2, UMEDIAN F8.2, UMODE, USTDDEV F8.2, UVARIANCE F8.2, USUM F8.2, UCOUNT, UTOTALN, ULAYERROWPCT.SUM] BY a>b
+    /SLABELS POSITION=ROW
+    /CATEGORIES VARIABLES=a b MISSING=INCLUDE.
+]])
 AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [dnl
                                 Statistics
 ╭─────────┬──────────────────────────────────────────────────────────────╮
@@ -4964,8 +4977,95 @@ AT_CHECK([pspp ctables.sps -O box=unicode -O width=120], [0], [dnl
 │  Sum              │181.00│147.00│197.00│181.00│180.00│194.00│178.00│177.00│191.00│
 │  Count            │    10│    10│    10│    10│    10│    10│    10│    10│    10│
 │  Total N          │    10│    10│    10│    10│    10│    10│    10│    10│    10│
-│  Layer Row Sum %  │ xxxx%│ xxxx%│ xxxx%│ xxxx%│ xxxx%│ xxxx%│ xxx8%│ xxxx%│ xxxx%
+│  Layer Row Sum %  │ 26.3%│ 21.3%│     .│ 26.3%│ 26.1%│     .│     .│     .│     .
 ╰───────────────────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────╯
+
+                                  Statistics
+╭─────────┬─────────────────────────────────────────────────────────────────╮
+│         │                                a                                │
+│         ├─────────────────────┬─────────────────────┬─────────────────────┤
+│         │          1          │          2          │          9          │
+│         ├─────────────────────┼─────────────────────┼─────────────────────┤
+│         │          b          │          b          │          b          │
+│         ├───────┬──────┬──────┼──────┬───────┬──────┼──────┬──────┬───────┤
+│         │   3   │   4  │   9  │   3  │   4   │   9  │   3  │   4  │   9   │
+│         ├───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│         │   c   │   c  │   c  │   c  │   c   │   c  │   c  │   c  │   c   │
+├─────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│N Valid  │     40│    35│    41│    26│     38│    40│    34│    32│     39│
+│  Missing│      6│    14│    11│    22│     13│     7│    16│    21│     10│
+├─────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│Mean     │  27.23│ 24.20│ 22.63│ 27.96│  27.21│ 23.48│ 23.71│ 25.47│  26.03│
+├─────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│S.E. Mean│    .93│   .75│  1.03│  1.12│    .84│   .87│  1.01│  1.05│   1.01│
+├─────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│Median   │  30.00│ 22.00│ 19.00│ 30.00│  29.00│ 24.00│ 23.00│ 24.00│  28.00│
+├─────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│Mode     │     34│    29│    19│    34│     33│    28│    23│    18│     30│
+├─────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│Std Dev  │   5.89│  4.42│  6.59│  5.69│   5.16│  5.50│  5.87│  5.94│   6.30│
+├─────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│Variance │  34.64│ 19.52│ 43.39│ 32.36│  26.66│ 30.20│ 34.46│ 35.29│  39.71│
+├─────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│Range    │  18.00│ 13.00│ 20.00│ 18.00│  15.00│ 20.00│ 18.00│ 15.00│  20.00│
+├─────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│Minimum  │     16│    18│    15│    16│     18│    15│    16│    18│     15│
+├─────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│Maximum  │     34│    31│    35│    34│     33│    35│    34│    33│     35│
+├─────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│Sum      │1089.00│847.00│928.00│727.00│1034.00│939.00│806.00│815.00│1015.00│
+╰─────────┴───────┴──────┴──────┴──────┴───────┴──────┴──────┴──────┴───────╯
+
+                                     Custom Tables
+╭───────────────────┬─────────────────────────────────────────────────────────────────╮
+│                   │                                a                                │
+│                   ├─────────────────────┬─────────────────────┬─────────────────────┤
+│                   │          1          │          2          │          9          │
+│                   ├─────────────────────┼─────────────────────┼─────────────────────┤
+│                   │          b          │          b          │          b          │
+│                   ├───────┬──────┬──────┼──────┬───────┬──────┼──────┬──────┬───────┤
+│                   │   3   │   4  │   9  │   3  │   4   │   9  │   3  │   4  │   9   │
+├───────────────────┼───────┼──────┼──────┼──────┼───────┼──────┼──────┼──────┼───────┤
+│c Valid N          │     40│    35│    41│    26│     38│    40│    34│    32│     39│
+│  Missing          │      6│    14│    11│    22│     13│     7│    16│    21│     10│
+│  Mean             │  27.22│ 24.20│ 22.63│ 27.96│  27.21│ 23.48│ 23.71│ 25.47│  26.03│
+│  Std Error of Mean│    .93│   .75│  1.03│  1.12│    .84│   .87│  1.01│  1.05│   1.01│
+│  Median           │  30.00│ 22.00│ 19.00│ 30.00│  29.00│ 24.00│ 23.00│ 24.00│  28.00│
+│  Mode             │     34│    29│    19│    34│     33│    28│    23│    18│     30│
+│  Std Deviation    │   5.89│  4.42│  6.59│  5.69│   5.16│  5.50│  5.87│  5.94│   6.30│
+│  Variance         │  34.64│ 19.52│ 43.39│ 32.36│  26.66│ 30.20│ 34.46│ 35.29│  39.71│
+│  Range            │  18.00│ 13.00│ 20.00│ 18.00│  15.00│ 20.00│ 18.00│ 15.00│  20.00│
+│  Minimum          │     16│    18│    15│    16│     18│    15│    16│    18│     15│
+│  Maximum          │     34│    31│    35│    34│     33│    35│    34│    33│     35│
+│  Sum              │1089.00│847.00│928.00│727.00│1034.00│939.00│806.00│815.00│1015.00│
+│  Count            │     46│    49│    52│    48│     51│    47│    50│    53│     49│
+│  Total N          │     46│    49│    52│    48│     51│    47│    50│    53│     49│
+│  Layer Row Sum %  │  29.5%│ 22.9%│     .│ 19.7%│  28.0%│     .│     .│     .│      .│
+╰───────────────────┴───────┴──────┴──────┴──────┴───────┴──────┴──────┴──────┴───────╯
+
+                                        Custom Tables
+╭────────────────────────────┬──────────────────────────────────────────────────────────────╮
+│                            │                               a                              │
+│                            ├────────────────────┬────────────────────┬────────────────────┤
+│                            │          1         │          2         │          9         │
+│                            ├────────────────────┼────────────────────┼────────────────────┤
+│                            │          b         │          b         │          b         │
+│                            ├──────┬──────┬──────┼──────┬──────┬──────┼──────┬──────┬──────┤
+│                            │   3  │   4  │   9  │   3  │   4  │   9  │   3  │   4  │   9  │
+├────────────────────────────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┤
+│c Valid N                   │     7│     6│     8│     7│     7│     8│     7│     7│     8│
+│  Missing                   │     3│     4│     2│     3│     3│     2│     3│     3│     2│
+│  Unweighted Mean           │ 25.86│ 24.50│ 24.63│ 25.86│ 25.71│ 24.25│ 25.43│ 25.29│ 23.88│
+│  Std Error of Mean         │  2.44│  2.14│  2.58│  2.44│  2.18│  2.43│  2.36│  2.18│  2.47│
+│  Median                    │ 25.00│ 24.50│ 25.00│ 25.00│ 27.00│ 25.00│ 25.00│ 24.00│ 23.50│
+│  Mode                      │    16│    18│    15│    16│    18│    15│    16│    18│    15│
+│  Std Deviation             │  6.47│  5.24│  7.31│  6.47│  5.77│  6.88│  6.24│  5.77│  6.98│
+│  Variance                  │ 41.81│ 27.50│ 53.41│ 41.81│ 33.24│ 47.36│ 38.95│ 33.24│ 48.70│
+│  Sum                       │181.00│147.00│197.00│181.00│180.00│194.00│178.00│177.00│191.00│
+│  Unweighted Count          │    10│    10│    10│    10│    10│    10│    10│    10│    10│
+│  Total N                   │    10│    10│    10│    10│    10│    10│    10│    10│    10│
+│  Unweighted Layer Row Sum %│ 26.3%│ 21.3%│     .│ 26.3%│ 26.1%│     .│     .│     .│     .│
+╰────────────────────────────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────╯
 ])
 AT_CLEANUP