409369edbf52ac4c143ee3f1f6896ee0849d52bf
[pspp-builds.git] / src / language / stats / npar.c
1 /* PSPP - a program for statistical analysis. -*-c-*-
2    Copyright (C) 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18
19 #include <language/stats/npar.h>
20 #include "npar-summary.h"
21
22 #include <stdlib.h>
23 #include <math.h>
24
25 #include "xalloc.h"
26 #include <data/case.h>
27 #include <data/casegrouper.h>
28 #include <data/casereader.h>
29 #include <data/dictionary.h>
30 #include <data/procedure.h>
31 #include <data/settings.h>
32 #include <data/variable.h>
33 #include <language/command.h>
34 #include <language/lexer/lexer.h>
35 #include <language/lexer/variable-parser.h>
36 #include <language/stats/binomial.h>
37 #include <language/stats/chisquare.h>
38 #include <language/stats/wilcoxon.h>
39 #include <language/stats/sign.h>
40 #include <libpspp/assertion.h>
41 #include <libpspp/cast.h>
42 #include <libpspp/hash.h>
43 #include <libpspp/message.h>
44 #include <libpspp/pool.h>
45 #include <libpspp/str.h>
46 #include <libpspp/taint.h>
47 #include <math/moments.h>
48
49 #include "gettext.h"
50 #define _(msgid) gettext (msgid)
51
52 /* Settings for subcommand specifiers. */
53 enum missing_type
54   {
55     MISS_ANALYSIS,
56     MISS_LISTWISE,
57   };
58
59 /* Array indices for STATISTICS subcommand. */
60 enum
61   {
62     NPAR_ST_DESCRIPTIVES = 0,
63     NPAR_ST_QUARTILES = 1,
64     NPAR_ST_ALL = 2,
65     NPAR_ST_count
66   };
67
68 /* NPAR TESTS structure. */
69 struct cmd_npar_tests
70   {
71     /* Count variables indicating how many
72        of the subcommands have been given. */
73     int chisquare;
74     int binomial;
75     int wilcoxon;
76     int sign;
77     int missing;
78     int method;
79     int statistics;
80
81     /* How missing values should be treated */
82     long miss;
83
84     /* Which statistics have been requested */
85     int a_statistics[NPAR_ST_count];
86   };
87
88
89 struct npar_specs
90 {
91   struct pool *pool;
92   struct npar_test **test;
93   size_t n_tests;
94
95   const struct variable **vv; /* Compendium of all variables
96                                   (those mentioned on ANY subcommand */
97   int n_vars; /* Number of variables in vv */
98
99   enum mv_class filter;    /* Missing values to filter. */
100
101   bool descriptives;       /* Descriptive statistics should be calculated */
102   bool quartiles;          /* Quartiles should be calculated */
103
104   bool exact;  /* Whether exact calculations have been requested */
105   double timer;   /* Maximum time (in minutes) to wait for exact calculations */
106 };
107
108
109 /* Prototype for custom subcommands of NPAR TESTS. */
110 static int npar_chisquare (struct lexer *, struct dataset *, struct npar_specs *);
111 static int npar_binomial (struct lexer *, struct dataset *,  struct npar_specs *);
112 static int npar_wilcoxon (struct lexer *, struct dataset *, struct npar_specs *);
113 static int npar_sign (struct lexer *, struct dataset *, struct npar_specs *);
114 static int npar_method (struct lexer *, struct npar_specs *);
115
116 /* Command parsing functions. */
117 static int parse_npar_tests (struct lexer *lexer, struct dataset *ds, struct cmd_npar_tests *p,
118                              struct npar_specs *npar_specs );
119
120 static int
121 parse_npar_tests (struct lexer *lexer, struct dataset *ds, struct cmd_npar_tests *npt,
122                   struct npar_specs *nps)
123 {
124   npt->chisquare = 0;
125   npt->binomial = 0;
126   npt->wilcoxon = 0;
127   npt->sign = 0;
128   npt->missing = 0;
129   npt->miss = MISS_ANALYSIS;
130   npt->method = 0;
131   npt->statistics = 0;
132   memset (npt->a_statistics, 0, sizeof npt->a_statistics);
133   for (;;)
134     {
135       if (lex_match_hyphenated_word (lexer, "CHISQUARE"))
136         {
137           lex_match (lexer, '=');
138           npt->chisquare++;
139           switch (npar_chisquare (lexer, ds, nps))
140             {
141             case 0:
142               goto lossage;
143             case 1:
144               break;
145             case 2:
146               lex_error (lexer, NULL);
147               goto lossage;
148             default:
149               NOT_REACHED ();
150             }
151         }
152       else if (lex_match_hyphenated_word (lexer, "BINOMIAL"))
153         {
154           lex_match (lexer, '=');
155           npt->binomial++;
156           switch (npar_binomial (lexer, ds, nps))
157             {
158             case 0:
159               goto lossage;
160             case 1:
161               break;
162             case 2:
163               lex_error (lexer, NULL);
164               goto lossage;
165             default:
166               NOT_REACHED ();
167             }
168         }
169       else if (lex_match_hyphenated_word (lexer, "WILCOXON"))
170         {
171           lex_match (lexer, '=');
172           npt->wilcoxon++;
173           switch (npar_wilcoxon (lexer, ds, nps))
174             {
175             case 0:
176               goto lossage;
177             case 1:
178               break;
179             case 2:
180               lex_error (lexer, NULL);
181               goto lossage;
182             default:
183               NOT_REACHED ();
184             }
185         }
186       else if (lex_match_hyphenated_word (lexer, "SIGN"))
187         {
188           lex_match (lexer, '=');
189           npt->sign++;
190           switch (npar_sign (lexer, ds, nps))
191             {
192             case 0:
193               goto lossage;
194             case 1:
195               break;
196             case 2:
197               lex_error (lexer, NULL);
198               goto lossage;
199             default:
200               NOT_REACHED ();
201             }
202         }
203       else if (lex_match_hyphenated_word (lexer, "MISSING"))
204         {
205           lex_match (lexer, '=');
206           npt->missing++;
207           if (npt->missing > 1)
208             {
209               msg (SE, _ ("The %s subcommand may be given only once."), "MISSING");
210               goto lossage;
211             }
212           while (lex_token (lexer) != '/' && lex_token (lexer) != '.')
213             {
214               if (lex_match_hyphenated_word (lexer, "ANALYSIS"))
215                 npt->miss = MISS_ANALYSIS;
216               else if (lex_match_hyphenated_word (lexer, "LISTWISE"))
217                 npt->miss = MISS_LISTWISE;
218               else if (lex_match_hyphenated_word (lexer, "INCLUDE"))
219                 nps->filter = MV_SYSTEM;
220               else if (lex_match_hyphenated_word (lexer, "EXCLUDE"))
221                 nps->filter = MV_ANY;
222               else
223                 {
224                   lex_error (lexer, NULL);
225                   goto lossage;
226                 }
227               lex_match (lexer, ',');
228             }
229         }
230       else if (lex_match_hyphenated_word (lexer, "METHOD"))
231         {
232           lex_match (lexer, '=');
233           npt->method++;
234           if (npt->method > 1)
235             {
236               msg (SE, _ ("The %s subcommand may be given only once."), "METHOD");
237               goto lossage;
238             }
239           switch (npar_method (lexer, nps))
240             {
241             case 0:
242               goto lossage;
243             case 1:
244               break;
245             case 2:
246               lex_error (lexer, NULL);
247               goto lossage;
248             default:
249               NOT_REACHED ();
250             }
251         }
252       else if (lex_match_hyphenated_word (lexer, "STATISTICS"))
253         {
254           lex_match (lexer, '=');
255           npt->statistics++;
256           while (lex_token (lexer) != '/' && lex_token (lexer) != '.')
257             {
258               if (lex_match_hyphenated_word (lexer, "DESCRIPTIVES"))
259                 npt->a_statistics[NPAR_ST_DESCRIPTIVES] = 1;
260               else if (lex_match_hyphenated_word (lexer, "QUARTILES"))
261                 npt->a_statistics[NPAR_ST_QUARTILES] = 1;
262               else if (lex_match (lexer, T_ALL))
263                 npt->a_statistics[NPAR_ST_ALL] = 1;
264               else
265                 {
266                   lex_error (lexer, NULL);
267                   goto lossage;
268                 }
269               lex_match (lexer, ',');
270             }
271         }
272       else if ( settings_get_syntax () != COMPATIBLE && lex_match_id (lexer, "ALGORITHM"))
273         {
274           lex_match (lexer, '=');
275           if (lex_match_id (lexer, "COMPATIBLE"))
276             settings_set_cmd_algorithm (COMPATIBLE);
277           else if (lex_match_id (lexer, "ENHANCED"))
278             settings_set_cmd_algorithm (ENHANCED);
279           }
280         if (!lex_match (lexer, '/'))
281           break;
282       }
283
284     if (lex_token (lexer) != '.')
285       {
286         lex_error (lexer, _ ("expecting end of command"));
287         goto lossage;
288       }
289
290   return true;
291
292 lossage:
293   return false;
294 }
295
296
297
298
299 static void one_sample_insert_variables (const struct npar_test *test,
300                                          struct const_hsh_table *variables);
301
302 static void two_sample_insert_variables (const struct npar_test *test,
303                                          struct const_hsh_table *variables);
304
305
306 static void
307 npar_execute (struct casereader *input,
308              const struct npar_specs *specs,
309              const struct dataset *ds)
310 {
311   int t;
312   struct descriptives *summary_descriptives = NULL;
313
314   for ( t = 0 ; t < specs->n_tests; ++t )
315     {
316       const struct npar_test *test = specs->test[t];
317       if ( NULL == test->execute )
318         {
319           msg (SW, _ ("NPAR subcommand not currently implemented."));
320           continue;
321         }
322       test->execute (ds, casereader_clone (input), specs->filter, test, specs->exact, specs->timer);
323     }
324
325   if ( specs->descriptives )
326     {
327       summary_descriptives = xnmalloc (sizeof (*summary_descriptives),
328                                        specs->n_vars);
329
330       npar_summary_calc_descriptives (summary_descriptives,
331                                       casereader_clone (input),
332                                       dataset_dict (ds),
333                                       specs->vv, specs->n_vars,
334                                       specs->filter);
335     }
336
337   if ( (specs->descriptives || specs->quartiles)
338        && !taint_has_tainted_successor (casereader_get_taint (input)) )
339     do_summary_box (summary_descriptives, specs->vv, specs->n_vars );
340
341   free (summary_descriptives);
342   casereader_destroy (input);
343 }
344
345
346 int
347 cmd_npar_tests (struct lexer *lexer, struct dataset *ds)
348 {
349   struct cmd_npar_tests cmd;
350   bool ok;
351   int i;
352   struct npar_specs npar_specs = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
353   struct const_hsh_table *var_hash;
354   struct casegrouper *grouper;
355   struct casereader *input, *group;
356
357   npar_specs.pool = pool_create ();
358   npar_specs.filter = MV_ANY;
359
360   var_hash = const_hsh_create_pool (npar_specs.pool, 0,
361                                     compare_vars_by_name, hash_var_by_name,
362                                     NULL, NULL);
363
364   if ( ! parse_npar_tests (lexer, ds, &cmd, &npar_specs) )
365     {
366       pool_destroy (npar_specs.pool);
367       return CMD_FAILURE;
368     }
369
370   for (i = 0; i < npar_specs.n_tests; ++i )
371     {
372       const struct npar_test *test = npar_specs.test[i];
373       test->insert_variables (test, var_hash);
374     }
375
376   npar_specs.vv = (const struct variable **) const_hsh_sort (var_hash);
377   npar_specs.n_vars = const_hsh_count (var_hash);
378
379   if ( cmd.statistics )
380     {
381       int i;
382
383       for ( i = 0 ; i < NPAR_ST_count; ++i )
384         {
385           if ( cmd.a_statistics[i] )
386             {
387               switch ( i )
388                 {
389                 case NPAR_ST_DESCRIPTIVES:
390                   npar_specs.descriptives = true;
391                   break;
392                 case NPAR_ST_QUARTILES:
393                   npar_specs.quartiles = true;
394                   break;
395                 case NPAR_ST_ALL:
396                   npar_specs.quartiles = true;
397                   npar_specs.descriptives = true;
398                   break;
399                 default:
400                   NOT_REACHED ();
401                 };
402             }
403         }
404     }
405
406   input = proc_open (ds);
407   if ( cmd.miss == MISS_LISTWISE )
408     {
409       input = casereader_create_filter_missing (input,
410                                                 npar_specs.vv,
411                                                 npar_specs.n_vars,
412                                                 npar_specs.filter,
413                                                 NULL, NULL);
414     }
415
416
417   grouper = casegrouper_create_splits (input, dataset_dict (ds));
418   while (casegrouper_get_next_group (grouper, &group))
419     npar_execute (group, &npar_specs, ds);
420   ok = casegrouper_destroy (grouper);
421   ok = proc_commit (ds) && ok;
422
423   const_hsh_destroy (var_hash);
424
425   pool_destroy (npar_specs.pool);
426
427   return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
428 }
429
430 static int
431 npar_chisquare (struct lexer *lexer, struct dataset *ds,
432                 struct npar_specs *specs)
433 {
434   struct chisquare_test *cstp = pool_alloc (specs->pool, sizeof (*cstp));
435   struct one_sample_test *tp = &cstp->parent;
436   struct npar_test *nt = &tp->parent;
437
438   nt->execute = chisquare_execute;
439   nt->insert_variables = one_sample_insert_variables;
440
441   if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
442                                    &tp->vars, &tp->n_vars,
443                                    PV_NO_SCRATCH | PV_NO_DUPLICATE))
444     {
445       return 2;
446     }
447
448   cstp->ranged = false;
449
450   if ( lex_match (lexer, '('))
451     {
452       cstp->ranged = true;
453       if ( ! lex_force_num (lexer)) return 0;
454       cstp->lo = lex_integer (lexer);
455       lex_get (lexer);
456       lex_force_match (lexer, ',');
457       if (! lex_force_num (lexer) ) return 0;
458       cstp->hi = lex_integer (lexer);
459       if ( cstp->lo >= cstp->hi )
460         {
461           msg (ME,
462               _ ("The specified value of HI (%d) is "
463                 "lower than the specified value of LO (%d)"),
464               cstp->hi, cstp->lo);
465           return 0;
466         }
467       lex_get (lexer);
468       if (! lex_force_match (lexer, ')')) return 0;
469     }
470
471   cstp->n_expected = 0;
472   cstp->expected = NULL;
473   if ( lex_match (lexer, '/') )
474     {
475       if ( lex_match_id (lexer, "EXPECTED") )
476         {
477           lex_force_match (lexer, '=');
478           if ( ! lex_match_id (lexer, "EQUAL") )
479             {
480               double f;
481               int n;
482               while ( lex_is_number (lexer) )
483                 {
484                   int i;
485                   n = 1;
486                   f = lex_number (lexer);
487                   lex_get (lexer);
488                   if ( lex_match (lexer, '*'))
489                     {
490                       n = f;
491                       f = lex_number (lexer);
492                       lex_get (lexer);
493                     }
494                   lex_match (lexer, ',');
495
496                   cstp->n_expected += n;
497                   cstp->expected = pool_realloc (specs->pool,
498                                                  cstp->expected,
499                                                  sizeof (double) *
500                                                  cstp->n_expected);
501                   for ( i = cstp->n_expected - n ;
502                         i < cstp->n_expected;
503                         ++i )
504                     cstp->expected[i] = f;
505
506                 }
507             }
508         }
509       else
510         lex_put_back (lexer, '/');
511     }
512
513   if ( cstp->ranged && cstp->n_expected > 0 &&
514        cstp->n_expected != cstp->hi - cstp->lo + 1 )
515     {
516       msg (ME,
517           _ ("%d expected values were given, but the specified "
518             "range (%d-%d) requires exactly %d values."),
519           cstp->n_expected, cstp->lo, cstp->hi,
520           cstp->hi - cstp->lo +1);
521       return 0;
522     }
523
524   specs->n_tests++;
525   specs->test = pool_realloc (specs->pool,
526                               specs->test,
527                               sizeof (*specs->test) * specs->n_tests);
528
529   specs->test[specs->n_tests - 1] = nt;
530
531   return 1;
532 }
533
534
535 static int
536 npar_binomial (struct lexer *lexer, struct dataset *ds,
537                struct npar_specs *specs)
538 {
539   struct binomial_test *btp = pool_alloc (specs->pool, sizeof (*btp));
540   struct one_sample_test *tp = &btp->parent;
541   struct npar_test *nt = &tp->parent;
542
543   nt->execute = binomial_execute;
544   nt->insert_variables = one_sample_insert_variables;
545
546   btp->category1 = btp->category2 = btp->cutpoint = SYSMIS;
547
548   btp->p = 0.5;
549
550   if ( lex_match (lexer, '(') )
551     {
552       if ( lex_force_num (lexer) )
553         {
554           btp->p = lex_number (lexer);
555           lex_get (lexer);
556           lex_force_match (lexer, ')');
557         }
558       else
559         return 0;
560     }
561   else
562     /* Kludge: q2c swallows the '=' so put it back here  */
563      lex_put_back (lexer, '=');
564
565   if (lex_match (lexer, '=') )
566     {
567       if (parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
568                                       &tp->vars, &tp->n_vars,
569                                       PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
570         {
571           if (lex_match (lexer, '('))
572             {
573               lex_force_num (lexer);
574               btp->category1 = lex_number (lexer);
575               lex_get (lexer);
576               if ( lex_match (lexer, ','))
577                 {
578                   if ( ! lex_force_num (lexer) ) return 2;
579                   btp->category2 = lex_number (lexer);
580                   lex_get (lexer);
581                 }
582               else
583                 {
584                   btp->cutpoint = btp->category1;
585                 }
586
587               lex_force_match (lexer, ')');
588             }
589         }
590       else
591         return 2;
592
593     }
594
595   specs->n_tests++;
596   specs->test = pool_realloc (specs->pool,
597                               specs->test,
598                               sizeof (*specs->test) * specs->n_tests);
599
600   specs->test[specs->n_tests - 1] = nt;
601
602   return 1;
603 }
604
605
606 static bool
607 parse_two_sample_related_test (struct lexer *lexer,
608                                     const struct dictionary *dict,
609                                     struct two_sample_test *test_parameters,
610                                     struct pool *pool
611                                     );
612
613
614 static bool
615 parse_two_sample_related_test (struct lexer *lexer,
616                                const struct dictionary *dict,
617                                struct two_sample_test *test_parameters,
618                                struct pool *pool
619                                )
620 {
621   int n = 0;
622   bool paired = false;
623   bool with = false;
624   const struct variable **vlist1;
625   size_t n_vlist1;
626
627   const struct variable **vlist2;
628   size_t n_vlist2;
629
630   test_parameters->parent.insert_variables = two_sample_insert_variables;
631
632   if (!parse_variables_const_pool (lexer, pool,
633                                    dict,
634                                    &vlist1, &n_vlist1,
635                                    PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
636     return false;
637
638   if ( lex_match (lexer, T_WITH))
639     {
640       with = true;
641       if ( !parse_variables_const_pool (lexer, pool, dict,
642                                         &vlist2, &n_vlist2,
643                                         PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) )
644         return false;
645
646       paired = (lex_match (lexer, '(') &&
647                 lex_match_id (lexer, "PAIRED") && lex_match (lexer, ')'));
648     }
649
650
651   if ( with )
652     {
653       if (paired)
654         {
655           if ( n_vlist1 != n_vlist2)
656             msg (SE, _ ("PAIRED was specified but the number of variables "
657                        "preceding WITH (%zu) did not match the number "
658                        "following (%zu)."), n_vlist1, n_vlist2);
659
660           test_parameters->n_pairs = n_vlist1 ;
661         }
662       else
663         {
664           test_parameters->n_pairs = n_vlist1 * n_vlist2;
665         }
666     }
667   else
668     {
669       test_parameters->n_pairs = (n_vlist1 * (n_vlist1 - 1)) / 2 ;
670     }
671
672   test_parameters->pairs =
673     pool_alloc (pool, sizeof ( variable_pair) * test_parameters->n_pairs);
674
675   if ( with )
676     {
677       if (paired)
678         {
679           int i;
680           assert (n_vlist1 == n_vlist2);
681           for ( i = 0 ; i < n_vlist1; ++i )
682             {
683               test_parameters->pairs[n][1] = vlist1[i];
684               test_parameters->pairs[n][0] = vlist2[i];
685               n++;
686             }
687         }
688       else
689         {
690           int i,j;
691           for ( i = 0 ; i < n_vlist1; ++i )
692             {
693               for ( j = 0 ; j < n_vlist2; ++j )
694                 {
695                   test_parameters->pairs[n][1] = vlist1[i];
696                   test_parameters->pairs[n][0] = vlist2[j];
697                   n++;
698                 }
699             }
700         }
701     }
702   else
703     {
704       int i,j;
705       for ( i = 0 ; i < n_vlist1 - 1; ++i )
706         {
707           for ( j = i + 1 ; j < n_vlist1; ++j )
708             {
709               assert ( n < test_parameters->n_pairs);
710               test_parameters->pairs[n][1] = vlist1[i];
711               test_parameters->pairs[n][0] = vlist1[j];
712               n++;
713             }
714         }
715     }
716
717   assert ( n == test_parameters->n_pairs);
718
719   return true;
720 }
721
722
723 static int
724 npar_wilcoxon (struct lexer *lexer,
725                struct dataset *ds,
726                struct npar_specs *specs )
727 {
728
729
730   struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
731   struct npar_test *nt = &tp->parent;
732   nt->execute = wilcoxon_execute;
733
734   if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
735                                       tp, specs->pool) )
736     return 0;
737
738   specs->n_tests++;
739   specs->test = pool_realloc (specs->pool,
740                               specs->test,
741                               sizeof (*specs->test) * specs->n_tests);
742   specs->test[specs->n_tests - 1] = nt;
743
744   return 1;
745 }
746
747 static int
748 npar_sign (struct lexer *lexer, struct dataset *ds,
749            struct npar_specs *specs)
750 {
751   struct two_sample_test *tp = pool_alloc (specs->pool, sizeof (*tp));
752   struct npar_test *nt = &tp->parent;
753
754   nt->execute = sign_execute;
755
756   if (!parse_two_sample_related_test (lexer, dataset_dict (ds),
757                                       tp, specs->pool) )
758     return 0;
759
760   specs->n_tests++;
761   specs->test = pool_realloc (specs->pool,
762                               specs->test,
763                               sizeof (*specs->test) * specs->n_tests);
764   specs->test[specs->n_tests - 1] = nt;
765
766   return 1;
767 }
768
769
770 /* Insert the variables for TEST into VAR_HASH */
771 static void
772 one_sample_insert_variables (const struct npar_test *test,
773                              struct const_hsh_table *var_hash)
774 {
775   int i;
776   const struct one_sample_test *ost = UP_CAST (test, const struct one_sample_test, parent);
777
778   for ( i = 0 ; i < ost->n_vars ; ++i )
779     const_hsh_insert (var_hash, ost->vars[i]);
780 }
781
782
783 static void
784 two_sample_insert_variables (const struct npar_test *test,
785                              struct const_hsh_table *var_hash)
786 {
787   int i;
788
789   const struct two_sample_test *tst = UP_CAST (test, const struct two_sample_test, parent);
790
791   for ( i = 0 ; i < tst->n_pairs ; ++i )
792     {
793       variable_pair *pair = &tst->pairs[i];
794
795       const_hsh_insert (var_hash, (*pair)[0]);
796       const_hsh_insert (var_hash, (*pair)[1]);
797     }
798 }
799
800 static int
801 npar_method (struct lexer *lexer,  struct npar_specs *specs)
802 {
803   if ( lex_match_id (lexer, "EXACT") )
804     {
805       specs->exact = true;
806       specs->timer = 0.0;
807       if (lex_match_id (lexer, "TIMER"))
808         {
809           specs->timer = 5.0;
810
811           if ( lex_match (lexer, '('))
812             {
813               if ( lex_force_num (lexer) )
814                 {
815                   specs->timer = lex_number (lexer);
816                   lex_get (lexer);
817                 }
818               lex_force_match (lexer, ')');
819             }
820         }
821     }
822
823   return 1;
824 }