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/mcnemar.h"
42 #include "language/stats/npar-summary.h"
43 #include "language/stats/runs.h"
44 #include "language/stats/sign.h"
45 #include "language/stats/wilcoxon.h"
46 #include "libpspp/array.h"
47 #include "libpspp/assertion.h"
48 #include "libpspp/cast.h"
49 #include "libpspp/hash-functions.h"
50 #include "libpspp/hmapx.h"
51 #include "libpspp/message.h"
52 #include "libpspp/pool.h"
53 #include "libpspp/str.h"
54 #include "libpspp/taint.h"
55 #include "math/moments.h"
57 #include "gl/xalloc.h"
60 #define _(msgid) gettext (msgid)
62 /* Settings for subcommand specifiers. */
69 /* Array indices for STATISTICS subcommand. */
72 NPAR_ST_DESCRIPTIVES = 0,
73 NPAR_ST_QUARTILES = 1,
78 /* NPAR TESTS structure. */
81 /* Count variables indicating how many
82 of the subcommands have been given. */
98 /* How missing values should be treated */
101 /* Which statistics have been requested */
102 int a_statistics[NPAR_ST_count];
109 struct npar_test **test;
112 const struct variable **vv; /* Compendium of all variables
113 (those mentioned on ANY subcommand */
114 int n_vars; /* Number of variables in vv */
116 enum mv_class filter; /* Missing values to filter. */
118 bool descriptives; /* Descriptive statistics should be calculated */
119 bool quartiles; /* Quartiles should be calculated */
121 bool exact; /* Whether exact calculations have been requested */
122 double timer; /* Maximum time (in minutes) to wait for exact calculations */
126 /* Prototype for custom subcommands of NPAR TESTS. */
127 static int npar_chisquare (struct lexer *, struct dataset *, struct npar_specs *);
128 static int npar_binomial (struct lexer *, struct dataset *, struct npar_specs *);
129 static int npar_runs (struct lexer *, struct dataset *, struct npar_specs *);
130 static int npar_friedman (struct lexer *, struct dataset *, struct npar_specs *);
131 static int npar_kendall (struct lexer *, struct dataset *, struct npar_specs *);
132 static int npar_cochran (struct lexer *, struct dataset *, struct npar_specs *);
133 static int npar_wilcoxon (struct lexer *, struct dataset *, struct npar_specs *);
134 static int npar_sign (struct lexer *, struct dataset *, struct npar_specs *);
135 static int npar_kruskal_wallis (struct lexer *, struct dataset *, struct npar_specs *);
136 static int npar_mann_whitney (struct lexer *, struct dataset *, struct npar_specs *);
137 static int npar_mcnemar (struct lexer *, struct dataset *, struct npar_specs *);
138 static int npar_method (struct lexer *, struct npar_specs *);
140 /* Command parsing functions. */
141 static int parse_npar_tests (struct lexer *lexer, struct dataset *ds, struct cmd_npar_tests *p,
142 struct npar_specs *npar_specs );
145 parse_npar_tests (struct lexer *lexer, struct dataset *ds, struct cmd_npar_tests *npt,
146 struct npar_specs *nps)
152 npt->kruskal_wallis = 0;
153 npt->mann_whitney = 0;
159 npt->miss = MISS_ANALYSIS;
162 memset (npt->a_statistics, 0, sizeof npt->a_statistics);
165 if (lex_match_id (lexer, "COCHRAN"))
168 switch (npar_cochran (lexer, ds, nps))
175 lex_error (lexer, NULL);
181 else if (lex_match_id (lexer, "FRIEDMAN"))
184 switch (npar_friedman (lexer, ds, nps))
191 lex_error (lexer, NULL);
197 else if (lex_match_id (lexer, "KENDALL"))
200 switch (npar_kendall (lexer, ds, nps))
207 lex_error (lexer, NULL);
213 else if (lex_match_id (lexer, "RUNS"))
216 switch (npar_runs (lexer, ds, nps))
223 lex_error (lexer, NULL);
229 else if (lex_match_id (lexer, "CHISQUARE"))
231 lex_match (lexer, T_EQUALS);
233 switch (npar_chisquare (lexer, ds, nps))
240 lex_error (lexer, NULL);
248 else if (lex_match_id (lexer, "BINOMIAL"))
250 lex_match (lexer, T_EQUALS);
252 switch (npar_binomial (lexer, ds, nps))
259 lex_error (lexer, NULL);
265 else if (lex_match_phrase (lexer, "K-W") ||
266 lex_match_phrase (lexer, "KRUSKAL-WALLIS"))
268 lex_match (lexer, T_EQUALS);
269 npt->kruskal_wallis++;
270 switch (npar_kruskal_wallis (lexer, ds, nps))
277 lex_error (lexer, NULL);
283 else if (lex_match_phrase (lexer, "MCNEMAR"))
285 lex_match (lexer, T_EQUALS);
287 switch (npar_mcnemar (lexer, ds, nps))
294 lex_error (lexer, NULL);
300 else if (lex_match_phrase (lexer, "M-W") ||
301 lex_match_phrase (lexer, "MANN-WHITNEY"))
303 lex_match (lexer, T_EQUALS);
305 switch (npar_mann_whitney (lexer, ds, nps))
312 lex_error (lexer, NULL);
318 else if (lex_match_id (lexer, "WILCOXON"))
320 lex_match (lexer, T_EQUALS);
322 switch (npar_wilcoxon (lexer, ds, nps))
329 lex_error (lexer, NULL);
335 else if (lex_match_id (lexer, "SIGN"))
337 lex_match (lexer, T_EQUALS);
339 switch (npar_sign (lexer, ds, nps))
346 lex_error (lexer, NULL);
352 else if (lex_match_id (lexer, "MISSING"))
354 lex_match (lexer, T_EQUALS);
356 if (npt->missing > 1)
358 msg (SE, _("The %s subcommand may be given only once."), "MISSING");
361 while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
363 if (lex_match_id (lexer, "ANALYSIS"))
364 npt->miss = MISS_ANALYSIS;
365 else if (lex_match_id (lexer, "LISTWISE"))
366 npt->miss = MISS_LISTWISE;
367 else if (lex_match_id (lexer, "INCLUDE"))
368 nps->filter = MV_SYSTEM;
369 else if (lex_match_id (lexer, "EXCLUDE"))
370 nps->filter = MV_ANY;
373 lex_error (lexer, NULL);
376 lex_match (lexer, T_COMMA);
379 else if (lex_match_id (lexer, "METHOD"))
381 lex_match (lexer, T_EQUALS);
385 msg (SE, _("The %s subcommand may be given only once."), "METHOD");
388 switch (npar_method (lexer, nps))
395 lex_error (lexer, NULL);
401 else if (lex_match_id (lexer, "STATISTICS"))
403 lex_match (lexer, T_EQUALS);
405 while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
407 if (lex_match_id (lexer, "DESCRIPTIVES"))
408 npt->a_statistics[NPAR_ST_DESCRIPTIVES] = 1;
409 else if (lex_match_id (lexer, "QUARTILES"))
410 npt->a_statistics[NPAR_ST_QUARTILES] = 1;
411 else if (lex_match (lexer, T_ALL))
412 npt->a_statistics[NPAR_ST_ALL] = 1;
415 lex_error (lexer, NULL);
418 lex_match (lexer, T_COMMA);
421 else if ( settings_get_syntax () != COMPATIBLE && lex_match_id (lexer, "ALGORITHM"))
423 lex_match (lexer, T_EQUALS);
424 if (lex_match_id (lexer, "COMPATIBLE"))
425 settings_set_cmd_algorithm (COMPATIBLE);
426 else if (lex_match_id (lexer, "ENHANCED"))
427 settings_set_cmd_algorithm (ENHANCED);
429 if (!lex_match (lexer, T_SLASH))
433 if (lex_token (lexer) != T_ENDCMD)
435 lex_error (lexer, _("expecting end of command"));
446 static void one_sample_insert_variables (const struct npar_test *test,
449 static void two_sample_insert_variables (const struct npar_test *test,
452 static void n_sample_insert_variables (const struct npar_test *test,
456 npar_execute (struct casereader *input,
457 const struct npar_specs *specs,
458 const struct dataset *ds)
461 struct descriptives *summary_descriptives = NULL;
463 for ( t = 0 ; t < specs->n_tests; ++t )
465 const struct npar_test *test = specs->test[t];
466 if ( NULL == test->execute )
468 msg (SW, _("NPAR subcommand not currently implemented."));
471 test->execute (ds, casereader_clone (input), specs->filter, test, specs->exact, specs->timer);
474 if ( specs->descriptives )
476 summary_descriptives = xnmalloc (sizeof (*summary_descriptives),
479 npar_summary_calc_descriptives (summary_descriptives,
480 casereader_clone (input),
482 specs->vv, specs->n_vars,
486 if ( (specs->descriptives || specs->quartiles)
487 && !taint_has_tainted_successor (casereader_get_taint (input)) )
488 do_summary_box (summary_descriptives, specs->vv, specs->n_vars );
490 free (summary_descriptives);
491 casereader_destroy (input);
495 cmd_npar_tests (struct lexer *lexer, struct dataset *ds)
497 struct cmd_npar_tests cmd;
500 struct npar_specs npar_specs = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
501 struct casegrouper *grouper;
502 struct casereader *input, *group;
503 struct hmapx var_map = HMAPX_INITIALIZER (var_map);
506 npar_specs.pool = pool_create ();
507 npar_specs.filter = MV_ANY;
508 npar_specs.n_vars = -1;
509 npar_specs.vv = NULL;
511 if ( ! parse_npar_tests (lexer, ds, &cmd, &npar_specs) )
513 pool_destroy (npar_specs.pool);
517 for (i = 0; i < npar_specs.n_tests; ++i )
519 const struct npar_test *test = npar_specs.test[i];
520 test->insert_variables (test, &var_map);
524 struct hmapx_node *node;
525 struct variable *var;
526 npar_specs.n_vars = 0;
528 HMAPX_FOR_EACH (var, node, &var_map)
530 npar_specs.n_vars ++;
531 npar_specs.vv = pool_nrealloc (npar_specs.pool, npar_specs.vv, npar_specs.n_vars, sizeof (*npar_specs.vv));
532 npar_specs.vv[npar_specs.n_vars - 1] = var;
536 sort (npar_specs.vv, npar_specs.n_vars, sizeof (*npar_specs.vv),
537 compare_var_ptrs_by_name, NULL);
539 if ( cmd.statistics )
543 for ( i = 0 ; i < NPAR_ST_count; ++i )
545 if ( cmd.a_statistics[i] )
549 case NPAR_ST_DESCRIPTIVES:
550 npar_specs.descriptives = true;
552 case NPAR_ST_QUARTILES:
553 npar_specs.quartiles = true;
556 npar_specs.quartiles = true;
557 npar_specs.descriptives = true;
566 input = proc_open (ds);
567 if ( cmd.miss == MISS_LISTWISE )
569 input = casereader_create_filter_missing (input,
577 grouper = casegrouper_create_splits (input, dataset_dict (ds));
578 while (casegrouper_get_next_group (grouper, &group))
579 npar_execute (group, &npar_specs, ds);
580 ok = casegrouper_destroy (grouper);
581 ok = proc_commit (ds) && ok;
583 pool_destroy (npar_specs.pool);
584 hmapx_destroy (&var_map);
586 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
590 npar_runs (struct lexer *lexer, struct dataset *ds,
591 struct npar_specs *specs)
593 struct runs_test *rt = pool_alloc (specs->pool, sizeof (*rt));
594 struct one_sample_test *tp = &rt->parent;
595 struct npar_test *nt = &tp->parent;
597 nt->execute = runs_execute;
598 nt->insert_variables = one_sample_insert_variables;
600 if ( lex_force_match (lexer, T_LPAREN) )
602 if ( lex_match_id (lexer, "MEAN"))
604 rt->cp_mode = CP_MEAN;
606 else if (lex_match_id (lexer, "MEDIAN"))
608 rt->cp_mode = CP_MEDIAN;
610 else if (lex_match_id (lexer, "MODE"))
612 rt->cp_mode = CP_MODE;
614 else if (lex_is_number (lexer))
616 rt->cutpoint = lex_number (lexer);
617 rt->cp_mode = CP_CUSTOM;
622 lex_error (lexer, _("Expecting MEAN, MEDIAN, MODE or number"));
626 lex_force_match (lexer, T_RPAREN);
627 lex_force_match (lexer, T_EQUALS);
628 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
629 &tp->vars, &tp->n_vars,
630 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
637 specs->test = pool_realloc (specs->pool,
639 sizeof (*specs->test) * specs->n_tests);
641 specs->test[specs->n_tests - 1] = nt;
647 npar_friedman (struct lexer *lexer, struct dataset *ds,
648 struct npar_specs *specs)
650 struct friedman_test *ft = pool_alloc (specs->pool, sizeof (*ft));
651 struct one_sample_test *ost = &ft->parent;
652 struct npar_test *nt = &ost->parent;
654 ft->kendalls_w = false;
655 nt->execute = friedman_execute;
656 nt->insert_variables = one_sample_insert_variables;
658 lex_match (lexer, T_EQUALS);
660 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
661 &ost->vars, &ost->n_vars,
662 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
668 specs->test = pool_realloc (specs->pool,
670 sizeof (*specs->test) * specs->n_tests);
672 specs->test[specs->n_tests - 1] = nt;
678 npar_kendall (struct lexer *lexer, struct dataset *ds,
679 struct npar_specs *specs)
681 struct friedman_test *kt = pool_alloc (specs->pool, sizeof (*kt));
682 struct one_sample_test *ost = &kt->parent;
683 struct npar_test *nt = &ost->parent;
685 kt->kendalls_w = true;
686 nt->execute = friedman_execute;
687 nt->insert_variables = one_sample_insert_variables;
689 lex_match (lexer, T_EQUALS);
691 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
692 &ost->vars, &ost->n_vars,
693 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
699 specs->test = pool_realloc (specs->pool,
701 sizeof (*specs->test) * specs->n_tests);
703 specs->test[specs->n_tests - 1] = nt;
710 npar_cochran (struct lexer *lexer, struct dataset *ds,
711 struct npar_specs *specs)
713 struct one_sample_test *ft = pool_alloc (specs->pool, sizeof (*ft));
714 struct npar_test *nt = &ft->parent;
716 nt->execute = cochran_execute;
717 nt->insert_variables = one_sample_insert_variables;
719 lex_match (lexer, T_EQUALS);
721 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
722 &ft->vars, &ft->n_vars,
723 PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
729 specs->test = pool_realloc (specs->pool,
731 sizeof (*specs->test) * specs->n_tests);
733 specs->test[specs->n_tests - 1] = nt;
740 npar_chisquare (struct lexer *lexer, struct dataset *ds,
741 struct npar_specs *specs)
743 struct chisquare_test *cstp = pool_alloc (specs->pool, sizeof (*cstp));
744 struct one_sample_test *tp = &cstp->parent;
745 struct npar_test *nt = &tp->parent;
748 nt->execute = chisquare_execute;
749 nt->insert_variables = one_sample_insert_variables;
751 if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
752 &tp->vars, &tp->n_vars,
753 PV_NO_SCRATCH | PV_NO_DUPLICATE))
758 cstp->ranged = false;
760 if ( lex_match (lexer, T_LPAREN))
763 if ( ! lex_force_num (lexer)) return 0;
764 cstp->lo = lex_integer (lexer);
766 lex_force_match (lexer, T_COMMA);
767 if (! lex_force_num (lexer) ) return 0;
768 cstp->hi = lex_integer (lexer);
769 if ( cstp->lo >= cstp->hi )
772 _("The specified value of HI (%d) is "
773 "lower than the specified value of LO (%d)"),
778 if (! lex_force_match (lexer, T_RPAREN)) return 0;
781 cstp->n_expected = 0;
782 cstp->expected = NULL;
783 if (lex_match_phrase (lexer, "/EXPECTED"))
785 lex_force_match (lexer, T_EQUALS);
786 if ( ! lex_match_id (lexer, "EQUAL") )
790 while ( lex_is_number (lexer) )
794 f = lex_number (lexer);
796 if ( lex_match (lexer, T_ASTERISK))
799 f = lex_number (lexer);
802 lex_match (lexer, T_COMMA);
804 cstp->n_expected += n;
805 cstp->expected = pool_realloc (specs->pool,
809 for ( i = cstp->n_expected - n ;
810 i < cstp->n_expected;
812 cstp->expected[i] = f;
818 if ( cstp->ranged && cstp->n_expected > 0 &&
819 cstp->n_expected != cstp->hi - cstp->lo + 1 )
822 _("%d expected values were given, but the specified "
823 "range (%d-%d) requires exactly %d values."),
824 cstp->n_expected, cstp->lo, cstp->hi,
825 cstp->hi - cstp->lo +1);
830 specs->test = pool_realloc (specs->pool,
832 sizeof (*specs->test) * specs->n_tests);
834 specs->test[specs->n_tests - 1] = nt;
841 npar_binomial (struct lexer *lexer, struct dataset *ds,
842 struct npar_specs *specs)
844 struct binomial_test *btp = pool_alloc (specs->pool, sizeof (*btp));
845 struct one_sample_test *tp = &btp->parent;
846 struct npar_test *nt = &tp->parent;
849 nt->execute = binomial_execute;
850 nt->insert_variables = one_sample_insert_variables;
852 btp->category1 = btp->category2 = btp->cutpoint = SYSMIS;
856 if ( lex_match (lexer, T_LPAREN) )
859 if ( lex_force_num (lexer) )
861 btp->p = lex_number (lexer);
863 lex_force_match (lexer, T_RPAREN);
871 if (equals || lex_match (lexer, T_EQUALS) )
873 if (parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
874 &tp->vars, &tp->n_vars,
875 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
877 if (lex_match (lexer, T_LPAREN))
879 lex_force_num (lexer);
880 btp->category1 = lex_number (lexer);
882 if ( lex_match (lexer, T_COMMA))
884 if ( ! lex_force_num (lexer) ) return 2;
885 btp->category2 = lex_number (lexer);
890 btp->cutpoint = btp->category1;
893 lex_force_match (lexer, T_RPAREN);
902 specs->test = pool_realloc (specs->pool,
904 sizeof (*specs->test) * specs->n_tests);
906 specs->test[specs->n_tests - 1] = nt;
913 parse_two_sample_related_test (struct lexer *lexer,
914 const struct dictionary *dict,
915 struct two_sample_test *test_parameters,
922 const struct variable **vlist1;
925 const struct variable **vlist2;
928 test_parameters->parent.insert_variables = two_sample_insert_variables;
930 if (!parse_variables_const_pool (lexer, pool,
933 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
936 if ( lex_match (lexer, T_WITH))
939 if ( !parse_variables_const_pool (lexer, pool, dict,
941 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
944 paired = (lex_match (lexer, T_LPAREN) &&
945 lex_match_id (lexer, "PAIRED") && lex_match (lexer, T_RPAREN));
953 if ( n_vlist1 != n_vlist2)
954 msg (SE, _("PAIRED was specified but the number of variables "
955 "preceding WITH (%zu) did not match the number "
956 "following (%zu)."), n_vlist1, n_vlist2);
958 test_parameters->n_pairs = n_vlist1 ;
962 test_parameters->n_pairs = n_vlist1 * n_vlist2;
967 test_parameters->n_pairs = (n_vlist1 * (n_vlist1 - 1)) / 2 ;
970 test_parameters->pairs =
971 pool_alloc (pool, sizeof ( variable_pair) * test_parameters->n_pairs);
978 assert (n_vlist1 == n_vlist2);
979 for ( i = 0 ; i < n_vlist1; ++i )
981 test_parameters->pairs[n][0] = vlist1[i];
982 test_parameters->pairs[n][1] = vlist2[i];
989 for ( i = 0 ; i < n_vlist1; ++i )
991 for ( j = 0 ; j < n_vlist2; ++j )
993 test_parameters->pairs[n][0] = vlist1[i];
994 test_parameters->pairs[n][1] = vlist2[j];
1003 for ( i = 0 ; i < n_vlist1 - 1; ++i )
1005 for ( j = i + 1 ; j < n_vlist1; ++j )
1007 assert ( n < test_parameters->n_pairs);
1008 test_parameters->pairs[n][0] = vlist1[i];
1009 test_parameters->pairs[n][1] = vlist1[j];
1015 assert ( n == test_parameters->n_pairs);
1022 parse_n_sample_related_test (struct lexer *lexer,
1023 const struct dictionary *dict,
1024 struct n_sample_test *nst,
1028 if (!parse_variables_const_pool (lexer, pool,
1030 &nst->vars, &nst->n_vars,
1031 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
1034 if ( ! lex_force_match (lexer, T_BY))
1037 nst->indep_var = parse_variable_const (lexer, dict);
1039 if ( ! lex_force_match (lexer, T_LPAREN))
1042 value_init (&nst->val1, var_get_width (nst->indep_var));
1043 if ( ! parse_value (lexer, &nst->val1, nst->indep_var))
1045 value_destroy (&nst->val1, var_get_width (nst->indep_var));
1049 lex_match (lexer, T_COMMA);
1051 value_init (&nst->val2, var_get_width (nst->indep_var));
1052 if ( ! parse_value (lexer, &nst->val2, nst->indep_var))
1054 value_destroy (&nst->val2, var_get_width (nst->indep_var));
1058 if ( ! lex_force_match (lexer, T_RPAREN))
1065 npar_wilcoxon (struct lexer *lexer,
1067 struct npar_specs *specs )
1069 struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1070 struct npar_test *nt = &tp->parent;
1071 nt->execute = wilcoxon_execute;
1073 if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
1078 specs->test = pool_realloc (specs->pool,
1080 sizeof (*specs->test) * specs->n_tests);
1081 specs->test[specs->n_tests - 1] = nt;
1088 npar_mann_whitney (struct lexer *lexer,
1090 struct npar_specs *specs )
1092 struct n_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1093 struct npar_test *nt = &tp->parent;
1095 nt->insert_variables = n_sample_insert_variables;
1096 nt->execute = mann_whitney_execute;
1098 if (!parse_n_sample_related_test (lexer, dataset_dict (ds),
1103 specs->test = pool_realloc (specs->pool,
1105 sizeof (*specs->test) * specs->n_tests);
1106 specs->test[specs->n_tests - 1] = nt;
1115 npar_sign (struct lexer *lexer, struct dataset *ds,
1116 struct npar_specs *specs)
1118 struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1119 struct npar_test *nt = &tp->parent;
1121 nt->execute = sign_execute;
1123 if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
1128 specs->test = pool_realloc (specs->pool,
1130 sizeof (*specs->test) * specs->n_tests);
1131 specs->test[specs->n_tests - 1] = nt;
1138 npar_mcnemar (struct lexer *lexer, struct dataset *ds,
1139 struct npar_specs *specs)
1141 struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1142 struct npar_test *nt = &tp->parent;
1144 nt->execute = mcnemar_execute;
1146 if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
1151 specs->test = pool_realloc (specs->pool,
1153 sizeof (*specs->test) * specs->n_tests);
1154 specs->test[specs->n_tests - 1] = nt;
1161 npar_kruskal_wallis (struct lexer *lexer, struct dataset *ds,
1162 struct npar_specs *specs)
1164 struct n_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1165 struct npar_test *nt = &tp->parent;
1167 nt->insert_variables = n_sample_insert_variables;
1169 nt->execute = kruskal_wallis_execute;
1171 if (!parse_n_sample_related_test (lexer, dataset_dict (ds),
1176 specs->test = pool_realloc (specs->pool,
1178 sizeof (*specs->test) * specs->n_tests);
1179 specs->test[specs->n_tests - 1] = nt;
1185 insert_variable_into_map (struct hmapx *var_map, const struct variable *var)
1187 size_t hash = hash_pointer (var, 0);
1188 struct hmapx_node *node;
1189 const struct variable *v = NULL;
1191 HMAPX_FOR_EACH_WITH_HASH (v, node, hash, var_map)
1197 hmapx_insert (var_map, CONST_CAST (struct variable *, var), hash);
1200 /* Insert the variables for TEST into VAR_MAP */
1202 one_sample_insert_variables (const struct npar_test *test,
1203 struct hmapx *var_map)
1206 const struct one_sample_test *ost = UP_CAST (test, const struct one_sample_test, parent);
1208 for ( i = 0 ; i < ost->n_vars ; ++i )
1209 insert_variable_into_map (var_map, ost->vars[i]);
1214 two_sample_insert_variables (const struct npar_test *test,
1215 struct hmapx *var_map)
1218 const struct two_sample_test *tst = UP_CAST (test, const struct two_sample_test, parent);
1220 for ( i = 0 ; i < tst->n_pairs ; ++i )
1222 variable_pair *pair = &tst->pairs[i];
1224 insert_variable_into_map (var_map, (*pair)[0]);
1225 insert_variable_into_map (var_map, (*pair)[1]);
1230 n_sample_insert_variables (const struct npar_test *test,
1231 struct hmapx *var_map)
1234 const struct n_sample_test *tst = UP_CAST (test, const struct n_sample_test, parent);
1236 for ( i = 0 ; i < tst->n_vars ; ++i )
1237 insert_variable_into_map (var_map, tst->vars[i]);
1239 insert_variable_into_map (var_map, tst->indep_var);
1244 npar_method (struct lexer *lexer, struct npar_specs *specs)
1246 if ( lex_match_id (lexer, "EXACT") )
1248 specs->exact = true;
1250 if (lex_match_id (lexer, "TIMER"))
1254 if ( lex_match (lexer, T_LPAREN))
1256 if ( lex_force_num (lexer) )
1258 specs->timer = lex_number (lexer);
1261 lex_force_match (lexer, T_RPAREN);