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_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);
242 else if (lex_match_id (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, T_EQUALS);
282 switch (npar_mann_whitney (lexer, ds, nps))
289 lex_error (lexer, NULL);
295 else if (lex_match_id (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_id (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_id (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_id (lexer, "ANALYSIS"))
341 npt->miss = MISS_ANALYSIS;
342 else if (lex_match_id (lexer, "LISTWISE"))
343 npt->miss = MISS_LISTWISE;
344 else if (lex_match_id (lexer, "INCLUDE"))
345 nps->filter = MV_SYSTEM;
346 else if (lex_match_id (lexer, "EXCLUDE"))
347 nps->filter = MV_ANY;
350 lex_error (lexer, NULL);
353 lex_match (lexer, T_COMMA);
356 else if (lex_match_id (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_id (lexer, "STATISTICS"))
380 lex_match (lexer, T_EQUALS);
382 while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD)
384 if (lex_match_id (lexer, "DESCRIPTIVES"))
385 npt->a_statistics[NPAR_ST_DESCRIPTIVES] = 1;
386 else if (lex_match_id (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, T_LPAREN) )
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, T_RPAREN);
604 lex_force_match (lexer, T_EQUALS);
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, T_EQUALS);
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, T_EQUALS);
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, T_EQUALS);
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, 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 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;
831 nt->execute = binomial_execute;
832 nt->insert_variables = one_sample_insert_variables;
834 btp->category1 = btp->category2 = btp->cutpoint = SYSMIS;
838 if ( lex_match (lexer, T_LPAREN) )
841 if ( lex_force_num (lexer) )
843 btp->p = lex_number (lexer);
845 lex_force_match (lexer, T_RPAREN);
853 if (equals || lex_match (lexer, T_EQUALS) )
855 if (parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
856 &tp->vars, &tp->n_vars,
857 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
859 if (lex_match (lexer, T_LPAREN))
861 lex_force_num (lexer);
862 btp->category1 = lex_number (lexer);
864 if ( lex_match (lexer, T_COMMA))
866 if ( ! lex_force_num (lexer) ) return 2;
867 btp->category2 = lex_number (lexer);
872 btp->cutpoint = btp->category1;
875 lex_force_match (lexer, T_RPAREN);
884 specs->test = pool_realloc (specs->pool,
886 sizeof (*specs->test) * specs->n_tests);
888 specs->test[specs->n_tests - 1] = nt;
895 parse_two_sample_related_test (struct lexer *lexer,
896 const struct dictionary *dict,
897 struct two_sample_test *test_parameters,
903 parse_two_sample_related_test (struct lexer *lexer,
904 const struct dictionary *dict,
905 struct two_sample_test *test_parameters,
912 const struct variable **vlist1;
915 const struct variable **vlist2;
918 test_parameters->parent.insert_variables = two_sample_insert_variables;
920 if (!parse_variables_const_pool (lexer, pool,
923 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
926 if ( lex_match (lexer, T_WITH))
929 if ( !parse_variables_const_pool (lexer, pool, dict,
931 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
934 paired = (lex_match (lexer, T_LPAREN) &&
935 lex_match_id (lexer, "PAIRED") && lex_match (lexer, T_RPAREN));
943 if ( n_vlist1 != n_vlist2)
944 msg (SE, _("PAIRED was specified but the number of variables "
945 "preceding WITH (%zu) did not match the number "
946 "following (%zu)."), n_vlist1, n_vlist2);
948 test_parameters->n_pairs = n_vlist1 ;
952 test_parameters->n_pairs = n_vlist1 * n_vlist2;
957 test_parameters->n_pairs = (n_vlist1 * (n_vlist1 - 1)) / 2 ;
960 test_parameters->pairs =
961 pool_alloc (pool, sizeof ( variable_pair) * test_parameters->n_pairs);
968 assert (n_vlist1 == n_vlist2);
969 for ( i = 0 ; i < n_vlist1; ++i )
971 test_parameters->pairs[n][1] = vlist1[i];
972 test_parameters->pairs[n][0] = vlist2[i];
979 for ( i = 0 ; i < n_vlist1; ++i )
981 for ( j = 0 ; j < n_vlist2; ++j )
983 test_parameters->pairs[n][1] = vlist1[i];
984 test_parameters->pairs[n][0] = vlist2[j];
993 for ( i = 0 ; i < n_vlist1 - 1; ++i )
995 for ( j = i + 1 ; j < n_vlist1; ++j )
997 assert ( n < test_parameters->n_pairs);
998 test_parameters->pairs[n][1] = vlist1[i];
999 test_parameters->pairs[n][0] = vlist1[j];
1005 assert ( n == test_parameters->n_pairs);
1012 parse_n_sample_related_test (struct lexer *lexer,
1013 const struct dictionary *dict,
1014 struct n_sample_test *nst,
1018 if (!parse_variables_const_pool (lexer, pool,
1020 &nst->vars, &nst->n_vars,
1021 PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
1024 if ( ! lex_force_match (lexer, T_BY))
1027 nst->indep_var = parse_variable_const (lexer, dict);
1029 if ( ! lex_force_match (lexer, T_LPAREN))
1032 value_init (&nst->val1, var_get_width (nst->indep_var));
1033 if ( ! parse_value (lexer, &nst->val1, var_get_width (nst->indep_var)))
1035 value_destroy (&nst->val1, var_get_width (nst->indep_var));
1039 lex_match (lexer, T_COMMA);
1041 value_init (&nst->val2, var_get_width (nst->indep_var));
1042 if ( ! parse_value (lexer, &nst->val2, var_get_width (nst->indep_var)))
1044 value_destroy (&nst->val2, var_get_width (nst->indep_var));
1048 if ( ! lex_force_match (lexer, T_RPAREN))
1055 npar_wilcoxon (struct lexer *lexer,
1057 struct npar_specs *specs )
1061 struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1062 struct npar_test *nt = &tp->parent;
1063 nt->execute = wilcoxon_execute;
1065 if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
1070 specs->test = pool_realloc (specs->pool,
1072 sizeof (*specs->test) * specs->n_tests);
1073 specs->test[specs->n_tests - 1] = nt;
1080 npar_mann_whitney (struct lexer *lexer,
1082 struct npar_specs *specs )
1084 struct n_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1085 struct npar_test *nt = &tp->parent;
1087 nt->insert_variables = n_sample_insert_variables;
1088 nt->execute = mann_whitney_execute;
1090 if (!parse_n_sample_related_test (lexer, dataset_dict (ds),
1095 specs->test = pool_realloc (specs->pool,
1097 sizeof (*specs->test) * specs->n_tests);
1098 specs->test[specs->n_tests - 1] = nt;
1105 npar_sign (struct lexer *lexer, struct dataset *ds,
1106 struct npar_specs *specs)
1108 struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1109 struct npar_test *nt = &tp->parent;
1111 nt->execute = sign_execute;
1113 if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
1118 specs->test = pool_realloc (specs->pool,
1120 sizeof (*specs->test) * specs->n_tests);
1121 specs->test[specs->n_tests - 1] = nt;
1127 npar_kruskal_wallis (struct lexer *lexer, struct dataset *ds,
1128 struct npar_specs *specs)
1130 struct n_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
1131 struct npar_test *nt = &tp->parent;
1133 nt->insert_variables = n_sample_insert_variables;
1135 nt->execute = kruskal_wallis_execute;
1137 if (!parse_n_sample_related_test (lexer, dataset_dict (ds),
1142 specs->test = pool_realloc (specs->pool,
1144 sizeof (*specs->test) * specs->n_tests);
1145 specs->test[specs->n_tests - 1] = nt;
1151 insert_variable_into_map (struct hmapx *var_map, const struct variable *var)
1153 size_t hash = hash_pointer (var, 0);
1154 struct hmapx_node *node;
1155 const struct variable *v = NULL;
1157 HMAPX_FOR_EACH_WITH_HASH (v, node, hash, var_map)
1163 hmapx_insert (var_map, CONST_CAST (struct variable *, var), hash);
1166 /* Insert the variables for TEST into VAR_MAP */
1168 one_sample_insert_variables (const struct npar_test *test,
1169 struct hmapx *var_map)
1172 const struct one_sample_test *ost = UP_CAST (test, const struct one_sample_test, parent);
1174 for ( i = 0 ; i < ost->n_vars ; ++i )
1175 insert_variable_into_map (var_map, ost->vars[i]);
1180 two_sample_insert_variables (const struct npar_test *test,
1181 struct hmapx *var_map)
1184 const struct two_sample_test *tst = UP_CAST (test, const struct two_sample_test, parent);
1186 for ( i = 0 ; i < tst->n_pairs ; ++i )
1188 variable_pair *pair = &tst->pairs[i];
1190 insert_variable_into_map (var_map, (*pair)[0]);
1191 insert_variable_into_map (var_map, (*pair)[1]);
1196 n_sample_insert_variables (const struct npar_test *test,
1197 struct hmapx *var_map)
1200 const struct n_sample_test *tst = UP_CAST (test, const struct n_sample_test, parent);
1202 for ( i = 0 ; i < tst->n_vars ; ++i )
1203 insert_variable_into_map (var_map, tst->vars[i]);
1205 insert_variable_into_map (var_map, tst->indep_var);
1210 npar_method (struct lexer *lexer, struct npar_specs *specs)
1212 if ( lex_match_id (lexer, "EXACT") )
1214 specs->exact = true;
1216 if (lex_match_id (lexer, "TIMER"))
1220 if ( lex_match (lexer, T_LPAREN))
1222 if ( lex_force_num (lexer) )
1224 specs->timer = lex_number (lexer);
1227 lex_force_match (lexer, T_RPAREN);