1 /* PSPP - a program for statistical analysis. -*-c-*-
2 Copyright (C) 2006, 2008, 2009, 2010 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 <language/stats/npar.h>
20 #include "npar-summary.h"
27 #include <data/case.h>
28 #include <data/casegrouper.h>
29 #include <data/casereader.h>
30 #include <data/dictionary.h>
31 #include <data/procedure.h>
32 #include <data/settings.h>
33 #include <data/variable.h>
34 #include <libpspp/array.h>
35 #include <libpspp/assertion.h>
36 #include <libpspp/cast.h>
37 #include <libpspp/hmapx.h>
38 #include <libpspp/hash-functions.h>
39 #include <libpspp/message.h>
40 #include <libpspp/pool.h>
41 #include <libpspp/str.h>
42 #include <libpspp/taint.h>
43 #include <language/command.h>
44 #include <language/lexer/lexer.h>
45 #include <language/lexer/variable-parser.h>
46 #include <language/lexer/value-parser.h>
47 #include <language/stats/binomial.h>
48 #include <language/stats/chisquare.h>
49 #include <language/stats/cochran.h>
50 #include <language/stats/runs.h>
51 #include <language/stats/friedman.h>
52 #include <language/stats/kruskal-wallis.h>
53 #include <language/stats/mann-whitney.h>
54 #include <language/stats/wilcoxon.h>
55 #include <language/stats/sign.h>
56 #include <math/moments.h>
59 #define _(msgid) gettext (msgid)
61 /* Settings for subcommand specifiers. */
68 /* Array indices for STATISTICS subcommand. */
71 NPAR_ST_DESCRIPTIVES = 0,
72 NPAR_ST_QUARTILES = 1,
77 /* NPAR TESTS structure. */
80 /* Count variables indicating how many
81 of the subcommands have been given. */
95 /* How missing values should be treated */
98 /* Which statistics have been requested */
99 int a_statistics[NPAR_ST_count];
106 struct npar_test **test;
109 const struct variable **vv; /* Compendium of all variables
110 (those mentioned on ANY subcommand */
111 int n_vars; /* Number of variables in vv */
113 enum mv_class filter; /* Missing values to filter. */
115 bool descriptives; /* Descriptive statistics should be calculated */
116 bool quartiles; /* Quartiles should be calculated */
118 bool exact; /* Whether exact calculations have been requested */
119 double timer; /* Maximum time (in minutes) to wait for exact calculations */
123 /* Prototype for custom subcommands of NPAR TESTS. */
124 static int npar_chisquare (struct lexer *, struct dataset *, struct npar_specs *);
125 static int npar_binomial (struct lexer *, struct dataset *, struct npar_specs *);
126 static int npar_runs (struct lexer *, struct dataset *, struct npar_specs *);
127 static int npar_friedman (struct lexer *, struct dataset *, struct npar_specs *);
128 static int npar_cochran (struct lexer *, struct dataset *, struct npar_specs *);
129 static int npar_wilcoxon (struct lexer *, struct dataset *, struct npar_specs *);
130 static int npar_sign (struct lexer *, struct dataset *, struct npar_specs *);
131 static int npar_kruskal_wallis (struct lexer *, struct dataset *, struct npar_specs *);
132 static int npar_mann_whitney (struct lexer *, struct dataset *, struct npar_specs *);
133 static int npar_method (struct lexer *, struct npar_specs *);
135 /* Command parsing functions. */
136 static int parse_npar_tests (struct lexer *lexer, struct dataset *ds, struct cmd_npar_tests *p,
137 struct npar_specs *npar_specs );
140 parse_npar_tests (struct lexer *lexer, struct dataset *ds, struct cmd_npar_tests *npt,
141 struct npar_specs *nps)
147 npt->kruskal_wallis = 0;
148 npt->mann_whitney = 0;
153 npt->miss = MISS_ANALYSIS;
156 memset (npt->a_statistics, 0, sizeof npt->a_statistics);
159 if (lex_match_hyphenated_word (lexer, "COCHRAN"))
162 switch (npar_cochran (lexer, ds, nps))
169 lex_error (lexer, NULL);
175 else if (lex_match_hyphenated_word (lexer, "FRIEDMAN"))
178 switch (npar_friedman (lexer, ds, nps))
185 lex_error (lexer, NULL);
191 else if (lex_match_hyphenated_word (lexer, "RUNS"))
194 switch (npar_runs (lexer, ds, nps))
201 lex_error (lexer, NULL);
207 else if (lex_match_hyphenated_word (lexer, "CHISQUARE"))
209 lex_match (lexer, '=');
211 switch (npar_chisquare (lexer, ds, nps))
218 lex_error (lexer, NULL);
224 else if (lex_match_hyphenated_word (lexer, "BINOMIAL"))
226 lex_match (lexer, '=');
228 switch (npar_binomial (lexer, ds, nps))
235 lex_error (lexer, NULL);
241 else if (lex_match_hyphenated_word (lexer, "K-W") ||
242 lex_match_hyphenated_word (lexer, "KRUSKAL-WALLIS"))
244 lex_match (lexer, '=');
245 npt->kruskal_wallis++;
246 switch (npar_kruskal_wallis (lexer, ds, nps))
253 lex_error (lexer, NULL);
259 else if (lex_match_hyphenated_word (lexer, "M-W") ||
260 lex_match_hyphenated_word (lexer, "MANN-WHITNEY"))
262 lex_match (lexer, '=');
264 switch (npar_mann_whitney (lexer, ds, nps))
271 lex_error (lexer, NULL);
277 else if (lex_match_hyphenated_word (lexer, "WILCOXON"))
279 lex_match (lexer, '=');
281 switch (npar_wilcoxon (lexer, ds, nps))
288 lex_error (lexer, NULL);
294 else if (lex_match_hyphenated_word (lexer, "SIGN"))
296 lex_match (lexer, '=');
298 switch (npar_sign (lexer, ds, nps))
305 lex_error (lexer, NULL);
311 else if (lex_match_hyphenated_word (lexer, "MISSING"))
313 lex_match (lexer, '=');
315 if (npt->missing > 1)
317 msg (SE, _("The %s subcommand may be given only once."), "MISSING");
320 while (lex_token (lexer) != '/' && lex_token (lexer) != '.')
322 if (lex_match_hyphenated_word (lexer, "ANALYSIS"))
323 npt->miss = MISS_ANALYSIS;
324 else if (lex_match_hyphenated_word (lexer, "LISTWISE"))
325 npt->miss = MISS_LISTWISE;
326 else if (lex_match_hyphenated_word (lexer, "INCLUDE"))
327 nps->filter = MV_SYSTEM;
328 else if (lex_match_hyphenated_word (lexer, "EXCLUDE"))
329 nps->filter = MV_ANY;
332 lex_error (lexer, NULL);
335 lex_match (lexer, ',');
338 else if (lex_match_hyphenated_word (lexer, "METHOD"))
340 lex_match (lexer, '=');
344 msg (SE, _("The %s subcommand may be given only once."), "METHOD");
347 switch (npar_method (lexer, nps))
354 lex_error (lexer, NULL);
360 else if (lex_match_hyphenated_word (lexer, "STATISTICS"))
362 lex_match (lexer, '=');
364 while (lex_token (lexer) != '/' && lex_token (lexer) != '.')
366 if (lex_match_hyphenated_word (lexer, "DESCRIPTIVES"))
367 npt->a_statistics[NPAR_ST_DESCRIPTIVES] = 1;
368 else if (lex_match_hyphenated_word (lexer, "QUARTILES"))
369 npt->a_statistics[NPAR_ST_QUARTILES] = 1;
370 else if (lex_match (lexer, T_ALL))
371 npt->a_statistics[NPAR_ST_ALL] = 1;
374 lex_error (lexer, NULL);
377 lex_match (lexer, ',');
380 else if ( settings_get_syntax () != COMPATIBLE && lex_match_id (lexer, "ALGORITHM"))
382 lex_match (lexer, '=');
383 if (lex_match_id (lexer, "COMPATIBLE"))
384 settings_set_cmd_algorithm (COMPATIBLE);
385 else if (lex_match_id (lexer, "ENHANCED"))
386 settings_set_cmd_algorithm (ENHANCED);
388 if (!lex_match (lexer, '/'))
392 if (lex_token (lexer) != '.')
394 lex_error (lexer, _("expecting end of command"));
405 static void one_sample_insert_variables (const struct npar_test *test,
408 static void two_sample_insert_variables (const struct npar_test *test,
411 static void n_sample_insert_variables (const struct npar_test *test,
415 npar_execute (struct casereader *input,
416 const struct npar_specs *specs,
417 const struct dataset *ds)
420 struct descriptives *summary_descriptives = NULL;
422 for ( t = 0 ; t < specs->n_tests; ++t )
424 const struct npar_test *test = specs->test[t];
425 if ( NULL == test->execute )
427 msg (SW, _("NPAR subcommand not currently implemented."));
430 test->execute (ds, casereader_clone (input), specs->filter, test, specs->exact, specs->timer);
433 if ( specs->descriptives )
435 summary_descriptives = xnmalloc (sizeof (*summary_descriptives),
438 npar_summary_calc_descriptives (summary_descriptives,
439 casereader_clone (input),
441 specs->vv, specs->n_vars,
445 if ( (specs->descriptives || specs->quartiles)
446 && !taint_has_tainted_successor (casereader_get_taint (input)) )
447 do_summary_box (summary_descriptives, specs->vv, specs->n_vars );
449 free (summary_descriptives);
450 casereader_destroy (input);
454 cmd_npar_tests (struct lexer *lexer, struct dataset *ds)
456 struct cmd_npar_tests cmd;
459 struct npar_specs npar_specs = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
460 struct casegrouper *grouper;
461 struct casereader *input, *group;
462 struct hmapx var_map = HMAPX_INITIALIZER (var_map);
465 npar_specs.pool = pool_create ();
466 npar_specs.filter = MV_ANY;
467 npar_specs.n_vars = -1;
468 npar_specs.vv = NULL;
470 if ( ! parse_npar_tests (lexer, ds, &cmd, &npar_specs) )
472 pool_destroy (npar_specs.pool);
476 for (i = 0; i < npar_specs.n_tests; ++i )
478 const struct npar_test *test = npar_specs.test[i];
479 test->insert_variables (test, &var_map);
483 struct hmapx_node *node;
484 struct variable *var;
485 npar_specs.n_vars = 0;
487 HMAPX_FOR_EACH (var, node, &var_map)
489 npar_specs.n_vars ++;
490 npar_specs.vv = pool_nrealloc (npar_specs.pool, npar_specs.vv, npar_specs.n_vars, sizeof (*npar_specs.vv));
491 npar_specs.vv[npar_specs.n_vars - 1] = var;
495 sort (npar_specs.vv, npar_specs.n_vars, sizeof (*npar_specs.vv),
496 compare_var_ptrs_by_name, NULL);
498 if ( cmd.statistics )
502 for ( i = 0 ; i < NPAR_ST_count; ++i )
504 if ( cmd.a_statistics[i] )
508 case NPAR_ST_DESCRIPTIVES:
509 npar_specs.descriptives = true;
511 case NPAR_ST_QUARTILES:
512 npar_specs.quartiles = true;
515 npar_specs.quartiles = true;
516 npar_specs.descriptives = true;
525 input = proc_open (ds);
526 if ( cmd.miss == MISS_LISTWISE )
528 input = casereader_create_filter_missing (input,
536 grouper = casegrouper_create_splits (input, dataset_dict (ds));
537 while (casegrouper_get_next_group (grouper, &group))
538 npar_execute (group, &npar_specs, ds);
539 ok = casegrouper_destroy (grouper);
540 ok = proc_commit (ds) && ok;
542 pool_destroy (npar_specs.pool);
543 hmapx_destroy (&var_map);
545 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
549 npar_runs (struct lexer *lexer, struct dataset *ds,
550 struct npar_specs *specs)
552 struct runs_test *rt = pool_alloc (specs->pool, sizeof (*rt));
553 struct one_sample_test *tp = &rt->parent;
554 struct npar_test *nt = &tp->parent;
556 nt->execute = runs_execute;
557 nt->insert_variables = one_sample_insert_variables;
559 if ( lex_force_match (lexer, '(') )
561 if ( lex_match_id (lexer, "MEAN"))
563 rt->cp_mode = CP_MEAN;
565 else if (lex_match_id (lexer, "MEDIAN"))
567 rt->cp_mode = CP_MEDIAN;
569 else if (lex_match_id (lexer, "MODE"))
571 rt->cp_mode = CP_MODE;
573 else if (lex_is_number (lexer))
575 rt->cutpoint = lex_number (lexer);
576 rt->cp_mode = CP_CUSTOM;
581 lex_error (lexer, _("Expecting MEAN, MEDIAN, MODE or number"));
585 lex_force_match (lexer, ')');
586 lex_force_match (lexer, '=');
587 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
588 &tp->vars, &tp->n_vars,
589 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
596 specs->test = pool_realloc (specs->pool,
598 sizeof (*specs->test) * specs->n_tests);
600 specs->test[specs->n_tests - 1] = nt;
606 npar_friedman (struct lexer *lexer, struct dataset *ds,
607 struct npar_specs *specs)
609 struct one_sample_test *ft = pool_alloc (specs->pool, sizeof (*ft));
610 struct npar_test *nt = &ft->parent;
612 nt->execute = friedman_execute;
613 nt->insert_variables = one_sample_insert_variables;
615 lex_match (lexer, '=');
617 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
618 &ft->vars, &ft->n_vars,
619 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
625 specs->test = pool_realloc (specs->pool,
627 sizeof (*specs->test) * specs->n_tests);
629 specs->test[specs->n_tests - 1] = nt;
635 npar_cochran (struct lexer *lexer, struct dataset *ds,
636 struct npar_specs *specs)
638 struct one_sample_test *ft = pool_alloc (specs->pool, sizeof (*ft));
639 struct npar_test *nt = &ft->parent;
641 nt->execute = cochran_execute;
642 nt->insert_variables = one_sample_insert_variables;
644 lex_match (lexer, '=');
646 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
647 &ft->vars, &ft->n_vars,
648 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
654 specs->test = pool_realloc (specs->pool,
656 sizeof (*specs->test) * specs->n_tests);
658 specs->test[specs->n_tests - 1] = nt;
665 npar_chisquare (struct lexer *lexer, struct dataset *ds,
666 struct npar_specs *specs)
668 struct chisquare_test *cstp = pool_alloc (specs->pool, sizeof (*cstp));
669 struct one_sample_test *tp = &cstp->parent;
670 struct npar_test *nt = &tp->parent;
673 nt->execute = chisquare_execute;
674 nt->insert_variables = one_sample_insert_variables;
676 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
677 &tp->vars, &tp->n_vars,
678 PV_NO_SCRATCH | PV_NO_DUPLICATE))
683 cstp->ranged = false;
685 if ( lex_match (lexer, '('))
688 if ( ! lex_force_num (lexer)) return 0;
689 cstp->lo = lex_integer (lexer);
691 lex_force_match (lexer, ',');
692 if (! lex_force_num (lexer) ) return 0;
693 cstp->hi = lex_integer (lexer);
694 if ( cstp->lo >= cstp->hi )
697 _("The specified value of HI (%d) is "
698 "lower than the specified value of LO (%d)"),
703 if (! lex_force_match (lexer, ')')) return 0;
706 cstp->n_expected = 0;
707 cstp->expected = NULL;
708 if ( lex_match (lexer, '/') )
710 if ( lex_match_id (lexer, "EXPECTED") )
712 lex_force_match (lexer, '=');
713 if ( ! lex_match_id (lexer, "EQUAL") )
717 while ( lex_is_number (lexer) )
721 f = lex_number (lexer);
723 if ( lex_match (lexer, '*'))
726 f = lex_number (lexer);
729 lex_match (lexer, ',');
731 cstp->n_expected += n;
732 cstp->expected = pool_realloc (specs->pool,
736 for ( i = cstp->n_expected - n ;
737 i < cstp->n_expected;
739 cstp->expected[i] = f;
745 lex_put_back (lexer, '/');
748 if ( cstp->ranged && cstp->n_expected > 0 &&
749 cstp->n_expected != cstp->hi - cstp->lo + 1 )
752 _("%d expected values were given, but the specified "
753 "range (%d-%d) requires exactly %d values."),
754 cstp->n_expected, cstp->lo, cstp->hi,
755 cstp->hi - cstp->lo +1);
760 specs->test = pool_realloc (specs->pool,
762 sizeof (*specs->test) * specs->n_tests);
764 specs->test[specs->n_tests - 1] = nt;
771 npar_binomial (struct lexer *lexer, struct dataset *ds,
772 struct npar_specs *specs)
774 struct binomial_test *btp = pool_alloc (specs->pool, sizeof (*btp));
775 struct one_sample_test *tp = &btp->parent;
776 struct npar_test *nt = &tp->parent;
778 nt->execute = binomial_execute;
779 nt->insert_variables = one_sample_insert_variables;
781 btp->category1 = btp->category2 = btp->cutpoint = SYSMIS;
785 if ( lex_match (lexer, '(') )
787 if ( lex_force_num (lexer) )
789 btp->p = lex_number (lexer);
791 lex_force_match (lexer, ')');
797 /* Kludge: q2c swallows the '=' so put it back here */
798 lex_put_back (lexer, '=');
800 if (lex_match (lexer, '=') )
802 if (parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
803 &tp->vars, &tp->n_vars,
804 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
806 if (lex_match (lexer, '('))
808 lex_force_num (lexer);
809 btp->category1 = lex_number (lexer);
811 if ( lex_match (lexer, ','))
813 if ( ! lex_force_num (lexer) ) return 2;
814 btp->category2 = lex_number (lexer);
819 btp->cutpoint = btp->category1;
822 lex_force_match (lexer, ')');
831 specs->test = pool_realloc (specs->pool,
833 sizeof (*specs->test) * specs->n_tests);
835 specs->test[specs->n_tests - 1] = nt;
842 parse_two_sample_related_test (struct lexer *lexer,
843 const struct dictionary *dict,
844 struct two_sample_test *test_parameters,
850 parse_two_sample_related_test (struct lexer *lexer,
851 const struct dictionary *dict,
852 struct two_sample_test *test_parameters,
859 const struct variable **vlist1;
862 const struct variable **vlist2;
865 test_parameters->parent.insert_variables = two_sample_insert_variables;
867 if (!parse_variables_const_pool (lexer, pool,
870 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
873 if ( lex_match (lexer, T_WITH))
876 if ( !parse_variables_const_pool (lexer, pool, dict,
878 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
881 paired = (lex_match (lexer, '(') &&
882 lex_match_id (lexer, "PAIRED") && lex_match (lexer, ')'));
890 if ( n_vlist1 != n_vlist2)
891 msg (SE, _("PAIRED was specified but the number of variables "
892 "preceding WITH (%zu) did not match the number "
893 "following (%zu)."), n_vlist1, n_vlist2);
895 test_parameters->n_pairs = n_vlist1 ;
899 test_parameters->n_pairs = n_vlist1 * n_vlist2;
904 test_parameters->n_pairs = (n_vlist1 * (n_vlist1 - 1)) / 2 ;
907 test_parameters->pairs =
908 pool_alloc (pool, sizeof ( variable_pair) * test_parameters->n_pairs);
915 assert (n_vlist1 == n_vlist2);
916 for ( i = 0 ; i < n_vlist1; ++i )
918 test_parameters->pairs[n][1] = vlist1[i];
919 test_parameters->pairs[n][0] = vlist2[i];
926 for ( i = 0 ; i < n_vlist1; ++i )
928 for ( j = 0 ; j < n_vlist2; ++j )
930 test_parameters->pairs[n][1] = vlist1[i];
931 test_parameters->pairs[n][0] = vlist2[j];
940 for ( i = 0 ; i < n_vlist1 - 1; ++i )
942 for ( j = i + 1 ; j < n_vlist1; ++j )
944 assert ( n < test_parameters->n_pairs);
945 test_parameters->pairs[n][1] = vlist1[i];
946 test_parameters->pairs[n][0] = vlist1[j];
952 assert ( n == test_parameters->n_pairs);
959 parse_n_sample_related_test (struct lexer *lexer,
960 const struct dictionary *dict,
961 struct n_sample_test *nst,
965 if (!parse_variables_const_pool (lexer, pool,
967 &nst->vars, &nst->n_vars,
968 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
971 if ( ! lex_force_match (lexer, T_BY))
974 nst->indep_var = parse_variable_const (lexer, dict);
976 if ( ! lex_force_match (lexer, '('))
979 value_init (&nst->val1, var_get_width (nst->indep_var));
980 if ( ! parse_value (lexer, &nst->val1, var_get_width (nst->indep_var)))
982 value_destroy (&nst->val1, var_get_width (nst->indep_var));
986 lex_match (lexer, ',');
988 value_init (&nst->val2, var_get_width (nst->indep_var));
989 if ( ! parse_value (lexer, &nst->val2, var_get_width (nst->indep_var)))
991 value_destroy (&nst->val2, var_get_width (nst->indep_var));
995 if ( ! lex_force_match (lexer, ')'))
1002 npar_wilcoxon (struct lexer *lexer,
1004 struct npar_specs *specs )
1008 struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1009 struct npar_test *nt = &tp->parent;
1010 nt->execute = wilcoxon_execute;
1012 if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
1017 specs->test = pool_realloc (specs->pool,
1019 sizeof (*specs->test) * specs->n_tests);
1020 specs->test[specs->n_tests - 1] = nt;
1027 npar_mann_whitney (struct lexer *lexer,
1029 struct npar_specs *specs )
1031 struct n_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1032 struct npar_test *nt = &tp->parent;
1034 nt->insert_variables = n_sample_insert_variables;
1035 nt->execute = mann_whitney_execute;
1037 if (!parse_n_sample_related_test (lexer, dataset_dict (ds),
1042 specs->test = pool_realloc (specs->pool,
1044 sizeof (*specs->test) * specs->n_tests);
1045 specs->test[specs->n_tests - 1] = nt;
1052 npar_sign (struct lexer *lexer, struct dataset *ds,
1053 struct npar_specs *specs)
1055 struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1056 struct npar_test *nt = &tp->parent;
1058 nt->execute = sign_execute;
1060 if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
1065 specs->test = pool_realloc (specs->pool,
1067 sizeof (*specs->test) * specs->n_tests);
1068 specs->test[specs->n_tests - 1] = nt;
1074 npar_kruskal_wallis (struct lexer *lexer, struct dataset *ds,
1075 struct npar_specs *specs)
1077 struct n_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1078 struct npar_test *nt = &tp->parent;
1080 nt->insert_variables = n_sample_insert_variables;
1082 nt->execute = kruskal_wallis_execute;
1084 if (!parse_n_sample_related_test (lexer, dataset_dict (ds),
1089 specs->test = pool_realloc (specs->pool,
1091 sizeof (*specs->test) * specs->n_tests);
1092 specs->test[specs->n_tests - 1] = nt;
1098 insert_variable_into_map (struct hmapx *var_map, const struct variable *var)
1100 size_t hash = hash_pointer (var, 0);
1101 struct hmapx_node *node;
1102 const struct variable *v = NULL;
1104 HMAPX_FOR_EACH_WITH_HASH (v, node, hash, var_map)
1110 hmapx_insert (var_map, CONST_CAST (struct variable *, var), hash);
1113 /* Insert the variables for TEST into VAR_MAP */
1115 one_sample_insert_variables (const struct npar_test *test,
1116 struct hmapx *var_map)
1119 const struct one_sample_test *ost = UP_CAST (test, const struct one_sample_test, parent);
1121 for ( i = 0 ; i < ost->n_vars ; ++i )
1122 insert_variable_into_map (var_map, ost->vars[i]);
1127 two_sample_insert_variables (const struct npar_test *test,
1128 struct hmapx *var_map)
1131 const struct two_sample_test *tst = UP_CAST (test, const struct two_sample_test, parent);
1133 for ( i = 0 ; i < tst->n_pairs ; ++i )
1135 variable_pair *pair = &tst->pairs[i];
1137 insert_variable_into_map (var_map, (*pair)[0]);
1138 insert_variable_into_map (var_map, (*pair)[1]);
1143 n_sample_insert_variables (const struct npar_test *test,
1144 struct hmapx *var_map)
1147 const struct n_sample_test *tst = UP_CAST (test, const struct n_sample_test, parent);
1149 for ( i = 0 ; i < tst->n_vars ; ++i )
1150 insert_variable_into_map (var_map, tst->vars[i]);
1152 insert_variable_into_map (var_map, tst->indep_var);
1157 npar_method (struct lexer *lexer, struct npar_specs *specs)
1159 if ( lex_match_id (lexer, "EXACT") )
1161 specs->exact = true;
1163 if (lex_match_id (lexer, "TIMER"))
1167 if ( lex_match (lexer, '('))
1169 if ( lex_force_num (lexer) )
1171 specs->timer = lex_number (lexer);
1174 lex_force_match (lexer, ')');