(parse_map_in): Improve error message when user
[pspp] / src / language / stats / t-test.q
index 5c902dfd225038c42ad584c5bd560deaa53c3ffa..b593ebc4bc3df675f99a01dfe9e5d109c8b5a946 100644 (file)
@@ -1,8 +1,6 @@
 /* PSPP - computes sample statistics. -*-c-*-
 
    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
-   Written by John Williams <johnr.williams@stonebow.otago.ac.nz>.
-   Almost completly re-written by John Darrington 2004
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -112,7 +110,7 @@ static int n_pairs = 0 ;
 struct pair 
 {
   /* The variables comprising the pair */
-  struct variable *v[2];
+  const struct variable *v[2];
 
   /* The number of valid variable pairs */
   double n;
@@ -306,30 +304,29 @@ cmd_t_test (struct lexer *lexer, struct dataset *ds)
 
          int i;
          struct hsh_iterator hi;
-         struct hsh_table *hash;
-         struct variable *v;
+         struct const_hsh_table *hash;
+         const struct variable *v;
 
-         hash = hsh_create (n_pairs, compare_vars_by_name, hash_var_by_name,
+         hash = const_hsh_create (n_pairs, compare_vars_by_name, hash_var_by_name,
           0, 0);
 
          for (i=0; i < n_pairs; ++i)
            {
-             hsh_insert(hash,pairs[i].v[0]);
-             hsh_insert(hash,pairs[i].v[1]);
+             const_hsh_insert (hash, pairs[i].v[0]);
+             const_hsh_insert (hash, pairs[i].v[1]);
            }
 
          assert(cmd.n_variables == 0);
-         cmd.n_variables = hsh_count(hash);
+         cmd.n_variables = const_hsh_count (hash);
 
          cmd.v_variables = xnrealloc (cmd.v_variables, cmd.n_variables,
                                        sizeof *cmd.v_variables);
          /* Iterate through the hash */
-         for (i=0,v = (struct variable *) hsh_first(hash,&hi);
+         for (i=0,v = const_hsh_first (hash, &hi);
               v != 0;
-              v=hsh_next(hash,&hi) ) 
+              v = const_hsh_next (hash, &hi) ) 
            cmd.v_variables[i++]=v;
-
-         hsh_destroy(hash);
+         const_hsh_destroy(hash);
        }
     }
   else if ( !cmd.sbc_variables) 
@@ -443,7 +440,7 @@ tts_custom_groups (struct lexer *lexer, struct dataset *ds, struct cmd_t_test *c
 static int
 tts_custom_pairs (struct lexer *lexer, struct dataset *ds, struct cmd_t_test *cmd UNUSED, void *aux UNUSED)
 {
-  struct variable **vars;
+  const struct variable **vars;
   size_t n_vars;
   size_t n_pairs_local;
 
@@ -454,7 +451,7 @@ tts_custom_pairs (struct lexer *lexer, struct dataset *ds, struct cmd_t_test *cm
   lex_match (lexer, '=');
 
   n_vars=0;
-  if (!parse_variables (lexer, dataset_dict (ds), &vars, &n_vars,
+  if (!parse_variables_const (lexer, dataset_dict (ds), &vars, &n_vars,
                        PV_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH))
     {
       free (vars);
@@ -466,7 +463,7 @@ tts_custom_pairs (struct lexer *lexer, struct dataset *ds, struct cmd_t_test *cm
   if (lex_match (lexer, T_WITH))
     {
       n_before_WITH = n_vars;
-      if (!parse_variables (lexer, dataset_dict (ds), &vars, &n_vars,
+      if (!parse_variables_const (lexer, dataset_dict (ds), &vars, &n_vars,
                            PV_DUPLICATE | PV_APPEND
                            | PV_NUMERIC | PV_NO_SCRATCH))
        {
@@ -487,7 +484,7 @@ tts_custom_pairs (struct lexer *lexer, struct dataset *ds, struct cmd_t_test *cm
          msg (SE, _("PAIRED was specified but the number of variables "
                     "preceding WITH (%d) did not match the number "
                     "following (%d)."),
-              n_before_WITH, n_after_WITH );
+              (int) n_before_WITH, (int) n_after_WITH );
          return 0;
        }
       n_pairs_local = n_before_WITH;
@@ -751,7 +748,7 @@ ssbox_independent_samples_populate(struct ssbox *ssb,
 
   for (i=0; i < cmd->n_variables; ++i)
     {
-      struct variable *var = cmd->v_variables[i];
+      const struct variable *var = cmd->v_variables[i];
       struct hsh_table *grp_hash = group_proc_get (var)->group_hash;
       int count=0;
 
@@ -802,7 +799,7 @@ ssbox_independent_samples_populate(struct ssbox *ssb,
          gs = hsh_find(grp_hash, (void *) &search_val);
          assert(gs);
 
-         tab_float(ssb->t, 2 ,i*2+count+1, TAB_RIGHT, gs->n, 2, 0);
+         tab_float(ssb->t, 2 ,i*2+count+1, TAB_RIGHT, gs->n, 10, 0);
          tab_float(ssb->t, 3 ,i*2+count+1, TAB_RIGHT, gs->mean, 8, 2);
          tab_float(ssb->t, 4 ,i*2+count+1, TAB_RIGHT, gs->std_dev, 8, 3);
          tab_float(ssb->t, 5 ,i*2+count+1, TAB_RIGHT, gs->se_mean, 8, 3);
@@ -862,7 +859,7 @@ ssbox_paired_populate(struct ssbox *ssb,struct cmd_t_test *cmd UNUSED)
 
          /* Values */
          tab_float (ssb->t,2, i*2+j+1, TAB_RIGHT, pairs[i].mean[j], 8, 2);
-         tab_float (ssb->t,3, i*2+j+1, TAB_RIGHT, pairs[i].n, 2, 0);
+         tab_float (ssb->t,3, i*2+j+1, TAB_RIGHT, pairs[i].n, 10, 0);
          tab_float (ssb->t,4, i*2+j+1, TAB_RIGHT, pairs[i].std_dev[j], 8, 3);
          tab_float (ssb->t,5, i*2+j+1, TAB_RIGHT, pairs[i].std_dev[j]/sqrt(pairs[i].n), 8, 3);
 
@@ -883,7 +880,7 @@ ssbox_one_sample_populate(struct ssbox *ssb, struct cmd_t_test *cmd)
       struct group_statistics *gs = &group_proc_get (cmd->v_variables[i])->ugs;
 
       tab_text (ssb->t, 0, i+1, TAB_LEFT, var_get_name (cmd->v_variables[i]));
-      tab_float (ssb->t,1, i+1, TAB_RIGHT, gs->n, 2, 0);
+      tab_float (ssb->t,1, i+1, TAB_RIGHT, gs->n, 10, 0);
       tab_float (ssb->t,2, i+1, TAB_RIGHT, gs->mean, 8, 2);
       tab_float (ssb->t,3, i+1, TAB_RIGHT, gs->std_dev, 8, 2);
       tab_float (ssb->t,4, i+1, TAB_RIGHT, gs->se_mean, 8, 3);
@@ -1014,7 +1011,7 @@ trbox_independent_samples_populate(struct trbox *self,
       double std_err_diff;
       double mean_diff;
 
-      struct variable *var = cmd->v_variables[i];
+      const struct variable *var = cmd->v_variables[i];
       struct group_proc *grp_data = group_proc_get (var);
 
       struct hsh_table *grp_hash = grp_data->group_hash;
@@ -1055,7 +1052,7 @@ trbox_independent_samples_populate(struct trbox *self,
       tab_float(self->t, 3, i*2+3, TAB_CENTER, q, 8,3 );
 
       df = gs0->n + gs1->n - 2.0 ;
-      tab_float (self->t, 5, i*2+3, TAB_RIGHT, df, 2, 0);
+      tab_float (self->t, 5, i*2+3, TAB_RIGHT, df, 10, 0);
 
       pooled_variance = ( (gs0->n )*pow2(gs0->s_std_dev)
                          + 
@@ -1228,7 +1225,7 @@ trbox_paired_populate(struct trbox *trb,
       tab_float(trb->t, 7, i+3, TAB_RIGHT, t , 8,3 );
 
       /* Degrees of freedom */
-      tab_float(trb->t, 8, i+3, TAB_RIGHT, df , 2, 0 );
+      tab_float(trb->t, 8, i+3, TAB_RIGHT, df , 10, 0 );
 
       p = gsl_cdf_tdist_P(t,df);
       q = gsl_cdf_tdist_P(t,df);
@@ -1431,7 +1428,7 @@ common_calc (const struct dictionary *dict,
 
   for(i = 0; i < cmd->n_variables ; ++i) 
     {
-      struct variable *v = cmd->v_variables[i];
+      const struct variable *v = cmd->v_variables[i];
 
       if (! casefilter_variable_missing (filter, c, v) )
        {
@@ -1507,7 +1504,7 @@ one_sample_calc (const struct dictionary *dict,
   for(i=0; i< cmd->n_variables ; ++i) 
     {
       struct group_statistics *gs;
-      struct variable *v = cmd->v_variables[i];
+      const struct variable *v = cmd->v_variables[i];
       const union value *val = case_data (c, v);
 
       gs= &group_proc_get (cmd->v_variables[i])->ugs;
@@ -1580,8 +1577,8 @@ paired_calc (const struct dictionary *dict, const struct ccase *c,
 
   for(i=0; i < n_pairs ; ++i )
     {
-      struct variable *v0 = pairs[i].v[0];
-      struct variable *v1 = pairs[i].v[1];
+      const struct variable *v0 = pairs[i].v[0];
+      const struct variable *v1 = pairs[i].v[1];
 
       const union value *val0 = case_data (c, v0);
       const union value *val1 = case_data (c, v1);
@@ -1713,7 +1710,7 @@ group_calc (const struct dictionary *dict,
 
   for(i=0; i< cmd->n_variables ; ++i) 
     {
-      struct variable *var = cmd->v_variables[i];
+      const struct variable *var = cmd->v_variables[i];
       const union value *val = case_data (c, var);
       struct hsh_table *grp_hash = group_proc_get (var)->group_hash;
       struct group_statistics *gs;
@@ -1744,7 +1741,7 @@ group_postcalc ( struct cmd_t_test *cmd )
 
   for (i = 0; i < cmd->n_variables ; ++i) 
     {
-      struct variable *var = cmd->v_variables[i];
+      const struct variable *var = cmd->v_variables[i];
       struct hsh_table *grp_hash = group_proc_get (var)->group_hash;
       struct hsh_iterator g;
       struct group_statistics *gs;
@@ -1787,7 +1784,8 @@ calculate(const struct ccase *first, const struct casefile *cf,
 
   struct cmd_t_test *cmd = (struct cmd_t_test *) cmd_;
 
-  struct casefilter *filter = casefilter_create (cmd->miss != TTS_INCLUDE, 
+  struct casefilter *filter = casefilter_create ((cmd->miss != TTS_INCLUDE
+                                                  ? MV_ANY : MV_SYSTEM), 
                                                 NULL, 0);
 
   if ( cmd->miss == TTS_LISTWISE )