1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include <gsl/gsl_cdf.h>
25 #include <data/case.h>
26 #include <data/casegrouper.h>
27 #include <data/casereader.h>
28 #include <data/dictionary.h>
29 #include <data/procedure.h>
30 #include <data/value-labels.h>
31 #include <data/variable.h>
32 #include <language/command.h>
33 #include <language/dictionary/split-file.h>
34 #include <language/lexer/lexer.h>
35 #include <language/lexer/value-parser.h>
36 #include <libpspp/array.h>
37 #include <libpspp/assertion.h>
38 #include <libpspp/compiler.h>
39 #include <libpspp/hash.h>
40 #include <libpspp/message.h>
41 #include <libpspp/misc.h>
42 #include <libpspp/str.h>
43 #include <libpspp/taint.h>
44 #include <math/group-proc.h>
45 #include <math/levene.h>
46 #include <output/manager.h>
47 #include <output/table.h>
48 #include <data/format.h>
55 #define _(msgid) gettext (msgid)
63 +variables=varlist("PV_NO_SCRATCH | PV_NUMERIC");
65 missing=miss:!analysis/listwise,
66 incl:include/!exclude;
67 +format=fmt:!labels/nolabels;
68 criteria=:cin(d:criteria,"%s > 0. && %s < 1.").
79 /* A pair of variables to be compared. */
82 const struct variable *v[2]; /* The paired variables. */
83 double n; /* The number of valid variable pairs */
84 double sum[2]; /* The sum of the members */
85 double ssq[2]; /* sum of squares of the members */
86 double std_dev[2]; /* Std deviation of the members */
87 double s_std_dev[2]; /* Sample Std deviation of the members */
88 double mean[2]; /* The means of the members */
89 double correlation; /* Correlation coefficient between the variables. */
90 double sum_of_diffs; /* The sum of the differences */
91 double sum_of_prod; /* The sum of the products */
92 double mean_diff; /* The mean of the differences */
93 double ssq_diffs; /* The sum of the squares of the differences */
94 double std_dev_diff; /* The std deviation of the differences */
97 /* Which mode was T-TEST invoked */
99 T_1_SAMPLE, /* One-sample tests. */
100 T_IND_SAMPLES, /* Independent-sample tests. */
101 T_PAIRED /* Paired-sample tests. */
104 /* Total state of a T-TEST procedure. */
107 enum t_test_mode mode; /* Mode that T-TEST was invoked in. */
108 double criteria; /* Confidence interval in (0, 1). */
109 enum mv_class exclude; /* Classes of missing values to exclude. */
110 bool listwise_missing; /* Drop whole case if one missing var? */
111 struct fmt_spec weight_format; /* Format of weight variable. */
113 /* Dependent variables. */
114 const struct variable **vars;
117 /* For mode == T_1_SAMPLE. */
120 /* For mode == T_PAIRED only. */
124 /* For mode == T_IND_SAMPLES only. */
125 struct variable *indep_var; /* Independent variable. */
126 enum comparison criterion; /* Type of comparison. */
127 double critical_value; /* CMP_LE only: Grouping threshold value. */
128 union value g_value[2]; /* CMP_EQ only: Per-group indep var values. */
131 /* Statistics Summary Box */
135 void (*populate) (struct ssbox *, struct t_test_proc *);
136 void (*finalize) (struct ssbox *);
139 static void ssbox_create (struct ssbox *, struct t_test_proc *);
140 static void ssbox_populate (struct ssbox *, struct t_test_proc *);
141 static void ssbox_finalize (struct ssbox *);
143 /* Paired Samples Correlation box */
144 static void pscbox (struct t_test_proc *);
147 /* Test Results Box. */
150 void (*populate) (struct trbox *, struct t_test_proc *);
151 void (*finalize) (struct trbox *);
154 static void trbox_create (struct trbox *, struct t_test_proc *);
155 static void trbox_populate (struct trbox *, struct t_test_proc *);
156 static void trbox_finalize (struct trbox *);
158 static void calculate (struct t_test_proc *, struct casereader *,
159 const struct dataset *);
161 static int compare_group_binary (const struct group_statistics *a,
162 const struct group_statistics *b,
163 const struct t_test_proc *);
164 static unsigned hash_group_binary (const struct group_statistics *g,
165 const struct t_test_proc *p);
168 cmd_t_test (struct lexer *lexer, struct dataset *ds)
170 struct cmd_t_test cmd;
171 struct t_test_proc proc;
172 struct casegrouper *grouper;
173 struct casereader *group;
180 proc.indep_var = NULL;
181 if (!parse_t_test (lexer, ds, &cmd, &proc))
184 wv = dict_get_weight (dataset_dict (ds));
185 proc.weight_format = wv ? *var_get_print_format (wv) : F_8_0;
187 if ((cmd.sbc_testval != 0) + (cmd.sbc_groups != 0) + (cmd.sbc_pairs != 0)
190 msg (SE, _("Exactly one of TESTVAL, GROUPS and PAIRS subcommands "
191 "must be specified."));
195 proc.mode = (cmd.sbc_testval ? T_1_SAMPLE
196 : cmd.sbc_groups ? T_IND_SAMPLES
198 proc.criteria = cmd.sbc_criteria ? cmd.criteria : 0.95;
199 proc.exclude = cmd.incl != TTS_INCLUDE ? MV_ANY : MV_SYSTEM;
200 proc.listwise_missing = cmd.miss == TTS_LISTWISE;
202 if (proc.mode == T_1_SAMPLE)
203 proc.testval = cmd.n_testval[0];
205 if (proc.mode == T_PAIRED)
209 if (cmd.sbc_variables)
211 msg (SE, _("VARIABLES subcommand may not be used with PAIRS."));
215 /* Fill proc.vars with the unique variables from pairs. */
216 proc.n_vars = proc.n_pairs * 2;
217 proc.vars = xmalloc (sizeof *proc.vars * proc.n_vars);
218 for (i = j = 0; i < proc.n_pairs; i++)
220 proc.vars[j++] = proc.pairs[i].v[0];
221 proc.vars[j++] = proc.pairs[i].v[1];
223 proc.n_vars = sort_unique (proc.vars, proc.n_vars, sizeof *proc.vars,
224 compare_var_ptrs_by_name, NULL);
228 if (!cmd.n_variables)
230 msg (SE, _("One or more VARIABLES must be specified."));
233 proc.n_vars = cmd.n_variables;
234 proc.vars = cmd.v_variables;
235 cmd.v_variables = NULL;
239 grouper = casegrouper_create_splits (proc_open (ds), dataset_dict (ds));
240 while (casegrouper_get_next_group (grouper, &group))
241 calculate (&proc, group, ds);
242 ok = casegrouper_destroy (grouper);
243 ok = proc_commit (ds) && ok;
245 if (proc.mode == T_IND_SAMPLES)
248 /* Destroy any group statistics we created */
249 for (v = 0; v < proc.n_vars; v++)
251 struct group_proc *grpp = group_proc_get (proc.vars[v]);
252 hsh_destroy (grpp->group_hash);
259 if (proc.indep_var != NULL)
261 int width = var_get_width (proc.indep_var);
262 value_destroy (&proc.g_value[0], width);
263 value_destroy (&proc.g_value[1], width);
267 return ok ? CMD_SUCCESS : CMD_FAILURE;
271 tts_custom_groups (struct lexer *lexer, struct dataset *ds,
272 struct cmd_t_test *cmd UNUSED, void *proc_)
274 struct t_test_proc *proc = proc_;
278 lex_match (lexer, '=');
280 proc->indep_var = parse_variable (lexer, dataset_dict (ds));
281 if (proc->indep_var == NULL)
283 lex_error (lexer, "expecting variable name in GROUPS subcommand");
286 width = var_get_width (proc->indep_var);
287 value_init (&proc->g_value[0], width);
288 value_init (&proc->g_value[1], width);
290 if (!lex_match (lexer, '('))
294 if (!parse_value (lexer, &proc->g_value[0], width))
296 lex_match (lexer, ',');
297 if (lex_match (lexer, ')'))
301 if (!parse_value (lexer, &proc->g_value[1], width)
302 || !lex_force_match (lexer, ')'))
308 if (var_is_numeric (proc->indep_var))
310 proc->criterion = n_values == 1 ? CMP_LE : CMP_EQ;
312 proc->critical_value = proc->g_value[0].f;
313 else if (n_values == 0)
315 proc->g_value[0].f = 1;
316 proc->g_value[1].f = 2;
321 proc->criterion = CMP_EQ;
324 msg (SE, _("When applying GROUPS to a string variable, two "
325 "values must be specified."));
333 add_pair (struct t_test_proc *proc,
334 const struct variable *v0, const struct variable *v1)
336 struct pair *p = &proc->pairs[proc->n_pairs++];
342 tts_custom_pairs (struct lexer *lexer, struct dataset *ds,
343 struct cmd_t_test *cmd UNUSED, void *proc_)
345 struct t_test_proc *proc = proc_;
347 const struct variable **vars1 = NULL;
350 const struct variable **vars2 = NULL;
355 size_t n_total_pairs;
358 lex_match (lexer, '=');
360 if (!parse_variables_const (lexer, dataset_dict (ds), &vars1, &n_vars1,
361 PV_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH))
364 if (lex_match (lexer, T_WITH))
366 if (!parse_variables_const (lexer, dataset_dict (ds), &vars2, &n_vars2,
367 PV_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH))
373 if (lex_match (lexer, '(')
374 && lex_match_id (lexer, "PAIRED")
375 && lex_match (lexer, ')'))
378 if (n_vars1 != n_vars2)
380 msg (SE, _("PAIRED was specified but the number of variables "
381 "preceding WITH (%zu) did not match the number "
395 msg (SE, _("At least two variables must be specified on PAIRS."));
400 /* Allocate storage for the new pairs. */
401 n_total_pairs = proc->n_pairs + (paired ? n_vars1
402 : n_vars2 > 0 ? n_vars1 * n_vars2
403 : n_vars1 * (n_vars1 - 1) / 2);
404 proc->pairs = xnrealloc (proc->pairs, n_total_pairs, sizeof *proc->pairs);
406 /* Populate the pairs with the appropriate variables. */
408 for (i = 0; i < n_vars1; i++)
409 add_pair (proc, vars1[i], vars2[i]);
410 else if (n_vars2 > 0)
411 for (i = 0; i < n_vars1; i++)
412 for (j = 0; j < n_vars2; j++)
413 add_pair (proc, vars1[i], vars2[j]);
415 for (i = 0; i < n_vars1; i++)
416 for (j = i + 1; j < n_vars1; j++)
417 add_pair (proc, vars1[i], vars1[j]);
418 assert (proc->n_pairs == n_total_pairs);
425 /* Implementation of the SSBOX object. */
427 static void ssbox_base_init (struct ssbox *, int cols, int rows);
428 static void ssbox_base_finalize (struct ssbox *);
429 static void ssbox_one_sample_init (struct ssbox *, struct t_test_proc *);
430 static void ssbox_independent_samples_init (struct ssbox *, struct t_test_proc *);
431 static void ssbox_paired_init (struct ssbox *, struct t_test_proc *);
433 /* Factory to create an ssbox. */
435 ssbox_create (struct ssbox *ssb, struct t_test_proc *proc)
440 ssbox_one_sample_init (ssb, proc);
443 ssbox_independent_samples_init (ssb, proc);
446 ssbox_paired_init (ssb, proc);
453 /* Despatcher for the populate method */
455 ssbox_populate (struct ssbox *ssb, struct t_test_proc *proc)
457 ssb->populate (ssb, proc);
460 /* Despatcher for finalize */
462 ssbox_finalize (struct ssbox *ssb)
467 /* Submit the box and clear up */
469 ssbox_base_finalize (struct ssbox *ssb)
474 /* Initialize a ssbox struct */
476 ssbox_base_init (struct ssbox *this, int cols, int rows)
478 this->finalize = ssbox_base_finalize;
479 this->t = tab_create (cols, rows);
481 tab_columns (this->t, SOM_COL_DOWN);
482 tab_headers (this->t, 0, 0, 1, 0);
483 tab_box (this->t, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, cols - 1, rows - 1);
484 tab_hline (this->t, TAL_2, 0, cols- 1, 1);
485 tab_dim (this->t, tab_natural_dimensions, NULL, NULL);
488 /* ssbox implementations. */
490 static void ssbox_one_sample_populate (struct ssbox *, struct t_test_proc *);
491 static void ssbox_independent_samples_populate (struct ssbox *,
492 struct t_test_proc *);
493 static void ssbox_paired_populate (struct ssbox *, struct t_test_proc *);
495 /* Initialize the one_sample ssbox */
497 ssbox_one_sample_init (struct ssbox *this, struct t_test_proc *proc)
500 const int vsize = proc->n_vars + 1;
502 this->populate = ssbox_one_sample_populate;
504 ssbox_base_init (this, hsize, vsize);
505 tab_title (this->t, _("One-Sample Statistics"));
506 tab_vline (this->t, TAL_2, 1, 0, vsize - 1);
507 tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, _("N"));
508 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
509 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
510 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("S.E. Mean"));
513 /* Initialize the independent samples ssbox */
515 ssbox_independent_samples_init (struct ssbox *this, struct t_test_proc *proc)
518 int vsize = proc->n_vars * 2 + 1;
520 this->populate = ssbox_independent_samples_populate;
522 ssbox_base_init (this, hsize, vsize);
523 tab_vline (this->t, TAL_GAP, 1, 0, vsize - 1);
524 tab_title (this->t, _("Group Statistics"));
525 tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE,
526 var_get_name (proc->indep_var));
527 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("N"));
528 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
529 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
530 tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("S.E. Mean"));
533 /* Populate the ssbox for independent samples */
535 ssbox_independent_samples_populate (struct ssbox *ssb,
536 struct t_test_proc *proc)
541 double indep_value[2];
545 for (i = 0; i < 2; i++)
547 union value *value = &proc->g_value[i];
548 int width = var_get_width (proc->indep_var);
550 indep_value[i] = (proc->criterion == CMP_LE ? proc->critical_value
553 if (val_type_from_width (width) == VAL_NUMERIC)
555 const char *s = var_lookup_value_label (proc->indep_var, value);
556 val_lab[i] = s ? xstrdup (s) : xasprintf ("%g", indep_value[i]);
559 val_lab[i] = xmemdup0 (value_str (value, width), width);
562 if (proc->criterion == CMP_LE)
564 strcpy (prefix[0], ">=");
565 strcpy (prefix[1], "<");
569 strcpy (prefix[0], "");
570 strcpy (prefix[1], "");
573 for (i = 0; i < proc->n_vars; i++)
575 const struct variable *var = proc->vars[i];
576 struct hsh_table *grp_hash = group_proc_get (var)->group_hash;
579 tab_text (ssb->t, 0, i * 2 + 1, TAB_LEFT,
580 var_get_name (proc->vars[i]));
581 tab_text_format (ssb->t, 1, i * 2 + 1, TAB_LEFT,
582 "%s%s", prefix[0], val_lab[0]);
583 tab_text_format (ssb->t, 1, i * 2 + 1+ 1, TAB_LEFT,
584 "%s%s", prefix[1], val_lab[1]);
586 /* Fill in the group statistics */
587 for (count = 0; count < 2; count++)
589 union value search_val;
590 struct group_statistics *gs;
592 if (proc->criterion == CMP_LE)
593 search_val.f = proc->critical_value + (count == 0 ? 1.0 : -1.0);
595 search_val = proc->g_value[count];
597 gs = hsh_find (grp_hash, &search_val);
600 tab_double (ssb->t, 2, i * 2 + count+ 1, TAB_RIGHT, gs->n,
601 &proc->weight_format);
602 tab_double (ssb->t, 3, i * 2 + count+ 1, TAB_RIGHT, gs->mean, NULL);
603 tab_double (ssb->t, 4, i * 2 + count+ 1, TAB_RIGHT, gs->std_dev,
605 tab_double (ssb->t, 5, i * 2 + count+ 1, TAB_RIGHT, gs->se_mean,
613 /* Initialize the paired values ssbox */
615 ssbox_paired_init (struct ssbox *this, struct t_test_proc *proc)
618 int vsize = proc->n_pairs * 2 + 1;
620 this->populate = ssbox_paired_populate;
622 ssbox_base_init (this, hsize, vsize);
623 tab_title (this->t, _("Paired Sample Statistics"));
624 tab_vline (this->t, TAL_GAP, 1, 0, vsize - 1);
625 tab_vline (this->t, TAL_2, 2, 0, vsize - 1);
626 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
627 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("N"));
628 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
629 tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("S.E. Mean"));
632 /* Populate the ssbox for paired values */
634 ssbox_paired_populate (struct ssbox *ssb, struct t_test_proc *proc)
638 for (i = 0; i < proc->n_pairs; i++)
640 struct pair *p = &proc->pairs[i];
643 tab_text_format (ssb->t, 0, i * 2 + 1, TAB_LEFT, _("Pair %d"), i);
644 for (j=0; j < 2; j++)
647 tab_text (ssb->t, 1, i * 2 + j + 1, TAB_LEFT,
648 var_get_name (p->v[j]));
651 tab_double (ssb->t, 2, i * 2 + j + 1, TAB_RIGHT, p->mean[j], NULL);
652 tab_double (ssb->t, 3, i * 2 + j + 1, TAB_RIGHT, p->n,
653 &proc->weight_format);
654 tab_double (ssb->t, 4, i * 2 + j + 1, TAB_RIGHT, p->std_dev[j],
656 tab_double (ssb->t, 5, i * 2 + j + 1, TAB_RIGHT,
657 p->std_dev[j] /sqrt (p->n), NULL);
662 /* Populate the one sample ssbox */
664 ssbox_one_sample_populate (struct ssbox *ssb, struct t_test_proc *proc)
668 for (i = 0; i < proc->n_vars; i++)
670 struct group_statistics *gs = &group_proc_get (proc->vars[i])->ugs;
672 tab_text (ssb->t, 0, i + 1, TAB_LEFT, var_get_name (proc->vars[i]));
673 tab_double (ssb->t, 1, i + 1, TAB_RIGHT, gs->n, &proc->weight_format);
674 tab_double (ssb->t, 2, i + 1, TAB_RIGHT, gs->mean, NULL);
675 tab_double (ssb->t, 3, i + 1, TAB_RIGHT, gs->std_dev, NULL);
676 tab_double (ssb->t, 4, i + 1, TAB_RIGHT, gs->se_mean, NULL);
680 /* Implementation of the Test Results box struct */
682 static void trbox_base_init (struct trbox *, size_t n_vars, int cols);
683 static void trbox_base_finalize (struct trbox *);
684 static void trbox_independent_samples_init (struct trbox *,
685 struct t_test_proc *);
686 static void trbox_independent_samples_populate (struct trbox *,
687 struct t_test_proc *);
688 static void trbox_one_sample_init (struct trbox *, struct t_test_proc *);
689 static void trbox_one_sample_populate (struct trbox *, struct t_test_proc *);
690 static void trbox_paired_init (struct trbox *, struct t_test_proc *);
691 static void trbox_paired_populate (struct trbox *, struct t_test_proc *);
693 /* Create a trbox according to mode*/
695 trbox_create (struct trbox *trb, struct t_test_proc *proc)
700 trbox_one_sample_init (trb, proc);
703 trbox_independent_samples_init (trb, proc);
706 trbox_paired_init (trb, proc);
713 /* Populate a trbox according to proc */
715 trbox_populate (struct trbox *trb, struct t_test_proc *proc)
717 trb->populate (trb, proc);
720 /* Submit and destroy a trbox */
722 trbox_finalize (struct trbox *trb)
727 /* Initialize the independent samples trbox */
729 trbox_independent_samples_init (struct trbox *self,
730 struct t_test_proc *proc)
732 const int hsize = 11;
733 const int vsize = proc->n_vars * 2 + 3;
736 self->populate = trbox_independent_samples_populate;
738 trbox_base_init (self, proc->n_vars * 2, hsize);
739 tab_title (self->t, _("Independent Samples Test"));
740 tab_hline (self->t, TAL_1, 2, hsize - 1, 1);
741 tab_vline (self->t, TAL_2, 2, 0, vsize - 1);
742 tab_vline (self->t, TAL_1, 4, 0, vsize - 1);
743 tab_box (self->t, -1, -1, -1, TAL_1, 2, 1, hsize - 2, vsize - 1);
744 tab_hline (self->t, TAL_1, hsize - 2, hsize - 1, 2);
745 tab_box (self->t, -1, -1, -1, TAL_1, hsize - 2, 2, hsize - 1, vsize - 1);
746 tab_joint_text (self->t, 2, 0, 3, 0,
747 TAB_CENTER, _("Levene's Test for Equality of Variances"));
748 tab_joint_text (self->t, 4, 0, hsize- 1, 0,
749 TAB_CENTER, _("t-test for Equality of Means"));
751 tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("F"));
752 tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Sig."));
753 tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("t"));
754 tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("df"));
755 tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
756 tab_text (self->t, 7, 2, TAB_CENTER | TAT_TITLE, _("Mean Difference"));
757 tab_text (self->t, 8, 2, TAB_CENTER | TAT_TITLE, _("Std. Error Difference"));
758 tab_text (self->t, 9, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
759 tab_text (self->t, 10, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
761 tab_joint_text_format (self->t, 9, 1, 10, 1, TAB_CENTER,
762 _("%g%% Confidence Interval of the Difference"),
763 proc->criteria * 100.0);
766 /* Populate the independent samples trbox */
768 trbox_independent_samples_populate (struct trbox *self,
769 struct t_test_proc *proc)
773 for (i = 0; i < proc->n_vars; i++)
782 double pooled_variance;
788 const struct variable *var = proc->vars[i];
789 struct group_proc *grp_data = group_proc_get (var);
791 struct hsh_table *grp_hash = grp_data->group_hash;
793 struct group_statistics *gs0;
794 struct group_statistics *gs1;
796 union value search_val;
798 if (proc->criterion == CMP_LE)
799 search_val.f = proc->critical_value - 1.0;
801 search_val = proc->g_value[0];
803 gs0 = hsh_find (grp_hash, &search_val);
806 if (proc->criterion == CMP_LE)
807 search_val.f = proc->critical_value + 1.0;
809 search_val = proc->g_value[1];
811 gs1 = hsh_find (grp_hash, &search_val);
815 tab_text (self->t, 0, i * 2 + 3, TAB_LEFT, var_get_name (proc->vars[i]));
816 tab_text (self->t, 1, i * 2 + 3, TAB_LEFT, _("Equal variances assumed"));
817 tab_double (self->t, 2, i * 2 + 3, TAB_CENTER, grp_data->levene, NULL);
819 /* Now work out the significance of the Levene test */
821 df2 = grp_data->ugs.n - 2;
822 q = gsl_cdf_fdist_Q (grp_data->levene, df1, df2);
823 tab_double (self->t, 3, i * 2 + 3, TAB_CENTER, q, NULL);
825 df = gs0->n + gs1->n - 2.0;
826 tab_double (self->t, 5, i * 2 + 3, TAB_RIGHT, df, NULL);
828 pooled_variance = (gs0->n * pow2 (gs0->s_std_dev)
829 + gs1->n *pow2 (gs1->s_std_dev)) / df ;
831 t = (gs0->mean - gs1->mean) / sqrt (pooled_variance);
832 t /= sqrt ((gs0->n + gs1->n) / (gs0->n * gs1->n));
834 tab_double (self->t, 4, i * 2 + 3, TAB_RIGHT, t, NULL);
836 p = gsl_cdf_tdist_P (t, df);
837 q = gsl_cdf_tdist_Q (t, df);
839 tab_double (self->t, 6, i * 2 + 3, TAB_RIGHT, 2.0 * (t > 0 ? q : p),
842 mean_diff = gs0->mean - gs1->mean;
843 tab_double (self->t, 7, i * 2 + 3, TAB_RIGHT, mean_diff, NULL);
846 std_err_diff = sqrt (pow2 (gs0->se_mean) + pow2 (gs1->se_mean));
847 tab_double (self->t, 8, i * 2 + 3, TAB_RIGHT, std_err_diff, NULL);
849 /* Now work out the confidence interval */
850 q = (1 - proc->criteria)/2.0; /* 2-tailed test */
852 t = gsl_cdf_tdist_Qinv (q, df);
853 tab_double (self->t, 9, i * 2 + 3, TAB_RIGHT,
854 mean_diff - t * std_err_diff, NULL);
856 tab_double (self->t, 10, i * 2 + 3, TAB_RIGHT,
857 mean_diff + t * std_err_diff, NULL);
860 /* Now for the \sigma_1 != \sigma_2 case */
861 tab_text (self->t, 1, i * 2 + 3 + 1,
862 TAB_LEFT, _("Equal variances not assumed"));
864 se2 = ((pow2 (gs0->s_std_dev) / (gs0->n - 1)) +
865 (pow2 (gs1->s_std_dev) / (gs1->n - 1)));
867 t = mean_diff / sqrt (se2);
868 tab_double (self->t, 4, i * 2 + 3 + 1, TAB_RIGHT, t, NULL);
870 df = pow2 (se2) / ((pow2 (pow2 (gs0->s_std_dev) / (gs0->n - 1))
872 + (pow2 (pow2 (gs1->s_std_dev) / (gs1->n - 1))
874 tab_double (self->t, 5, i * 2 + 3 + 1, TAB_RIGHT, df, NULL);
876 p = gsl_cdf_tdist_P (t, df);
877 q = gsl_cdf_tdist_Q (t, df);
879 tab_double (self->t, 6, i * 2 + 3 + 1, TAB_RIGHT, 2.0 * (t > 0 ? q : p),
882 /* Now work out the confidence interval */
883 q = (1 - proc->criteria) / 2.0; /* 2-tailed test */
885 t = gsl_cdf_tdist_Qinv (q, df);
887 tab_double (self->t, 7, i * 2 + 3 + 1, TAB_RIGHT, mean_diff, NULL);
888 tab_double (self->t, 8, i * 2 + 3 + 1, TAB_RIGHT, std_err_diff, NULL);
889 tab_double (self->t, 9, i * 2 + 3 + 1, TAB_RIGHT,
890 mean_diff - t * std_err_diff, NULL);
891 tab_double (self->t, 10, i * 2 + 3 + 1, TAB_RIGHT,
892 mean_diff + t * std_err_diff, NULL);
896 /* Initialize the paired samples trbox */
898 trbox_paired_init (struct trbox *self, struct t_test_proc *proc)
901 const int vsize=proc->n_pairs+ 3;
903 self->populate = trbox_paired_populate;
905 trbox_base_init (self, proc->n_pairs, hsize);
906 tab_title (self->t, _("Paired Samples Test"));
907 tab_hline (self->t, TAL_1, 2, 6, 1);
908 tab_vline (self->t, TAL_2, 2, 0, vsize - 1);
909 tab_joint_text (self->t, 2, 0, 6, 0, TAB_CENTER, _("Paired Differences"));
910 tab_box (self->t, -1, -1, -1, TAL_1, 2, 1, 6, vsize - 1);
911 tab_box (self->t, -1, -1, -1, TAL_1, 6, 0, hsize - 1, vsize - 1);
912 tab_hline (self->t, TAL_1, 5, 6, 2);
913 tab_vline (self->t, TAL_GAP, 6, 0, 1);
915 tab_joint_text_format (self->t, 5, 1, 6, 1, TAB_CENTER,
916 _("%g%% Confidence Interval of the Difference"),
917 proc->criteria*100.0);
919 tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("Mean"));
920 tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
921 tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Std. Error Mean"));
922 tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
923 tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
924 tab_text (self->t, 7, 2, TAB_CENTER | TAT_TITLE, _("t"));
925 tab_text (self->t, 8, 2, TAB_CENTER | TAT_TITLE, _("df"));
926 tab_text (self->t, 9, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
929 /* Populate the paired samples trbox */
931 trbox_paired_populate (struct trbox *trb,
932 struct t_test_proc *proc)
936 for (i = 0; i < proc->n_pairs; i++)
938 struct pair *pair = &proc->pairs[i];
946 tab_text_format (trb->t, 0, i + 3, TAB_LEFT, _("Pair %d"), i);
947 tab_text_format (trb->t, 1, i + 3, TAB_LEFT, "%s - %s",
948 var_get_name (pair->v[0]),
949 var_get_name (pair->v[1]));
950 tab_double (trb->t, 2, i + 3, TAB_RIGHT, pair->mean_diff, NULL);
951 tab_double (trb->t, 3, i + 3, TAB_RIGHT, pair->std_dev_diff, NULL);
954 se_mean = pair->std_dev_diff / sqrt (n);
955 tab_double (trb->t, 4, i + 3, TAB_RIGHT, se_mean, NULL);
957 /* Now work out the confidence interval */
958 q = (1 - proc->criteria) / 2.0; /* 2-tailed test */
960 t = gsl_cdf_tdist_Qinv (q, df);
962 tab_double (trb->t, 5, i + 3, TAB_RIGHT,
963 pair->mean_diff - t * se_mean, NULL);
964 tab_double (trb->t, 6, i + 3, TAB_RIGHT,
965 pair->mean_diff + t * se_mean, NULL);
967 t = ((pair->mean[0] - pair->mean[1])
968 / sqrt ((pow2 (pair->s_std_dev[0]) + pow2 (pair->s_std_dev[1])
969 - (2 * pair->correlation
970 * pair->s_std_dev[0] * pair->s_std_dev[1]))
973 tab_double (trb->t, 7, i + 3, TAB_RIGHT, t, NULL);
975 /* Degrees of freedom */
976 tab_double (trb->t, 8, i + 3, TAB_RIGHT, df, &proc->weight_format);
978 p = gsl_cdf_tdist_P (t,df);
979 q = gsl_cdf_tdist_Q (t,df);
981 tab_double (trb->t, 9, i + 3, TAB_RIGHT, 2.0 * (t > 0 ? q : p), NULL);
985 /* Initialize the one sample trbox */
987 trbox_one_sample_init (struct trbox *self, struct t_test_proc *proc)
990 const int vsize = proc->n_vars + 3;
992 self->populate = trbox_one_sample_populate;
994 trbox_base_init (self, proc->n_vars, hsize);
995 tab_title (self->t, _("One-Sample Test"));
996 tab_hline (self->t, TAL_1, 1, hsize - 1, 1);
997 tab_vline (self->t, TAL_2, 1, 0, vsize - 1);
999 tab_joint_text_format (self->t, 1, 0, hsize - 1, 0, TAB_CENTER,
1000 _("Test Value = %f"), proc->testval);
1002 tab_box (self->t, -1, -1, -1, TAL_1, 1, 1, hsize - 1, vsize - 1);
1005 tab_joint_text_format (self->t, 5, 1, 6, 1, TAB_CENTER,
1006 _("%g%% Confidence Interval of the Difference"),
1007 proc->criteria * 100.0);
1009 tab_vline (self->t, TAL_GAP, 6, 1, 1);
1010 tab_hline (self->t, TAL_1, 5, 6, 2);
1011 tab_text (self->t, 1, 2, TAB_CENTER | TAT_TITLE, _("t"));
1012 tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("df"));
1013 tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
1014 tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Mean Difference"));
1015 tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
1016 tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
1019 /* Populate the one sample trbox */
1021 trbox_one_sample_populate (struct trbox *trb, struct t_test_proc *proc)
1027 for (i = 0; i < proc->n_vars; i++)
1032 struct group_statistics *gs = &group_proc_get (proc->vars[i])->ugs;
1034 tab_text (trb->t, 0, i + 3, TAB_LEFT, var_get_name (proc->vars[i]));
1036 t = (gs->mean - proc->testval) * sqrt (gs->n) / gs->std_dev;
1038 tab_double (trb->t, 1, i + 3, TAB_RIGHT, t, NULL);
1040 /* degrees of freedom */
1043 tab_double (trb->t, 2, i + 3, TAB_RIGHT, df, &proc->weight_format);
1045 p = gsl_cdf_tdist_P (t, df);
1046 q = gsl_cdf_tdist_Q (t, df);
1048 /* Multiply by 2 to get 2-tailed significance, makeing sure we've got
1050 tab_double (trb->t, 3, i + 3, TAB_RIGHT, 2.0 * (t > 0 ? q : p), NULL);
1051 tab_double (trb->t, 4, i + 3, TAB_RIGHT, gs->mean_diff, NULL);
1054 q = (1 - proc->criteria) / 2.0; /* 2-tailed test */
1055 t = gsl_cdf_tdist_Qinv (q, df);
1057 tab_double (trb->t, 5, i + 3, TAB_RIGHT,
1058 gs->mean_diff - t * gs->se_mean, NULL);
1059 tab_double (trb->t, 6, i + 3, TAB_RIGHT,
1060 gs->mean_diff + t * gs->se_mean, NULL);
1064 /* Base initializer for the generalized trbox */
1066 trbox_base_init (struct trbox *self, size_t data_rows, int cols)
1068 const size_t rows = 3 + data_rows;
1070 self->finalize = trbox_base_finalize;
1071 self->t = tab_create (cols, rows);
1072 tab_headers (self->t, 0, 0, 3, 0);
1073 tab_box (self->t, TAL_2, TAL_2, TAL_0, TAL_0, 0, 0, cols - 1, rows - 1);
1074 tab_hline (self->t, TAL_2, 0, cols- 1, 3);
1075 tab_dim (self->t, tab_natural_dimensions, NULL, NULL);
1078 /* Base finalizer for the trbox */
1080 trbox_base_finalize (struct trbox *trb)
1082 tab_submit (trb->t);
1085 /* Create, populate and submit the Paired Samples Correlation box */
1087 pscbox (struct t_test_proc *proc)
1089 const int rows=1+proc->n_pairs;
1093 struct tab_table *table;
1095 table = tab_create (cols, rows);
1097 tab_columns (table, SOM_COL_DOWN);
1098 tab_headers (table, 0, 0, 1, 0);
1099 tab_box (table, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, cols - 1, rows - 1);
1100 tab_hline (table, TAL_2, 0, cols - 1, 1);
1101 tab_vline (table, TAL_2, 2, 0, rows - 1);
1102 tab_dim (table, tab_natural_dimensions, NULL, NULL);
1103 tab_title (table, _("Paired Samples Correlations"));
1105 /* column headings */
1106 tab_text (table, 2, 0, TAB_CENTER | TAT_TITLE, _("N"));
1107 tab_text (table, 3, 0, TAB_CENTER | TAT_TITLE, _("Correlation"));
1108 tab_text (table, 4, 0, TAB_CENTER | TAT_TITLE, _("Sig."));
1110 for (i = 0; i < proc->n_pairs; i++)
1112 struct pair *pair = &proc->pairs[i];
1113 double df = pair->n - 2;
1116 /* corr2 will mathematically always be in the range [0, 1.0]. Inaccurate
1117 calculations sometimes cause it to be slightly greater than 1.0, so
1118 force it into the correct range to avoid NaN from sqrt(). */
1119 double corr2 = MIN (1.0, pow2 (pair->correlation));
1120 double correlation_t = pair->correlation * sqrt (df) / sqrt (1 - corr2);
1123 tab_text_format (table, 0, i + 1, TAB_LEFT | TAT_TITLE,
1125 tab_text_format (table, 1, i + 1, TAB_LEFT | TAT_TITLE,
1127 var_get_name (pair->v[0]),
1128 var_get_name (pair->v[1]));
1131 tab_double (table, 2, i + 1, TAB_RIGHT, pair->n, &proc->weight_format);
1132 tab_double (table, 3, i + 1, TAB_RIGHT, pair->correlation, NULL);
1134 p = gsl_cdf_tdist_P (correlation_t, df);
1135 q = gsl_cdf_tdist_Q (correlation_t, df);
1136 tab_double (table, 4, i + 1, TAB_RIGHT,
1137 2.0 * (correlation_t > 0 ? q : p), NULL);
1143 /* Calculation Implementation */
1145 /* Calculations common to all variants of the T test. */
1147 common_calc (const struct dictionary *dict,
1148 struct t_test_proc *proc,
1149 struct casereader *reader)
1154 for (i = 0; i < proc->n_vars; i++)
1156 struct group_statistics *gs = &group_proc_get (proc->vars[i])->ugs;
1163 for (; (c = casereader_read (reader)) != NULL; case_unref (c))
1165 double weight = dict_get_case_weight (dict, c, NULL);
1167 /* Listwise has to be implicit if the independent variable
1169 if (proc->mode == T_IND_SAMPLES)
1171 if (var_is_value_missing (proc->indep_var,
1172 case_data (c, proc->indep_var),
1177 for (i = 0; i < proc->n_vars; i++)
1179 const struct variable *v = proc->vars[i];
1180 const union value *val = case_data (c, v);
1182 if (!var_is_value_missing (v, val, proc->exclude))
1184 struct group_statistics *gs;
1185 gs = &group_proc_get (v)->ugs;
1188 gs->sum += weight * val->f;
1189 gs->ssq += weight * pow2 (val->f);
1193 casereader_destroy (reader);
1195 for (i = 0; i < proc->n_vars; i++)
1197 struct group_statistics *gs = &group_proc_get (proc->vars[i])->ugs;
1199 gs->mean = gs->sum / gs->n;
1200 gs->s_std_dev = sqrt (((gs->ssq / gs->n) - pow2 (gs->mean)));
1201 gs->std_dev = sqrt (gs->n / (gs->n- 1)
1202 * ((gs->ssq / gs->n) - pow2 (gs->mean)));
1203 gs->se_mean = gs->std_dev / sqrt (gs->n);
1204 gs->mean_diff = gs->sum_diff / gs->n;
1208 /* Calculations for one sample T test. */
1210 one_sample_calc (const struct dictionary *dict, struct t_test_proc *proc,
1211 struct casereader *reader)
1216 for (i = 0; i < proc->n_vars; i++)
1218 struct group_statistics *gs = &group_proc_get (proc->vars[i])->ugs;
1222 for (; (c = casereader_read (reader)) != NULL; case_unref (c))
1224 double weight = dict_get_case_weight (dict, c, NULL);
1225 for (i = 0; i < proc->n_vars; i++)
1227 const struct variable *v = proc->vars[i];
1228 struct group_statistics *gs = &group_proc_get (v)->ugs;
1229 const union value *val = case_data (c, v);
1230 if (!var_is_value_missing (v, val, proc->exclude))
1231 gs->sum_diff += weight * (val->f - proc->testval);
1235 for (i = 0; i < proc->n_vars; i++)
1237 struct group_statistics *gs = &group_proc_get (proc->vars[i])->ugs;
1238 gs->mean_diff = gs->sum_diff / gs->n;
1241 casereader_destroy (reader);
1247 paired_calc (const struct dictionary *dict, struct t_test_proc *proc,
1248 struct casereader *reader)
1253 for (i = 0; i < proc->n_pairs; i++)
1255 struct pair *pair = &proc->pairs[i];
1257 pair->sum[0] = pair->sum[1] = 0;
1258 pair->ssq[0] = pair->ssq[1] = 0;
1259 pair->sum_of_prod = 0;
1260 pair->correlation = 0;
1261 pair->sum_of_diffs = 0;
1262 pair->ssq_diffs = 0;
1265 for (; (c = casereader_read (reader)) != NULL; case_unref (c))
1267 double weight = dict_get_case_weight (dict, c, NULL);
1268 for (i = 0; i < proc->n_pairs; i++)
1270 struct pair *pair = &proc->pairs[i];
1271 const struct variable *v0 = pair->v[0];
1272 const struct variable *v1 = pair->v[1];
1274 const union value *val0 = case_data (c, v0);
1275 const union value *val1 = case_data (c, v1);
1277 if (!var_is_value_missing (v0, val0, proc->exclude)
1278 && !var_is_value_missing (v1, val1, proc->exclude))
1281 pair->sum[0] += weight * val0->f;
1282 pair->sum[1] += weight * val1->f;
1283 pair->ssq[0] += weight * pow2 (val0->f);
1284 pair->ssq[1] += weight * pow2 (val1->f);
1285 pair->sum_of_prod += weight * val0->f * val1->f;
1286 pair->sum_of_diffs += weight * (val0->f - val1->f);
1287 pair->ssq_diffs += weight * pow2 (val0->f - val1->f);
1292 for (i = 0; i < proc->n_pairs; i++)
1294 struct pair *pair = &proc->pairs[i];
1295 const double n = pair->n;
1298 for (j=0; j < 2; j++)
1300 pair->mean[j] = pair->sum[j] / n;
1301 pair->s_std_dev[j] = sqrt ((pair->ssq[j] / n
1302 - pow2 (pair->mean[j])));
1303 pair->std_dev[j] = sqrt (n / (n- 1) * (pair->ssq[j] / n
1304 - pow2 (pair->mean[j])));
1307 pair->correlation = (pair->sum_of_prod / pair->n
1308 - pair->mean[0] * pair->mean[1]);
1309 /* correlation now actually contains the covariance */
1310 pair->correlation /= pair->std_dev[0] * pair->std_dev[1];
1311 pair->correlation *= pair->n / (pair->n - 1);
1313 pair->mean_diff = pair->sum_of_diffs / n;
1314 pair->std_dev_diff = sqrt (n / (n - 1) * ((pair->ssq_diffs / n)
1315 - pow2 (pair->mean_diff)));
1318 casereader_destroy (reader);
1323 group_calc (const struct dictionary *dict, struct t_test_proc *proc,
1324 struct casereader *reader)
1329 for (i = 0; i < proc->n_vars; i++)
1331 struct group_proc *ttpr = group_proc_get (proc->vars[i]);
1334 /* There's always 2 groups for a T - TEST */
1336 ttpr->group_hash = hsh_create (2,
1337 (hsh_compare_func *) compare_group_binary,
1338 (hsh_hash_func *) hash_group_binary,
1339 (hsh_free_func *) free_group,
1342 for (j = 0; j < 2; j++)
1344 struct group_statistics *gs = xmalloc (sizeof *gs);
1348 if (proc->criterion == CMP_EQ)
1349 gs->id = proc->g_value[j];
1353 gs->id.f = proc->critical_value - 1.0;
1355 gs->id.f = proc->critical_value + 1.0;
1358 hsh_insert (ttpr->group_hash, gs);
1362 for (; (c = casereader_read (reader)) != NULL; case_unref (c))
1364 const double weight = dict_get_case_weight (dict, c, NULL);
1365 const union value *gv;
1367 if (var_is_value_missing (proc->indep_var,
1368 case_data (c, proc->indep_var), proc->exclude))
1371 gv = case_data (c, proc->indep_var);
1372 for (i = 0; i < proc->n_vars; i++)
1374 const struct variable *var = proc->vars[i];
1375 const union value *val = case_data (c, var);
1376 struct hsh_table *grp_hash = group_proc_get (var)->group_hash;
1377 struct group_statistics *gs = hsh_find (grp_hash, gv);
1379 /* If the independent variable doesn't match either of the values
1380 for this case then move on to the next case. */
1384 if (!var_is_value_missing (var, val, proc->exclude))
1387 gs->sum += weight * val->f;
1388 gs->ssq += weight * pow2 (val->f);
1393 for (i = 0; i < proc->n_vars; i++)
1395 const struct variable *var = proc->vars[i];
1396 struct hsh_table *grp_hash = group_proc_get (var)->group_hash;
1397 struct hsh_iterator g;
1398 struct group_statistics *gs;
1401 for (gs = hsh_first (grp_hash, &g); gs != NULL;
1402 gs = hsh_next (grp_hash, &g))
1404 gs->mean = gs->sum / gs->n;
1405 gs->s_std_dev = sqrt (((gs->ssq / gs->n) - pow2 (gs->mean)));
1406 gs->std_dev = sqrt (gs->n / (gs->n- 1)
1407 * ((gs->ssq / gs->n) - pow2 (gs->mean)));
1408 gs->se_mean = gs->std_dev / sqrt (gs->n);
1411 assert (count == 2);
1414 casereader_destroy (reader);
1420 calculate (struct t_test_proc *proc,
1421 struct casereader *input, const struct dataset *ds)
1423 const struct dictionary *dict = dataset_dict (ds);
1424 struct ssbox stat_summary_box;
1425 struct trbox test_results_box;
1426 struct taint *taint;
1429 c = casereader_peek (input, 0);
1432 casereader_destroy (input);
1435 output_split_file_values (ds, c);
1438 if (proc->listwise_missing)
1439 input = casereader_create_filter_missing (input,
1442 proc->exclude, NULL, NULL);
1443 input = casereader_create_filter_weight (input, dict, NULL, NULL);
1444 taint = taint_clone (casereader_get_taint (input));
1446 common_calc (dict, proc, casereader_clone (input));
1450 one_sample_calc (dict, proc, input);
1453 paired_calc (dict, proc, input);
1456 group_calc (dict, proc, casereader_clone (input));
1457 levene (dict, input, proc->indep_var, proc->n_vars, proc->vars,
1464 if (!taint_has_tainted_successor (taint))
1466 ssbox_create (&stat_summary_box, proc);
1467 ssbox_populate (&stat_summary_box, proc);
1468 ssbox_finalize (&stat_summary_box);
1470 if (proc->mode == T_PAIRED)
1473 trbox_create (&test_results_box, proc);
1474 trbox_populate (&test_results_box, proc);
1475 trbox_finalize (&test_results_box);
1478 taint_destroy (taint);
1481 /* return 0 if G belongs to group 0,
1482 1 if it belongs to group 1,
1483 2 if it belongs to neither group */
1485 which_group (const struct group_statistics *g,
1486 const struct t_test_proc *proc)
1488 int width = var_get_width (proc->indep_var);
1490 if (0 == value_compare_3way (&g->id, &proc->g_value[0], width))
1493 if (0 == value_compare_3way (&g->id, &proc->g_value[1], width))
1499 /* Return -1 if the id of a is less than b; +1 if greater than and
1502 compare_group_binary (const struct group_statistics *a,
1503 const struct group_statistics *b,
1504 const struct t_test_proc *proc)
1509 if (proc->criterion == CMP_LE)
1511 flag_a = (a->id.f < proc->critical_value);
1512 flag_b = (b->id.f < proc->critical_value);
1516 flag_a = which_group (a, proc);
1517 flag_b = which_group (b, proc);
1520 if (flag_a < flag_b)
1523 return (flag_a > flag_b);
1526 /* This is a degenerate case of a hash, since it can only return three possible
1527 values. It's really a comparison, being used as a hash function */
1530 hash_group_binary (const struct group_statistics *g,
1531 const struct t_test_proc *proc)
1533 return (proc->criterion == CMP_LE
1534 ? g->id.f < proc->critical_value
1535 : which_group (g, proc));