1 /* PSPP - a program for statistical analysis. -*-c-*-
2 Copyright (C) 2006, 2008, 2009, 2010, 2011 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"
24 #include "data/case.h"
25 #include "data/casegrouper.h"
26 #include "data/casereader.h"
27 #include "data/dataset.h"
28 #include "data/dictionary.h"
29 #include "data/settings.h"
30 #include "data/variable.h"
31 #include "language/command.h"
32 #include "language/lexer/lexer.h"
33 #include "language/lexer/value-parser.h"
34 #include "language/lexer/variable-parser.h"
35 #include "language/stats/binomial.h"
36 #include "language/stats/chisquare.h"
37 #include "language/stats/cochran.h"
38 #include "language/stats/friedman.h"
39 #include "language/stats/kruskal-wallis.h"
40 #include "language/stats/mann-whitney.h"
41 #include "language/stats/npar-summary.h"
42 #include "language/stats/runs.h"
43 #include "language/stats/sign.h"
44 #include "language/stats/wilcoxon.h"
45 #include "libpspp/array.h"
46 #include "libpspp/assertion.h"
47 #include "libpspp/cast.h"
48 #include "libpspp/hash-functions.h"
49 #include "libpspp/hmapx.h"
50 #include "libpspp/message.h"
51 #include "libpspp/pool.h"
52 #include "libpspp/str.h"
53 #include "libpspp/taint.h"
54 #include "math/moments.h"
56 #include "gl/xalloc.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_id (lexer, "COCHRAN"))
164 switch (npar_cochran (lexer, ds, nps))
171 lex_error (lexer, NULL);
177 else if (lex_match_id (lexer, "FRIEDMAN"))
180 switch (npar_friedman (lexer, ds, nps))
187 lex_error (lexer, NULL);
193 else if (lex_match_id (lexer, "KENDALL"))
196 switch (npar_kendall (lexer, ds, nps))
203 lex_error (lexer, NULL);
209 else if (lex_match_id (lexer, "RUNS"))
212 switch (npar_runs (lexer, ds, nps))
219 lex_error (lexer, NULL);
225 else if (lex_match_id (lexer, "CHISQUARE"))
227 lex_match (lexer, T_EQUALS);
229 switch (npar_chisquare (lexer, ds, nps))
236 lex_error (lexer, NULL);
244 else if (lex_match_id (lexer, "BINOMIAL"))
246 lex_match (lexer, T_EQUALS);
248 switch (npar_binomial (lexer, ds, nps))
255 lex_error (lexer, NULL);
261 else if (lex_match_phrase (lexer, "K-W") ||
262 lex_match_phrase (lexer, "KRUSKAL-WALLIS"))
264 lex_match (lexer, T_EQUALS);
265 npt->kruskal_wallis++;
266 switch (npar_kruskal_wallis (lexer, ds, nps))
273 lex_error (lexer, NULL);
279 else if (lex_match_phrase (lexer, "M-W") ||
280 lex_match_phrase (lexer, "MANN-WHITNEY"))
282 lex_match (lexer, T_EQUALS);
284 switch (npar_mann_whitney (lexer, ds, nps))
291 lex_error (lexer, NULL);
297 else if (lex_match_id (lexer, "WILCOXON"))
299 lex_match (lexer, T_EQUALS);
301 switch (npar_wilcoxon (lexer, ds, nps))
308 lex_error (lexer, NULL);
314 else if (lex_match_id (lexer, "SIGN"))
316 lex_match (lexer, T_EQUALS);
318 switch (npar_sign (lexer, ds, nps))
325 lex_error (lexer, NULL);
331 else if (lex_match_id (lexer, "MISSING"))
333 lex_match (lexer, T_EQUALS);
335 if (npt->missing > 1)
337 msg (SE, _("The %s subcommand may be given only once."), "MISSING");
340 while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
342 if (lex_match_id (lexer, "ANALYSIS"))
343 npt->miss = MISS_ANALYSIS;
344 else if (lex_match_id (lexer, "LISTWISE"))
345 npt->miss = MISS_LISTWISE;
346 else if (lex_match_id (lexer, "INCLUDE"))
347 nps->filter = MV_SYSTEM;
348 else if (lex_match_id (lexer, "EXCLUDE"))
349 nps->filter = MV_ANY;
352 lex_error (lexer, NULL);
355 lex_match (lexer, T_COMMA);
358 else if (lex_match_id (lexer, "METHOD"))
360 lex_match (lexer, T_EQUALS);
364 msg (SE, _("The %s subcommand may be given only once."), "METHOD");
367 switch (npar_method (lexer, nps))
374 lex_error (lexer, NULL);
380 else if (lex_match_id (lexer, "STATISTICS"))
382 lex_match (lexer, T_EQUALS);
384 while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
386 if (lex_match_id (lexer, "DESCRIPTIVES"))
387 npt->a_statistics[NPAR_ST_DESCRIPTIVES] = 1;
388 else if (lex_match_id (lexer, "QUARTILES"))
389 npt->a_statistics[NPAR_ST_QUARTILES] = 1;
390 else if (lex_match (lexer, T_ALL))
391 npt->a_statistics[NPAR_ST_ALL] = 1;
394 lex_error (lexer, NULL);
397 lex_match (lexer, T_COMMA);
400 else if ( settings_get_syntax () != COMPATIBLE && lex_match_id (lexer, "ALGORITHM"))
402 lex_match (lexer, T_EQUALS);
403 if (lex_match_id (lexer, "COMPATIBLE"))
404 settings_set_cmd_algorithm (COMPATIBLE);
405 else if (lex_match_id (lexer, "ENHANCED"))
406 settings_set_cmd_algorithm (ENHANCED);
408 if (!lex_match (lexer, T_SLASH))
412 if (lex_token (lexer) != T_ENDCMD)
414 lex_error (lexer, _("expecting end of command"));
425 static void one_sample_insert_variables (const struct npar_test *test,
428 static void two_sample_insert_variables (const struct npar_test *test,
431 static void n_sample_insert_variables (const struct npar_test *test,
435 npar_execute (struct casereader *input,
436 const struct npar_specs *specs,
437 const struct dataset *ds)
440 struct descriptives *summary_descriptives = NULL;
442 for ( t = 0 ; t < specs->n_tests; ++t )
444 const struct npar_test *test = specs->test[t];
445 if ( NULL == test->execute )
447 msg (SW, _("NPAR subcommand not currently implemented."));
450 test->execute (ds, casereader_clone (input), specs->filter, test, specs->exact, specs->timer);
453 if ( specs->descriptives )
455 summary_descriptives = xnmalloc (sizeof (*summary_descriptives),
458 npar_summary_calc_descriptives (summary_descriptives,
459 casereader_clone (input),
461 specs->vv, specs->n_vars,
465 if ( (specs->descriptives || specs->quartiles)
466 && !taint_has_tainted_successor (casereader_get_taint (input)) )
467 do_summary_box (summary_descriptives, specs->vv, specs->n_vars );
469 free (summary_descriptives);
470 casereader_destroy (input);
474 cmd_npar_tests (struct lexer *lexer, struct dataset *ds)
476 struct cmd_npar_tests cmd;
479 struct npar_specs npar_specs = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
480 struct casegrouper *grouper;
481 struct casereader *input, *group;
482 struct hmapx var_map = HMAPX_INITIALIZER (var_map);
485 npar_specs.pool = pool_create ();
486 npar_specs.filter = MV_ANY;
487 npar_specs.n_vars = -1;
488 npar_specs.vv = NULL;
490 if ( ! parse_npar_tests (lexer, ds, &cmd, &npar_specs) )
492 pool_destroy (npar_specs.pool);
496 for (i = 0; i < npar_specs.n_tests; ++i )
498 const struct npar_test *test = npar_specs.test[i];
499 test->insert_variables (test, &var_map);
503 struct hmapx_node *node;
504 struct variable *var;
505 npar_specs.n_vars = 0;
507 HMAPX_FOR_EACH (var, node, &var_map)
509 npar_specs.n_vars ++;
510 npar_specs.vv = pool_nrealloc (npar_specs.pool, npar_specs.vv, npar_specs.n_vars, sizeof (*npar_specs.vv));
511 npar_specs.vv[npar_specs.n_vars - 1] = var;
515 sort (npar_specs.vv, npar_specs.n_vars, sizeof (*npar_specs.vv),
516 compare_var_ptrs_by_name, NULL);
518 if ( cmd.statistics )
522 for ( i = 0 ; i < NPAR_ST_count; ++i )
524 if ( cmd.a_statistics[i] )
528 case NPAR_ST_DESCRIPTIVES:
529 npar_specs.descriptives = true;
531 case NPAR_ST_QUARTILES:
532 npar_specs.quartiles = true;
535 npar_specs.quartiles = true;
536 npar_specs.descriptives = true;
545 input = proc_open (ds);
546 if ( cmd.miss == MISS_LISTWISE )
548 input = casereader_create_filter_missing (input,
556 grouper = casegrouper_create_splits (input, dataset_dict (ds));
557 while (casegrouper_get_next_group (grouper, &group))
558 npar_execute (group, &npar_specs, ds);
559 ok = casegrouper_destroy (grouper);
560 ok = proc_commit (ds) && ok;
562 pool_destroy (npar_specs.pool);
563 hmapx_destroy (&var_map);
565 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
569 npar_runs (struct lexer *lexer, struct dataset *ds,
570 struct npar_specs *specs)
572 struct runs_test *rt = pool_alloc (specs->pool, sizeof (*rt));
573 struct one_sample_test *tp = &rt->parent;
574 struct npar_test *nt = &tp->parent;
576 nt->execute = runs_execute;
577 nt->insert_variables = one_sample_insert_variables;
579 if ( lex_force_match (lexer, T_LPAREN) )
581 if ( lex_match_id (lexer, "MEAN"))
583 rt->cp_mode = CP_MEAN;
585 else if (lex_match_id (lexer, "MEDIAN"))
587 rt->cp_mode = CP_MEDIAN;
589 else if (lex_match_id (lexer, "MODE"))
591 rt->cp_mode = CP_MODE;
593 else if (lex_is_number (lexer))
595 rt->cutpoint = lex_number (lexer);
596 rt->cp_mode = CP_CUSTOM;
601 lex_error (lexer, _("Expecting MEAN, MEDIAN, MODE or number"));
605 lex_force_match (lexer, T_RPAREN);
606 lex_force_match (lexer, T_EQUALS);
607 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
608 &tp->vars, &tp->n_vars,
609 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
616 specs->test = pool_realloc (specs->pool,
618 sizeof (*specs->test) * specs->n_tests);
620 specs->test[specs->n_tests - 1] = nt;
626 npar_friedman (struct lexer *lexer, struct dataset *ds,
627 struct npar_specs *specs)
629 struct friedman_test *ft = pool_alloc (specs->pool, sizeof (*ft));
630 struct one_sample_test *ost = &ft->parent;
631 struct npar_test *nt = &ost->parent;
633 ft->kendalls_w = false;
634 nt->execute = friedman_execute;
635 nt->insert_variables = one_sample_insert_variables;
637 lex_match (lexer, T_EQUALS);
639 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
640 &ost->vars, &ost->n_vars,
641 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
647 specs->test = pool_realloc (specs->pool,
649 sizeof (*specs->test) * specs->n_tests);
651 specs->test[specs->n_tests - 1] = nt;
657 npar_kendall (struct lexer *lexer, struct dataset *ds,
658 struct npar_specs *specs)
660 struct friedman_test *kt = pool_alloc (specs->pool, sizeof (*kt));
661 struct one_sample_test *ost = &kt->parent;
662 struct npar_test *nt = &ost->parent;
664 kt->kendalls_w = true;
665 nt->execute = friedman_execute;
666 nt->insert_variables = one_sample_insert_variables;
668 lex_match (lexer, T_EQUALS);
670 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
671 &ost->vars, &ost->n_vars,
672 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
678 specs->test = pool_realloc (specs->pool,
680 sizeof (*specs->test) * specs->n_tests);
682 specs->test[specs->n_tests - 1] = nt;
689 npar_cochran (struct lexer *lexer, struct dataset *ds,
690 struct npar_specs *specs)
692 struct one_sample_test *ft = pool_alloc (specs->pool, sizeof (*ft));
693 struct npar_test *nt = &ft->parent;
695 nt->execute = cochran_execute;
696 nt->insert_variables = one_sample_insert_variables;
698 lex_match (lexer, T_EQUALS);
700 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
701 &ft->vars, &ft->n_vars,
702 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
708 specs->test = pool_realloc (specs->pool,
710 sizeof (*specs->test) * specs->n_tests);
712 specs->test[specs->n_tests - 1] = nt;
719 npar_chisquare (struct lexer *lexer, struct dataset *ds,
720 struct npar_specs *specs)
722 struct chisquare_test *cstp = pool_alloc (specs->pool, sizeof (*cstp));
723 struct one_sample_test *tp = &cstp->parent;
724 struct npar_test *nt = &tp->parent;
727 nt->execute = chisquare_execute;
728 nt->insert_variables = one_sample_insert_variables;
730 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
731 &tp->vars, &tp->n_vars,
732 PV_NO_SCRATCH | PV_NO_DUPLICATE))
737 cstp->ranged = false;
739 if ( lex_match (lexer, T_LPAREN))
742 if ( ! lex_force_num (lexer)) return 0;
743 cstp->lo = lex_integer (lexer);
745 lex_force_match (lexer, T_COMMA);
746 if (! lex_force_num (lexer) ) return 0;
747 cstp->hi = lex_integer (lexer);
748 if ( cstp->lo >= cstp->hi )
751 _("The specified value of HI (%d) is "
752 "lower than the specified value of LO (%d)"),
757 if (! lex_force_match (lexer, T_RPAREN)) return 0;
760 cstp->n_expected = 0;
761 cstp->expected = NULL;
762 if (lex_match_phrase (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, T_ASTERISK))
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 if ( cstp->ranged && cstp->n_expected > 0 &&
798 cstp->n_expected != cstp->hi - cstp->lo + 1 )
801 _("%d expected values were given, but the specified "
802 "range (%d-%d) requires exactly %d values."),
803 cstp->n_expected, cstp->lo, cstp->hi,
804 cstp->hi - cstp->lo +1);
809 specs->test = pool_realloc (specs->pool,
811 sizeof (*specs->test) * specs->n_tests);
813 specs->test[specs->n_tests - 1] = nt;
820 npar_binomial (struct lexer *lexer, struct dataset *ds,
821 struct npar_specs *specs)
823 struct binomial_test *btp = pool_alloc (specs->pool, sizeof (*btp));
824 struct one_sample_test *tp = &btp->parent;
825 struct npar_test *nt = &tp->parent;
828 nt->execute = binomial_execute;
829 nt->insert_variables = one_sample_insert_variables;
831 btp->category1 = btp->category2 = btp->cutpoint = SYSMIS;
835 if ( lex_match (lexer, T_LPAREN) )
838 if ( lex_force_num (lexer) )
840 btp->p = lex_number (lexer);
842 lex_force_match (lexer, T_RPAREN);
850 if (equals || lex_match (lexer, T_EQUALS) )
852 if (parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
853 &tp->vars, &tp->n_vars,
854 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
856 if (lex_match (lexer, T_LPAREN))
858 lex_force_num (lexer);
859 btp->category1 = lex_number (lexer);
861 if ( lex_match (lexer, T_COMMA))
863 if ( ! lex_force_num (lexer) ) return 2;
864 btp->category2 = lex_number (lexer);
869 btp->cutpoint = btp->category1;
872 lex_force_match (lexer, T_RPAREN);
881 specs->test = pool_realloc (specs->pool,
883 sizeof (*specs->test) * specs->n_tests);
885 specs->test[specs->n_tests - 1] = nt;
892 parse_two_sample_related_test (struct lexer *lexer,
893 const struct dictionary *dict,
894 struct two_sample_test *test_parameters,
900 parse_two_sample_related_test (struct lexer *lexer,
901 const struct dictionary *dict,
902 struct two_sample_test *test_parameters,
909 const struct variable **vlist1;
912 const struct variable **vlist2;
915 test_parameters->parent.insert_variables = two_sample_insert_variables;
917 if (!parse_variables_const_pool (lexer, pool,
920 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
923 if ( lex_match (lexer, T_WITH))
926 if ( !parse_variables_const_pool (lexer, pool, dict,
928 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
931 paired = (lex_match (lexer, T_LPAREN) &&
932 lex_match_id (lexer, "PAIRED") && lex_match (lexer, T_RPAREN));
940 if ( n_vlist1 != n_vlist2)
941 msg (SE, _("PAIRED was specified but the number of variables "
942 "preceding WITH (%zu) did not match the number "
943 "following (%zu)."), n_vlist1, n_vlist2);
945 test_parameters->n_pairs = n_vlist1 ;
949 test_parameters->n_pairs = n_vlist1 * n_vlist2;
954 test_parameters->n_pairs = (n_vlist1 * (n_vlist1 - 1)) / 2 ;
957 test_parameters->pairs =
958 pool_alloc (pool, sizeof ( variable_pair) * test_parameters->n_pairs);
965 assert (n_vlist1 == n_vlist2);
966 for ( i = 0 ; i < n_vlist1; ++i )
968 test_parameters->pairs[n][1] = vlist1[i];
969 test_parameters->pairs[n][0] = vlist2[i];
976 for ( i = 0 ; i < n_vlist1; ++i )
978 for ( j = 0 ; j < n_vlist2; ++j )
980 test_parameters->pairs[n][1] = vlist1[i];
981 test_parameters->pairs[n][0] = vlist2[j];
990 for ( i = 0 ; i < n_vlist1 - 1; ++i )
992 for ( j = i + 1 ; j < n_vlist1; ++j )
994 assert ( n < test_parameters->n_pairs);
995 test_parameters->pairs[n][1] = vlist1[i];
996 test_parameters->pairs[n][0] = vlist1[j];
1002 assert ( n == test_parameters->n_pairs);
1009 parse_n_sample_related_test (struct lexer *lexer,
1010 const struct dictionary *dict,
1011 struct n_sample_test *nst,
1015 if (!parse_variables_const_pool (lexer, pool,
1017 &nst->vars, &nst->n_vars,
1018 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
1021 if ( ! lex_force_match (lexer, T_BY))
1024 nst->indep_var = parse_variable_const (lexer, dict);
1026 if ( ! lex_force_match (lexer, T_LPAREN))
1029 value_init (&nst->val1, var_get_width (nst->indep_var));
1030 if ( ! parse_value (lexer, &nst->val1, nst->indep_var))
1032 value_destroy (&nst->val1, var_get_width (nst->indep_var));
1036 lex_match (lexer, T_COMMA);
1038 value_init (&nst->val2, var_get_width (nst->indep_var));
1039 if ( ! parse_value (lexer, &nst->val2, nst->indep_var))
1041 value_destroy (&nst->val2, var_get_width (nst->indep_var));
1045 if ( ! lex_force_match (lexer, T_RPAREN))
1052 npar_wilcoxon (struct lexer *lexer,
1054 struct npar_specs *specs )
1058 struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1059 struct npar_test *nt = &tp->parent;
1060 nt->execute = wilcoxon_execute;
1062 if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
1067 specs->test = pool_realloc (specs->pool,
1069 sizeof (*specs->test) * specs->n_tests);
1070 specs->test[specs->n_tests - 1] = nt;
1077 npar_mann_whitney (struct lexer *lexer,
1079 struct npar_specs *specs )
1081 struct n_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1082 struct npar_test *nt = &tp->parent;
1084 nt->insert_variables = n_sample_insert_variables;
1085 nt->execute = mann_whitney_execute;
1087 if (!parse_n_sample_related_test (lexer, dataset_dict (ds),
1092 specs->test = pool_realloc (specs->pool,
1094 sizeof (*specs->test) * specs->n_tests);
1095 specs->test[specs->n_tests - 1] = nt;
1102 npar_sign (struct lexer *lexer, struct dataset *ds,
1103 struct npar_specs *specs)
1105 struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1106 struct npar_test *nt = &tp->parent;
1108 nt->execute = sign_execute;
1110 if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
1115 specs->test = pool_realloc (specs->pool,
1117 sizeof (*specs->test) * specs->n_tests);
1118 specs->test[specs->n_tests - 1] = nt;
1124 npar_kruskal_wallis (struct lexer *lexer, struct dataset *ds,
1125 struct npar_specs *specs)
1127 struct n_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1128 struct npar_test *nt = &tp->parent;
1130 nt->insert_variables = n_sample_insert_variables;
1132 nt->execute = kruskal_wallis_execute;
1134 if (!parse_n_sample_related_test (lexer, dataset_dict (ds),
1139 specs->test = pool_realloc (specs->pool,
1141 sizeof (*specs->test) * specs->n_tests);
1142 specs->test[specs->n_tests - 1] = nt;
1148 insert_variable_into_map (struct hmapx *var_map, const struct variable *var)
1150 size_t hash = hash_pointer (var, 0);
1151 struct hmapx_node *node;
1152 const struct variable *v = NULL;
1154 HMAPX_FOR_EACH_WITH_HASH (v, node, hash, var_map)
1160 hmapx_insert (var_map, CONST_CAST (struct variable *, var), hash);
1163 /* Insert the variables for TEST into VAR_MAP */
1165 one_sample_insert_variables (const struct npar_test *test,
1166 struct hmapx *var_map)
1169 const struct one_sample_test *ost = UP_CAST (test, const struct one_sample_test, parent);
1171 for ( i = 0 ; i < ost->n_vars ; ++i )
1172 insert_variable_into_map (var_map, ost->vars[i]);
1177 two_sample_insert_variables (const struct npar_test *test,
1178 struct hmapx *var_map)
1181 const struct two_sample_test *tst = UP_CAST (test, const struct two_sample_test, parent);
1183 for ( i = 0 ; i < tst->n_pairs ; ++i )
1185 variable_pair *pair = &tst->pairs[i];
1187 insert_variable_into_map (var_map, (*pair)[0]);
1188 insert_variable_into_map (var_map, (*pair)[1]);
1193 n_sample_insert_variables (const struct npar_test *test,
1194 struct hmapx *var_map)
1197 const struct n_sample_test *tst = UP_CAST (test, const struct n_sample_test, parent);
1199 for ( i = 0 ; i < tst->n_vars ; ++i )
1200 insert_variable_into_map (var_map, tst->vars[i]);
1202 insert_variable_into_map (var_map, tst->indep_var);
1207 npar_method (struct lexer *lexer, struct npar_specs *specs)
1209 if ( lex_match_id (lexer, "EXACT") )
1211 specs->exact = true;
1213 if (lex_match_id (lexer, "TIMER"))
1217 if ( lex_match (lexer, T_LPAREN))
1219 if ( lex_force_num (lexer) )
1221 specs->timer = lex_number (lexer);
1224 lex_force_match (lexer, T_RPAREN);