MEANS: Implemented /MISSING=TABLE subcommand
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 16 Jan 2012 09:47:18 +0000 (10:47 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 16 Jan 2012 16:57:35 +0000 (17:57 +0100)
src/language/stats/means.c
tests/language/stats/means.at

index 874ddda8b256d8030ebdf42558608dde68ce89d3..7a6d5432ce7895f60701308a4da80a24e164a814 100644 (file)
@@ -474,6 +474,8 @@ struct means
   /* Missing value class for dependent variables */
   enum mv_class dep_exclude;
 
+  bool listwise_exclude;
+
   /* an array  indicating which statistics are to be calculated */
   int *cells;
 
@@ -592,6 +594,7 @@ cmd_means (struct lexer *lexer, struct dataset *ds)
 
   means.exclude = MV_ANY;
   means.dep_exclude = MV_ANY;
+  means.listwise_exclude = false;
   means.table = NULL;
   means.n_tables = 0;
 
@@ -670,8 +673,7 @@ cmd_means (struct lexer *lexer, struct dataset *ds)
              be dropped FOR THAT TABLE ONLY.
            */
            {
-             means.exclude = MV_ANY;
-             means.dep_exclude = MV_ANY;
+             means.listwise_exclude = true;
            }
          else if (lex_match_id (lexer, "DEPENDENT"))
            /*
@@ -969,6 +971,7 @@ run_means (struct means *cmd, struct casereader *input,
     {
       for (t = 0; t < cmd->n_tables; ++t)
        {
+         bool something_missing = false;
          int  v;
          struct mtable *table = &cmd->table[t];
 
@@ -981,11 +984,17 @@ run_means (struct means *cmd, struct casereader *input,
                    is_missing (cmd, table->dep_vars[v],
                                table->interactions[i], c);
                  if (missing)
-                   table->summary[v * table->n_interactions + i].missing++;
+                   {
+                     something_missing = true;
+                     table->summary[v * table->n_interactions + i].missing++;
+                   }
                  else
                    table->summary[v * table->n_interactions + i].non_missing++;
                }
            }
+         if ( something_missing && cmd->listwise_exclude)
+           continue;
+
          categoricals_update (table->cats, c);
        }
     }
index a69051b1adca55677a61dd80810ae5d091472534..e4d1f5a2f4e682685b7b6db0bec68fe710723936 100644 (file)
@@ -325,3 +325,91 @@ score
 ])
 
 AT_CLEANUP
+
+
+
+
+AT_SETUP([MEANS missing=table ])
+
+AT_DATA([means-miss-table.sps], [dnl
+data list notable list /a * b * g1.
+begin data.
+1 9 1  
+2 9 1 
+3 9 1 
+4 9 2 
+5 9 2 
+6 9 2 
+7 . 2 
+end data.
+
+MEANS a b BY g1
+      /a  BY g1
+      /cells =  COUNT
+      /missing = TABLE
+      .
+
+MEANS a b BY g1
+      /a  BY g1
+      /cells =  COUNT
+      .
+])
+
+
+AT_CHECK([pspp -O format=csv means-miss-table.sps], [0],
+  [dnl
+Table: Case Processing Summary
+,Cases,,,,,
+,Included,,Excluded,,Total,
+,N,Percent,N,Percent,N,Percent
+a: g1,7,100%,0,0%,7,100%
+b: g1,6,85.7143%,1,14.2857%,7,100%
+
+Table: Report
+,g1,N
+a,1.00,3.00
+,2.00,3.00
+b,1.00,3.00
+,2.00,3.00
+
+Table: Case Processing Summary
+,Cases,,,,,
+,Included,,Excluded,,Total,
+,N,Percent,N,Percent,N,Percent
+a: g1,7,100%,0,0%,7,100%
+
+Table: Report
+,g1,N
+a,1.00,3.00
+,2.00,4.00
+
+Table: Case Processing Summary
+,Cases,,,,,
+,Included,,Excluded,,Total,
+,N,Percent,N,Percent,N,Percent
+a: g1,7,100%,0,0%,7,100%
+b: g1,6,85.7143%,1,14.2857%,7,100%
+
+Table: Report
+,g1,N
+a,1.00,3.00
+,2.00,4.00
+b,1.00,3.00
+,2.00,3.00
+
+Table: Case Processing Summary
+,Cases,,,,,
+,Included,,Excluded,,Total,
+,N,Percent,N,Percent,N,Percent
+a: g1,7,100%,0,0%,7,100%
+
+Table: Report
+,g1,N
+a,1.00,3.00
+,2.00,4.00
+])
+
+AT_CLEANUP
+
+
+