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. */
96 /* How missing values should be treated */
99 /* Which statistics have been requested */
100 int a_statistics[NPAR_ST_count];
107 struct npar_test **test;
110 const struct variable **vv; /* Compendium of all variables
111 (those mentioned on ANY subcommand */
112 int n_vars; /* Number of variables in vv */
114 enum mv_class filter; /* Missing values to filter. */
116 bool descriptives; /* Descriptive statistics should be calculated */
117 bool quartiles; /* Quartiles should be calculated */
119 bool exact; /* Whether exact calculations have been requested */
120 double timer; /* Maximum time (in minutes) to wait for exact calculations */
124 /* Prototype for custom subcommands of NPAR TESTS. */
125 static int npar_chisquare (struct lexer *, struct dataset *, struct npar_specs *);
126 static int npar_binomial (struct lexer *, struct dataset *, struct npar_specs *);
127 static int npar_runs (struct lexer *, struct dataset *, struct npar_specs *);
128 static int npar_friedman (struct lexer *, struct dataset *, struct npar_specs *);
129 static int npar_kendall (struct lexer *, struct dataset *, struct npar_specs *);
130 static int npar_cochran (struct lexer *, struct dataset *, struct npar_specs *);
131 static int npar_wilcoxon (struct lexer *, struct dataset *, struct npar_specs *);
132 static int npar_sign (struct lexer *, struct dataset *, struct npar_specs *);
133 static int npar_kruskal_wallis (struct lexer *, struct dataset *, struct npar_specs *);
134 static int npar_mann_whitney (struct lexer *, struct dataset *, struct npar_specs *);
135 static int npar_method (struct lexer *, struct npar_specs *);
137 /* Command parsing functions. */
138 static int parse_npar_tests (struct lexer *lexer, struct dataset *ds, struct cmd_npar_tests *p,
139 struct npar_specs *npar_specs );
142 parse_npar_tests (struct lexer *lexer, struct dataset *ds, struct cmd_npar_tests *npt,
143 struct npar_specs *nps)
149 npt->kruskal_wallis = 0;
150 npt->mann_whitney = 0;
155 npt->miss = MISS_ANALYSIS;
158 memset (npt->a_statistics, 0, sizeof npt->a_statistics);
161 if (lex_match_hyphenated_word (lexer, "COCHRAN"))
164 switch (npar_cochran (lexer, ds, nps))
171 lex_error (lexer, NULL);
177 else if (lex_match_hyphenated_word (lexer, "FRIEDMAN"))
180 switch (npar_friedman (lexer, ds, nps))
187 lex_error (lexer, NULL);
193 else if (lex_match_hyphenated_word (lexer, "KENDALL"))
196 switch (npar_kendall (lexer, ds, nps))
203 lex_error (lexer, NULL);
209 else if (lex_match_hyphenated_word (lexer, "RUNS"))
212 switch (npar_runs (lexer, ds, nps))
219 lex_error (lexer, NULL);
225 else if (lex_match_hyphenated_word (lexer, "CHISQUARE"))
227 lex_match (lexer, T_EQUALS);
229 switch (npar_chisquare (lexer, ds, nps))
236 lex_error (lexer, NULL);
242 else if (lex_match_hyphenated_word (lexer, "BINOMIAL"))
244 lex_match (lexer, T_EQUALS);
246 switch (npar_binomial (lexer, ds, nps))
253 lex_error (lexer, NULL);
259 else if (lex_match_hyphenated_word (lexer, "K-W") ||
260 lex_match_hyphenated_word (lexer, "KRUSKAL-WALLIS"))
262 lex_match (lexer, T_EQUALS);
263 npt->kruskal_wallis++;
264 switch (npar_kruskal_wallis (lexer, ds, nps))
271 lex_error (lexer, NULL);
277 else if (lex_match_hyphenated_word (lexer, "M-W") ||
278 lex_match_hyphenated_word (lexer, "MANN-WHITNEY"))
280 lex_match (lexer, '=');
282 switch (npar_mann_whitney (lexer, ds, nps))
289 lex_error (lexer, NULL);
295 else if (lex_match_hyphenated_word (lexer, "WILCOXON"))
297 lex_match (lexer, T_EQUALS);
299 switch (npar_wilcoxon (lexer, ds, nps))
306 lex_error (lexer, NULL);
312 else if (lex_match_hyphenated_word (lexer, "SIGN"))
314 lex_match (lexer, T_EQUALS);
316 switch (npar_sign (lexer, ds, nps))
323 lex_error (lexer, NULL);
329 else if (lex_match_hyphenated_word (lexer, "MISSING"))
331 lex_match (lexer, T_EQUALS);
333 if (npt->missing > 1)
335 msg (SE, _("The %s subcommand may be given only once."), "MISSING");
338 while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
340 if (lex_match_hyphenated_word (lexer, "ANALYSIS"))
341 npt->miss = MISS_ANALYSIS;
342 else if (lex_match_hyphenated_word (lexer, "LISTWISE"))
343 npt->miss = MISS_LISTWISE;
344 else if (lex_match_hyphenated_word (lexer, "INCLUDE"))
345 nps->filter = MV_SYSTEM;
346 else if (lex_match_hyphenated_word (lexer, "EXCLUDE"))
347 nps->filter = MV_ANY;
350 lex_error (lexer, NULL);
353 lex_match (lexer, T_COMMA);
356 else if (lex_match_hyphenated_word (lexer, "METHOD"))
358 lex_match (lexer, T_EQUALS);
362 msg (SE, _("The %s subcommand may be given only once."), "METHOD");
365 switch (npar_method (lexer, nps))
372 lex_error (lexer, NULL);
378 else if (lex_match_hyphenated_word (lexer, "STATISTICS"))
380 lex_match (lexer, T_EQUALS);
382 while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
384 if (lex_match_hyphenated_word (lexer, "DESCRIPTIVES"))
385 npt->a_statistics[NPAR_ST_DESCRIPTIVES] = 1;
386 else if (lex_match_hyphenated_word (lexer, "QUARTILES"))
387 npt->a_statistics[NPAR_ST_QUARTILES] = 1;
388 else if (lex_match (lexer, T_ALL))
389 npt->a_statistics[NPAR_ST_ALL] = 1;
392 lex_error (lexer, NULL);
395 lex_match (lexer, T_COMMA);
398 else if ( settings_get_syntax () != COMPATIBLE && lex_match_id (lexer, "ALGORITHM"))
400 lex_match (lexer, T_EQUALS);
401 if (lex_match_id (lexer, "COMPATIBLE"))
402 settings_set_cmd_algorithm (COMPATIBLE);
403 else if (lex_match_id (lexer, "ENHANCED"))
404 settings_set_cmd_algorithm (ENHANCED);
406 if (!lex_match (lexer, T_SLASH))
410 if (lex_token (lexer) != T_ENDCMD)
412 lex_error (lexer, _("expecting end of command"));
423 static void one_sample_insert_variables (const struct npar_test *test,
426 static void two_sample_insert_variables (const struct npar_test *test,
429 static void n_sample_insert_variables (const struct npar_test *test,
433 npar_execute (struct casereader *input,
434 const struct npar_specs *specs,
435 const struct dataset *ds)
438 struct descriptives *summary_descriptives = NULL;
440 for ( t = 0 ; t < specs->n_tests; ++t )
442 const struct npar_test *test = specs->test[t];
443 if ( NULL == test->execute )
445 msg (SW, _("NPAR subcommand not currently implemented."));
448 test->execute (ds, casereader_clone (input), specs->filter, test, specs->exact, specs->timer);
451 if ( specs->descriptives )
453 summary_descriptives = xnmalloc (sizeof (*summary_descriptives),
456 npar_summary_calc_descriptives (summary_descriptives,
457 casereader_clone (input),
459 specs->vv, specs->n_vars,
463 if ( (specs->descriptives || specs->quartiles)
464 && !taint_has_tainted_successor (casereader_get_taint (input)) )
465 do_summary_box (summary_descriptives, specs->vv, specs->n_vars );
467 free (summary_descriptives);
468 casereader_destroy (input);
472 cmd_npar_tests (struct lexer *lexer, struct dataset *ds)
474 struct cmd_npar_tests cmd;
477 struct npar_specs npar_specs = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
478 struct casegrouper *grouper;
479 struct casereader *input, *group;
480 struct hmapx var_map = HMAPX_INITIALIZER (var_map);
483 npar_specs.pool = pool_create ();
484 npar_specs.filter = MV_ANY;
485 npar_specs.n_vars = -1;
486 npar_specs.vv = NULL;
488 if ( ! parse_npar_tests (lexer, ds, &cmd, &npar_specs) )
490 pool_destroy (npar_specs.pool);
494 for (i = 0; i < npar_specs.n_tests; ++i )
496 const struct npar_test *test = npar_specs.test[i];
497 test->insert_variables (test, &var_map);
501 struct hmapx_node *node;
502 struct variable *var;
503 npar_specs.n_vars = 0;
505 HMAPX_FOR_EACH (var, node, &var_map)
507 npar_specs.n_vars ++;
508 npar_specs.vv = pool_nrealloc (npar_specs.pool, npar_specs.vv, npar_specs.n_vars, sizeof (*npar_specs.vv));
509 npar_specs.vv[npar_specs.n_vars - 1] = var;
513 sort (npar_specs.vv, npar_specs.n_vars, sizeof (*npar_specs.vv),
514 compare_var_ptrs_by_name, NULL);
516 if ( cmd.statistics )
520 for ( i = 0 ; i < NPAR_ST_count; ++i )
522 if ( cmd.a_statistics[i] )
526 case NPAR_ST_DESCRIPTIVES:
527 npar_specs.descriptives = true;
529 case NPAR_ST_QUARTILES:
530 npar_specs.quartiles = true;
533 npar_specs.quartiles = true;
534 npar_specs.descriptives = true;
543 input = proc_open (ds);
544 if ( cmd.miss == MISS_LISTWISE )
546 input = casereader_create_filter_missing (input,
554 grouper = casegrouper_create_splits (input, dataset_dict (ds));
555 while (casegrouper_get_next_group (grouper, &group))
556 npar_execute (group, &npar_specs, ds);
557 ok = casegrouper_destroy (grouper);
558 ok = proc_commit (ds) && ok;
560 pool_destroy (npar_specs.pool);
561 hmapx_destroy (&var_map);
563 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
567 npar_runs (struct lexer *lexer, struct dataset *ds,
568 struct npar_specs *specs)
570 struct runs_test *rt = pool_alloc (specs->pool, sizeof (*rt));
571 struct one_sample_test *tp = &rt->parent;
572 struct npar_test *nt = &tp->parent;
574 nt->execute = runs_execute;
575 nt->insert_variables = one_sample_insert_variables;
577 if ( lex_force_match (lexer, '(') )
579 if ( lex_match_id (lexer, "MEAN"))
581 rt->cp_mode = CP_MEAN;
583 else if (lex_match_id (lexer, "MEDIAN"))
585 rt->cp_mode = CP_MEDIAN;
587 else if (lex_match_id (lexer, "MODE"))
589 rt->cp_mode = CP_MODE;
591 else if (lex_is_number (lexer))
593 rt->cutpoint = lex_number (lexer);
594 rt->cp_mode = CP_CUSTOM;
599 lex_error (lexer, _("Expecting MEAN, MEDIAN, MODE or number"));
603 lex_force_match (lexer, ')');
604 lex_force_match (lexer, '=');
605 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
606 &tp->vars, &tp->n_vars,
607 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
614 specs->test = pool_realloc (specs->pool,
616 sizeof (*specs->test) * specs->n_tests);
618 specs->test[specs->n_tests - 1] = nt;
624 npar_friedman (struct lexer *lexer, struct dataset *ds,
625 struct npar_specs *specs)
627 struct friedman_test *ft = pool_alloc (specs->pool, sizeof (*ft));
628 struct one_sample_test *ost = &ft->parent;
629 struct npar_test *nt = &ost->parent;
631 ft->kendalls_w = false;
632 nt->execute = friedman_execute;
633 nt->insert_variables = one_sample_insert_variables;
635 lex_match (lexer, '=');
637 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
638 &ost->vars, &ost->n_vars,
639 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
645 specs->test = pool_realloc (specs->pool,
647 sizeof (*specs->test) * specs->n_tests);
649 specs->test[specs->n_tests - 1] = nt;
655 npar_kendall (struct lexer *lexer, struct dataset *ds,
656 struct npar_specs *specs)
658 struct friedman_test *kt = pool_alloc (specs->pool, sizeof (*kt));
659 struct one_sample_test *ost = &kt->parent;
660 struct npar_test *nt = &ost->parent;
662 kt->kendalls_w = true;
663 nt->execute = friedman_execute;
664 nt->insert_variables = one_sample_insert_variables;
666 lex_match (lexer, '=');
668 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
669 &ost->vars, &ost->n_vars,
670 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
676 specs->test = pool_realloc (specs->pool,
678 sizeof (*specs->test) * specs->n_tests);
680 specs->test[specs->n_tests - 1] = nt;
687 npar_cochran (struct lexer *lexer, struct dataset *ds,
688 struct npar_specs *specs)
690 struct one_sample_test *ft = pool_alloc (specs->pool, sizeof (*ft));
691 struct npar_test *nt = &ft->parent;
693 nt->execute = cochran_execute;
694 nt->insert_variables = one_sample_insert_variables;
696 lex_match (lexer, '=');
698 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
699 &ft->vars, &ft->n_vars,
700 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
706 specs->test = pool_realloc (specs->pool,
708 sizeof (*specs->test) * specs->n_tests);
710 specs->test[specs->n_tests - 1] = nt;
717 npar_chisquare (struct lexer *lexer, struct dataset *ds,
718 struct npar_specs *specs)
720 struct chisquare_test *cstp = pool_alloc (specs->pool, sizeof (*cstp));
721 struct one_sample_test *tp = &cstp->parent;
722 struct npar_test *nt = &tp->parent;
725 nt->execute = chisquare_execute;
726 nt->insert_variables = one_sample_insert_variables;
728 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
729 &tp->vars, &tp->n_vars,
730 PV_NO_SCRATCH | PV_NO_DUPLICATE))
735 cstp->ranged = false;
737 if ( lex_match (lexer, T_LPAREN))
740 if ( ! lex_force_num (lexer)) return 0;
741 cstp->lo = lex_integer (lexer);
743 lex_force_match (lexer, T_COMMA);
744 if (! lex_force_num (lexer) ) return 0;
745 cstp->hi = lex_integer (lexer);
746 if ( cstp->lo >= cstp->hi )
749 _("The specified value of HI (%d) is "
750 "lower than the specified value of LO (%d)"),
755 if (! lex_force_match (lexer, T_RPAREN)) return 0;
758 cstp->n_expected = 0;
759 cstp->expected = NULL;
760 if ( lex_match (lexer, T_SLASH) )
762 if ( lex_match_id (lexer, "EXPECTED") )
764 lex_force_match (lexer, T_EQUALS);
765 if ( ! lex_match_id (lexer, "EQUAL") )
769 while ( lex_is_number (lexer) )
773 f = lex_number (lexer);
775 if ( lex_match (lexer, '*'))
778 f = lex_number (lexer);
781 lex_match (lexer, T_COMMA);
783 cstp->n_expected += n;
784 cstp->expected = pool_realloc (specs->pool,
788 for ( i = cstp->n_expected - n ;
789 i < cstp->n_expected;
791 cstp->expected[i] = f;
797 lex_put_back (lexer, T_SLASH);
800 if ( cstp->ranged && cstp->n_expected > 0 &&
801 cstp->n_expected != cstp->hi - cstp->lo + 1 )
804 _("%d expected values were given, but the specified "
805 "range (%d-%d) requires exactly %d values."),
806 cstp->n_expected, cstp->lo, cstp->hi,
807 cstp->hi - cstp->lo +1);
812 specs->test = pool_realloc (specs->pool,
814 sizeof (*specs->test) * specs->n_tests);
816 specs->test[specs->n_tests - 1] = nt;
823 npar_binomial (struct lexer *lexer, struct dataset *ds,
824 struct npar_specs *specs)
826 struct binomial_test *btp = pool_alloc (specs->pool, sizeof (*btp));
827 struct one_sample_test *tp = &btp->parent;
828 struct npar_test *nt = &tp->parent;
830 nt->execute = binomial_execute;
831 nt->insert_variables = one_sample_insert_variables;
833 btp->category1 = btp->category2 = btp->cutpoint = SYSMIS;
837 if ( lex_match (lexer, T_LPAREN) )
839 if ( lex_force_num (lexer) )
841 btp->p = lex_number (lexer);
843 lex_force_match (lexer, T_RPAREN);
849 /* Kludge: q2c swallows the '=' so put it back here */
850 lex_put_back (lexer, T_EQUALS);
852 if (lex_match (lexer, T_EQUALS) )
854 if (parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
855 &tp->vars, &tp->n_vars,
856 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
858 if (lex_match (lexer, T_LPAREN))
860 lex_force_num (lexer);
861 btp->category1 = lex_number (lexer);
863 if ( lex_match (lexer, T_COMMA))
865 if ( ! lex_force_num (lexer) ) return 2;
866 btp->category2 = lex_number (lexer);
871 btp->cutpoint = btp->category1;
874 lex_force_match (lexer, T_RPAREN);
883 specs->test = pool_realloc (specs->pool,
885 sizeof (*specs->test) * specs->n_tests);
887 specs->test[specs->n_tests - 1] = nt;
894 parse_two_sample_related_test (struct lexer *lexer,
895 const struct dictionary *dict,
896 struct two_sample_test *test_parameters,
902 parse_two_sample_related_test (struct lexer *lexer,
903 const struct dictionary *dict,
904 struct two_sample_test *test_parameters,
911 const struct variable **vlist1;
914 const struct variable **vlist2;
917 test_parameters->parent.insert_variables = two_sample_insert_variables;
919 if (!parse_variables_const_pool (lexer, pool,
922 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
925 if ( lex_match (lexer, T_WITH))
928 if ( !parse_variables_const_pool (lexer, pool, dict,
930 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
933 paired = (lex_match (lexer, T_LPAREN) &&
934 lex_match_id (lexer, "PAIRED") && lex_match (lexer, T_RPAREN));
942 if ( n_vlist1 != n_vlist2)
943 msg (SE, _("PAIRED was specified but the number of variables "
944 "preceding WITH (%zu) did not match the number "
945 "following (%zu)."), n_vlist1, n_vlist2);
947 test_parameters->n_pairs = n_vlist1 ;
951 test_parameters->n_pairs = n_vlist1 * n_vlist2;
956 test_parameters->n_pairs = (n_vlist1 * (n_vlist1 - 1)) / 2 ;
959 test_parameters->pairs =
960 pool_alloc (pool, sizeof ( variable_pair) * test_parameters->n_pairs);
967 assert (n_vlist1 == n_vlist2);
968 for ( i = 0 ; i < n_vlist1; ++i )
970 test_parameters->pairs[n][1] = vlist1[i];
971 test_parameters->pairs[n][0] = vlist2[i];
978 for ( i = 0 ; i < n_vlist1; ++i )
980 for ( j = 0 ; j < n_vlist2; ++j )
982 test_parameters->pairs[n][1] = vlist1[i];
983 test_parameters->pairs[n][0] = vlist2[j];
992 for ( i = 0 ; i < n_vlist1 - 1; ++i )
994 for ( j = i + 1 ; j < n_vlist1; ++j )
996 assert ( n < test_parameters->n_pairs);
997 test_parameters->pairs[n][1] = vlist1[i];
998 test_parameters->pairs[n][0] = vlist1[j];
1004 assert ( n == test_parameters->n_pairs);
1011 parse_n_sample_related_test (struct lexer *lexer,
1012 const struct dictionary *dict,
1013 struct n_sample_test *nst,
1017 if (!parse_variables_const_pool (lexer, pool,
1019 &nst->vars, &nst->n_vars,
1020 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
1023 if ( ! lex_force_match (lexer, T_BY))
1026 nst->indep_var = parse_variable_const (lexer, dict);
1028 if ( ! lex_force_match (lexer, T_LPAREN))
1031 value_init (&nst->val1, var_get_width (nst->indep_var));
1032 if ( ! parse_value (lexer, &nst->val1, var_get_width (nst->indep_var)))
1034 value_destroy (&nst->val1, var_get_width (nst->indep_var));
1038 lex_match (lexer, T_COMMA);
1040 value_init (&nst->val2, var_get_width (nst->indep_var));
1041 if ( ! parse_value (lexer, &nst->val2, var_get_width (nst->indep_var)))
1043 value_destroy (&nst->val2, var_get_width (nst->indep_var));
1047 if ( ! lex_force_match (lexer, T_RPAREN))
1054 npar_wilcoxon (struct lexer *lexer,
1056 struct npar_specs *specs )
1060 struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1061 struct npar_test *nt = &tp->parent;
1062 nt->execute = wilcoxon_execute;
1064 if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
1069 specs->test = pool_realloc (specs->pool,
1071 sizeof (*specs->test) * specs->n_tests);
1072 specs->test[specs->n_tests - 1] = nt;
1079 npar_mann_whitney (struct lexer *lexer,
1081 struct npar_specs *specs )
1083 struct n_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1084 struct npar_test *nt = &tp->parent;
1086 nt->insert_variables = n_sample_insert_variables;
1087 nt->execute = mann_whitney_execute;
1089 if (!parse_n_sample_related_test (lexer, dataset_dict (ds),
1094 specs->test = pool_realloc (specs->pool,
1096 sizeof (*specs->test) * specs->n_tests);
1097 specs->test[specs->n_tests - 1] = nt;
1104 npar_sign (struct lexer *lexer, struct dataset *ds,
1105 struct npar_specs *specs)
1107 struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1108 struct npar_test *nt = &tp->parent;
1110 nt->execute = sign_execute;
1112 if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
1117 specs->test = pool_realloc (specs->pool,
1119 sizeof (*specs->test) * specs->n_tests);
1120 specs->test[specs->n_tests - 1] = nt;
1126 npar_kruskal_wallis (struct lexer *lexer, struct dataset *ds,
1127 struct npar_specs *specs)
1129 struct n_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1130 struct npar_test *nt = &tp->parent;
1132 nt->insert_variables = n_sample_insert_variables;
1134 nt->execute = kruskal_wallis_execute;
1136 if (!parse_n_sample_related_test (lexer, dataset_dict (ds),
1141 specs->test = pool_realloc (specs->pool,
1143 sizeof (*specs->test) * specs->n_tests);
1144 specs->test[specs->n_tests - 1] = nt;
1150 insert_variable_into_map (struct hmapx *var_map, const struct variable *var)
1152 size_t hash = hash_pointer (var, 0);
1153 struct hmapx_node *node;
1154 const struct variable *v = NULL;
1156 HMAPX_FOR_EACH_WITH_HASH (v, node, hash, var_map)
1162 hmapx_insert (var_map, CONST_CAST (struct variable *, var), hash);
1165 /* Insert the variables for TEST into VAR_MAP */
1167 one_sample_insert_variables (const struct npar_test *test,
1168 struct hmapx *var_map)
1171 const struct one_sample_test *ost = UP_CAST (test, const struct one_sample_test, parent);
1173 for ( i = 0 ; i < ost->n_vars ; ++i )
1174 insert_variable_into_map (var_map, ost->vars[i]);
1179 two_sample_insert_variables (const struct npar_test *test,
1180 struct hmapx *var_map)
1183 const struct two_sample_test *tst = UP_CAST (test, const struct two_sample_test, parent);
1185 for ( i = 0 ; i < tst->n_pairs ; ++i )
1187 variable_pair *pair = &tst->pairs[i];
1189 insert_variable_into_map (var_map, (*pair)[0]);
1190 insert_variable_into_map (var_map, (*pair)[1]);
1195 n_sample_insert_variables (const struct npar_test *test,
1196 struct hmapx *var_map)
1199 const struct n_sample_test *tst = UP_CAST (test, const struct n_sample_test, parent);
1201 for ( i = 0 ; i < tst->n_vars ; ++i )
1202 insert_variable_into_map (var_map, tst->vars[i]);
1204 insert_variable_into_map (var_map, tst->indep_var);
1209 npar_method (struct lexer *lexer, struct npar_specs *specs)
1211 if ( lex_match_id (lexer, "EXACT") )
1213 specs->exact = true;
1215 if (lex_match_id (lexer, "TIMER"))
1219 if ( lex_match (lexer, T_LPAREN))
1221 if ( lex_force_num (lexer) )
1223 specs->timer = lex_number (lexer);
1226 lex_force_match (lexer, T_RPAREN);