glm.c: new function design_full to create default interactions
[pspp] / src / language / stats / glm.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2010, 2011 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 <gsl/gsl_cdf.h>
20 #include <gsl/gsl_matrix.h>
21 #include <gsl/gsl_combination.h>
22 #include <math.h>
23
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/format.h"
30 #include "data/value.h"
31 #include "language/command.h"
32 #include "language/dictionary/split-file.h"
33 #include "language/lexer/lexer.h"
34 #include "language/lexer/value-parser.h"
35 #include "language/lexer/variable-parser.h"
36 #include "libpspp/ll.h"
37 #include "libpspp/message.h"
38 #include "libpspp/misc.h"
39 #include "libpspp/taint.h"
40 #include "linreg/sweep.h"
41 #include "math/categoricals.h"
42 #include "math/covariance.h"
43 #include "math/interaction.h"
44 #include "math/moments.h"
45 #include "output/tab.h"
46
47 #include "gettext.h"
48 #define _(msgid) gettext (msgid)
49
50 struct glm_spec
51 {
52   size_t n_dep_vars;
53   const struct variable **dep_vars;
54
55   size_t n_factor_vars;
56   const struct variable **factor_vars;
57
58   size_t n_interactions;
59   struct interaction **interactions;
60
61   enum mv_class exclude;
62
63   /* The weight variable */
64   const struct variable *wv;
65
66   const struct dictionary *dict;
67
68   bool intercept;
69
70   double alpha;
71 };
72
73 struct glm_workspace
74 {
75   double total_ssq;
76   struct moments *totals;
77
78   struct categoricals *cats;
79
80   /* 
81      Sums of squares due to different variables. Element 0 is the SSE
82      for the entire model. For i > 0, element i is the SS due to
83      variable i.
84    */
85   gsl_vector *ssq;
86 };
87
88
89 /* Default design: all possible interactions */
90 static void
91 design_full (struct glm_spec *glm)
92 {
93   int sz;
94   int i = 0;
95   glm->n_interactions = (1 << glm->n_factor_vars) - 1;
96
97   glm->interactions = xcalloc (glm->n_interactions, sizeof *glm->interactions);
98
99   /* All subsets, with exception of the empty set, of [0, glm->n_factor_vars) */
100   for (sz = 1; sz <= glm->n_factor_vars; ++sz)
101     {
102       gsl_combination *c = gsl_combination_calloc (glm->n_factor_vars, sz);
103
104       do
105         {
106           struct interaction *iact = interaction_create (NULL);
107           int e;
108           for (e = 0 ; e < gsl_combination_k (c); ++e)
109             interaction_add_variable (iact, glm->factor_vars [gsl_combination_get (c, e)]);
110
111           glm->interactions[i++] = iact;
112         }
113       while (gsl_combination_next (c) == GSL_SUCCESS);
114
115       gsl_combination_free (c);
116     }
117 }
118
119 static void output_glm (const struct glm_spec *,
120                         const struct glm_workspace *ws);
121 static void run_glm (struct glm_spec *cmd, struct casereader *input,
122                      const struct dataset *ds);
123
124
125 static bool parse_design_spec (struct lexer *lexer, struct glm_spec *glm);
126
127 /* Define to 1 if the /DESIGN subcommand should not be optional */
128 #define DESIGN_MANDATORY 1
129
130 int
131 cmd_glm (struct lexer *lexer, struct dataset *ds)
132 {
133   int i;
134   struct const_var_set *factors = NULL;
135   struct glm_spec glm;
136   bool design = false;
137   glm.dict = dataset_dict (ds);
138   glm.n_dep_vars = 0;
139   glm.n_factor_vars = 0;
140   glm.n_interactions = 0;
141   glm.interactions = NULL;
142   glm.dep_vars = NULL;
143   glm.factor_vars = NULL;
144   glm.exclude = MV_ANY;
145   glm.intercept = true;
146   glm.wv = dict_get_weight (glm.dict);
147   glm.alpha = 0.05;
148
149   if (!parse_variables_const (lexer, glm.dict,
150                               &glm.dep_vars, &glm.n_dep_vars,
151                               PV_NO_DUPLICATE | PV_NUMERIC))
152     goto error;
153
154   lex_force_match (lexer, T_BY);
155
156   if (!parse_variables_const (lexer, glm.dict,
157                               &glm.factor_vars, &glm.n_factor_vars,
158                               PV_NO_DUPLICATE | PV_NUMERIC))
159     goto error;
160
161   if (glm.n_dep_vars > 1)
162     {
163       msg (ME, _("Multivariate analysis is not yet implemented"));
164       return CMD_FAILURE;
165     }
166
167   factors =
168     const_var_set_create_from_array (glm.factor_vars, glm.n_factor_vars);
169
170   while (lex_token (lexer) != T_ENDCMD)
171     {
172       lex_match (lexer, T_SLASH);
173
174       if (lex_match_id (lexer, "MISSING"))
175         {
176           lex_match (lexer, T_EQUALS);
177           while (lex_token (lexer) != T_ENDCMD
178                  && lex_token (lexer) != T_SLASH)
179             {
180               if (lex_match_id (lexer, "INCLUDE"))
181                 {
182                   glm.exclude = MV_SYSTEM;
183                 }
184               else if (lex_match_id (lexer, "EXCLUDE"))
185                 {
186                   glm.exclude = MV_ANY;
187                 }
188               else
189                 {
190                   lex_error (lexer, NULL);
191                   goto error;
192                 }
193             }
194         }
195       else if (lex_match_id (lexer, "INTERCEPT"))
196         {
197           lex_match (lexer, T_EQUALS);
198           while (lex_token (lexer) != T_ENDCMD
199                  && lex_token (lexer) != T_SLASH)
200             {
201               if (lex_match_id (lexer, "INCLUDE"))
202                 {
203                   glm.intercept = true;
204                 }
205               else if (lex_match_id (lexer, "EXCLUDE"))
206                 {
207                   glm.intercept = false;
208                 }
209               else
210                 {
211                   lex_error (lexer, NULL);
212                   goto error;
213                 }
214             }
215         }
216       else if (lex_match_id (lexer, "CRITERIA"))
217         {
218           lex_match (lexer, T_EQUALS);
219           if (lex_match_id (lexer, "ALPHA"))
220             {
221               if (lex_force_match (lexer, T_LPAREN))
222                 {
223                   if (! lex_force_num (lexer))
224                     {
225                       lex_error (lexer, NULL);
226                       goto error;
227                     }
228                   
229                   glm.alpha = lex_number (lexer);
230                   lex_get (lexer);
231                   if ( ! lex_force_match (lexer, T_RPAREN))
232                     {
233                       lex_error (lexer, NULL);
234                       goto error;
235                     }
236                 }
237             }
238           else
239             {
240               lex_error (lexer, NULL);
241               goto error;
242             }
243         }
244       else if (lex_match_id (lexer, "METHOD"))
245         {
246           lex_match (lexer, T_EQUALS);
247           if ( !lex_force_match_id (lexer, "SSTYPE"))
248             {
249               lex_error (lexer, NULL);
250               goto error;
251             }
252
253           if ( ! lex_force_match (lexer, T_LPAREN))
254             {
255               lex_error (lexer, NULL);
256               goto error;
257             }
258
259           if ( ! lex_force_int (lexer))
260             {
261               lex_error (lexer, NULL);
262               goto error;
263             }
264
265           if (3 != lex_integer (lexer))
266             {
267               msg (ME, _("Only type 3 sum of squares are currently implemented"));
268               goto error;
269             }
270
271           lex_get (lexer);
272
273           if ( ! lex_force_match (lexer, T_RPAREN))
274             {
275               lex_error (lexer, NULL);
276               goto error;
277             }
278         }
279       else if (lex_match_id (lexer, "DESIGN"))
280         {
281           lex_match (lexer, T_EQUALS);
282
283           if (! parse_design_spec (lexer, &glm))
284             goto error;
285
286 #if DESIGN_MANDATORY
287           if ( glm.n_interactions == 0)
288             {
289               msg (ME, _("One or more design  variables must be given"));
290               goto error;
291             }
292           
293           design = true;
294 #else
295           if (glm.n_interactions > 0)
296             design = true;
297 #endif
298         }
299       else
300         {
301           lex_error (lexer, NULL);
302           goto error;
303         }
304     }
305
306   if ( ! design )
307     {
308 #if DESIGN_MANDATORY
309       lex_error (lexer, _("/DESIGN is mandatory in GLM"));
310       goto error;
311 #endif
312
313       design_full (&glm);
314     }
315
316   {
317     struct casegrouper *grouper;
318     struct casereader *group;
319     bool ok;
320
321     grouper = casegrouper_create_splits (proc_open (ds), glm.dict);
322     while (casegrouper_get_next_group (grouper, &group))
323       run_glm (&glm, group, ds);
324     ok = casegrouper_destroy (grouper);
325     ok = proc_commit (ds) && ok;
326   }
327
328   const_var_set_destroy (factors);
329   free (glm.factor_vars);
330   for (i = 0 ; i < glm.n_interactions; ++i)
331     interaction_destroy (glm.interactions[i]);
332   free (glm.interactions);
333   free (glm.dep_vars);
334
335
336   return CMD_SUCCESS;
337
338 error:
339
340   const_var_set_destroy (factors);
341   free (glm.factor_vars);
342   for (i = 0 ; i < glm.n_interactions; ++i)
343     interaction_destroy (glm.interactions[i]);
344
345   free (glm.interactions);
346   free (glm.dep_vars);
347
348   return CMD_FAILURE;
349 }
350
351 static void get_ssq (struct covariance *, gsl_vector *,
352                      const struct glm_spec *);
353
354 static bool
355 not_dropped (size_t j, const size_t *dropped, size_t n_dropped)
356 {
357   size_t i;
358
359   for (i = 0; i < n_dropped; i++)
360     {
361       if (j == dropped[i])
362         return false;
363     }
364   return true;
365 }
366
367 static void
368 get_ssq (struct covariance *cov, gsl_vector *ssq, const struct glm_spec *cmd)
369 {
370   gsl_matrix *cm = covariance_calculate_unnormalized (cov);
371   size_t i;
372   size_t j;
373   size_t k;
374   size_t *dropped = xcalloc (covariance_dim (cov), sizeof (*dropped));
375   const struct categoricals *cats = covariance_get_categoricals (cov);
376
377   for (k = 0; k < cmd->n_interactions; k++)
378     {
379       size_t n = 0;
380       size_t m = 0;
381       gsl_matrix *small_cov = NULL;
382       size_t n_dropped = 0;
383       for (i = cmd->n_dep_vars; i < covariance_dim (cov); i++)
384         {
385           if (categoricals_get_interaction_by_subscript (cats, i - cmd->n_dep_vars)
386               == cmd->interactions[k])
387             {
388               assert (n_dropped < covariance_dim (cov));
389               dropped[n_dropped++] = i;
390             }
391         }
392       small_cov =
393         gsl_matrix_alloc (cm->size1 - n_dropped, cm->size2 - n_dropped);
394       gsl_matrix_set (small_cov, 0, 0, gsl_matrix_get (cm, 0, 0));
395       for (i = 0; i < cm->size1; i++)
396         {
397           if (not_dropped (i, dropped, n_dropped))
398             {
399               m = 0;
400               for (j = 0; j < cm->size2; j++)
401                 {
402                   if (not_dropped (j, dropped, n_dropped))
403                     {
404                       gsl_matrix_set (small_cov, n, m,
405                                       gsl_matrix_get (cm, i, j));
406                       m++;
407                     }
408                 }
409               n++;
410             }
411         }
412       reg_sweep (small_cov, 0);
413       gsl_vector_set (ssq, k + 1,
414                       gsl_matrix_get (small_cov, 0, 0)
415                       - gsl_vector_get (ssq, 0));
416       gsl_matrix_free (small_cov);
417     }
418
419   free (dropped);
420   gsl_matrix_free (cm);
421 }
422
423 //static  void dump_matrix (const gsl_matrix *m);
424
425 static void
426 run_glm (struct glm_spec *cmd, struct casereader *input,
427          const struct dataset *ds)
428 {
429   bool warn_bad_weight = true;
430   int v;
431   struct taint *taint;
432   struct dictionary *dict = dataset_dict (ds);
433   struct casereader *reader;
434   struct ccase *c;
435
436   struct glm_workspace ws;
437   struct covariance *cov;
438
439   ws.cats = categoricals_create (cmd->interactions, cmd->n_interactions,
440                                  cmd->wv, cmd->exclude,
441                                  NULL, NULL, NULL, NULL);
442
443   cov = covariance_2pass_create (cmd->n_dep_vars, cmd->dep_vars,
444                                  ws.cats, cmd->wv, cmd->exclude);
445
446
447   c = casereader_peek (input, 0);
448   if (c == NULL)
449     {
450       casereader_destroy (input);
451       return;
452     }
453   output_split_file_values (ds, c);
454   case_unref (c);
455
456   taint = taint_clone (casereader_get_taint (input));
457
458   ws.totals = moments_create (MOMENT_VARIANCE);
459
460   for (reader = casereader_clone (input);
461        (c = casereader_read (reader)) != NULL; case_unref (c))
462     {
463       double weight = dict_get_case_weight (dict, c, &warn_bad_weight);
464
465       for (v = 0; v < cmd->n_dep_vars; ++v)
466         moments_pass_one (ws.totals, case_data (c, cmd->dep_vars[v])->f,
467                           weight);
468
469       covariance_accumulate_pass1 (cov, c);
470     }
471   casereader_destroy (reader);
472
473   for (reader = input;
474        (c = casereader_read (reader)) != NULL; case_unref (c))
475     {
476       double weight = dict_get_case_weight (dict, c, &warn_bad_weight);
477
478       for (v = 0; v < cmd->n_dep_vars; ++v)
479         moments_pass_two (ws.totals, case_data (c, cmd->dep_vars[v])->f,
480                           weight);
481
482       covariance_accumulate_pass2 (cov, c);
483     }
484   casereader_destroy (reader);
485
486   {
487     gsl_matrix *cm = covariance_calculate_unnormalized (cov);
488
489     //    dump_matrix (cm);
490
491     ws.total_ssq = gsl_matrix_get (cm, 0, 0);
492
493     reg_sweep (cm, 0);
494
495     /*
496       Store the overall SSE.
497     */
498     ws.ssq = gsl_vector_alloc (cm->size1);
499     gsl_vector_set (ws.ssq, 0, gsl_matrix_get (cm, 0, 0));
500     get_ssq (cov, ws.ssq, cmd);
501     //    dump_matrix (cm);
502
503     gsl_matrix_free (cm);
504   }
505
506   if (!taint_has_tainted_successor (taint))
507     output_glm (cmd, &ws);
508
509   gsl_vector_free (ws.ssq);
510
511   covariance_destroy (cov);
512   moments_destroy (ws.totals);
513
514   taint_destroy (taint);
515 }
516
517 static void
518 output_glm (const struct glm_spec *cmd, const struct glm_workspace *ws)
519 {
520   const struct fmt_spec *wfmt =
521     cmd->wv ? var_get_print_format (cmd->wv) : &F_8_0;
522
523   double n_total, mean;
524   double df_corr = 0.0;
525   double mse = 0;
526
527   int f;
528   int r;
529   const int heading_columns = 1;
530   const int heading_rows = 1;
531   struct tab_table *t;
532
533   const int nc = 6;
534   int nr = heading_rows + 4 + cmd->n_interactions;
535   if (cmd->intercept)
536     nr++;
537
538   t = tab_create (nc, nr);
539   tab_title (t, _("Tests of Between-Subjects Effects"));
540
541   tab_headers (t, heading_columns, 0, heading_rows, 0);
542
543   tab_box (t, TAL_2, TAL_2, -1, TAL_1, 0, 0, nc - 1, nr - 1);
544
545   tab_hline (t, TAL_2, 0, nc - 1, heading_rows);
546   tab_vline (t, TAL_2, heading_columns, 0, nr - 1);
547
548   tab_text (t, 0, 0, TAB_CENTER | TAT_TITLE, _("Source"));
549
550   /* TRANSLATORS: The parameter is a roman numeral */
551   tab_text_format (t, 1, 0, TAB_CENTER | TAT_TITLE,
552                    _("Type %s Sum of Squares"), "III");
553   tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df"));
554   tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
555   tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("F"));
556   tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("Sig."));
557
558   moments_calculate (ws->totals, &n_total, &mean, NULL, NULL, NULL);
559
560   if (cmd->intercept)
561     df_corr += 1.0;
562
563   df_corr += categoricals_df_total (ws->cats);
564
565   mse = gsl_vector_get (ws->ssq, 0) / (n_total - df_corr);
566
567   r = heading_rows;
568   tab_text (t, 0, r, TAB_LEFT | TAT_TITLE, _("Corrected Model"));
569
570   r++;
571
572   if (cmd->intercept)
573     {
574       const double intercept = pow2 (mean * n_total) / n_total;
575       const double df = 1.0;
576       const double F = intercept / df / mse;
577       tab_text (t, 0, r, TAB_LEFT | TAT_TITLE, _("Intercept"));
578       tab_double (t, 1, r, 0, intercept, NULL);
579       tab_double (t, 2, r, 0, 1.00, wfmt);
580       tab_double (t, 3, r, 0, intercept / df, NULL);
581       tab_double (t, 4, r, 0, F, NULL);
582       tab_double (t, 5, r, 0, gsl_cdf_fdist_Q (F, df, n_total - df_corr),
583                   NULL);
584       r++;
585     }
586
587   for (f = 0; f < cmd->n_interactions; ++f)
588     {
589       struct string str = DS_EMPTY_INITIALIZER;
590       const double df = categoricals_df (ws->cats, f);
591       const double ssq = gsl_vector_get (ws->ssq, f + 1);
592       const double F = ssq / df / mse;
593       interaction_to_string (cmd->interactions[f], &str);
594       tab_text (t, 0, r, TAB_LEFT | TAT_TITLE, ds_cstr (&str));
595       ds_destroy (&str);
596
597       tab_double (t, 1, r, 0, ssq, NULL);
598       tab_double (t, 2, r, 0, df, wfmt);
599       tab_double (t, 3, r, 0, ssq / df, NULL);
600       tab_double (t, 4, r, 0, F, NULL);
601
602       tab_double (t, 5, r, 0, gsl_cdf_fdist_Q (F, df, n_total - df_corr),
603                   NULL);
604       r++;
605     }
606
607   {
608     /* Corrected Model */
609     const double df = df_corr - 1.0;
610     const double ssq = ws->total_ssq - gsl_vector_get (ws->ssq, 0);
611     const double F = ssq / df / mse;
612     tab_double (t, 1, heading_rows, 0, ssq, NULL);
613     tab_double (t, 2, heading_rows, 0, df, wfmt);
614     tab_double (t, 3, heading_rows, 0, ssq / df, NULL);
615     tab_double (t, 4, heading_rows, 0, F, NULL);
616
617     tab_double (t, 5, heading_rows, 0,
618                 gsl_cdf_fdist_Q (F, df, n_total - df_corr), NULL);
619   }
620
621   {
622     const double df = n_total - df_corr;
623     const double ssq = gsl_vector_get (ws->ssq, 0);
624     const double mse = ssq / df;
625     tab_text (t, 0, r, TAB_LEFT | TAT_TITLE, _("Error"));
626     tab_double (t, 1, r, 0, ssq, NULL);
627     tab_double (t, 2, r, 0, df, wfmt);
628     tab_double (t, 3, r++, 0, mse, NULL);
629   }
630
631   if (cmd->intercept)
632     {
633       const double intercept = pow2 (mean * n_total) / n_total;
634       const double ssq = intercept + ws->total_ssq;
635
636       tab_text (t, 0, r, TAB_LEFT | TAT_TITLE, _("Total"));
637       tab_double (t, 1, r, 0, ssq, NULL);
638       tab_double (t, 2, r, 0, n_total, wfmt);
639
640       r++;
641     }
642
643   tab_text (t, 0, r, TAB_LEFT | TAT_TITLE, _("Corrected Total"));
644
645
646   tab_double (t, 1, r, 0, ws->total_ssq, NULL);
647   tab_double (t, 2, r, 0, n_total - 1.0, wfmt);
648
649   tab_submit (t);
650 }
651
652 #if 0
653 static void
654 dump_matrix (const gsl_matrix * m)
655 {
656   size_t i, j;
657   for (i = 0; i < m->size1; ++i)
658     {
659       for (j = 0; j < m->size2; ++j)
660         {
661           double x = gsl_matrix_get (m, i, j);
662           printf ("%.3f ", x);
663         }
664       printf ("\n");
665     }
666   printf ("\n");
667 }
668 #endif
669
670
671 \f
672
673 /* Match a variable.
674    If the match succeeds, the variable will be placed in VAR.
675    Returns true if successful */
676 static bool
677 lex_match_variable (struct lexer *lexer, const struct glm_spec *glm, const struct variable **var)
678 {
679   if (lex_token (lexer) !=  T_ID)
680     return false;
681
682   *var = parse_variable_const  (lexer, glm->dict);
683
684   if ( *var == NULL)
685     return false;
686   return true;
687 }
688
689 /* An interaction is a variable followed by {*, BY} followed by an interaction */
690 static bool
691 parse_design_interaction (struct lexer *lexer, struct glm_spec *glm, struct interaction **iact)
692 {
693   const struct variable *v = NULL;
694   assert (iact);
695
696   switch  (lex_next_token (lexer, 1))
697     {
698     case T_ENDCMD:
699     case T_SLASH:
700     case T_COMMA:
701     case T_ID:
702     case T_BY:
703     case T_ASTERISK:
704       break;
705     default:
706       return false;
707       break;
708     }
709
710   if (! lex_match_variable (lexer, glm, &v))
711     {
712       interaction_destroy (*iact);
713       *iact = NULL;
714       return false;
715     }
716   
717   assert (v);
718
719   if ( *iact == NULL)
720     *iact = interaction_create (v);
721   else
722     interaction_add_variable (*iact, v);
723
724   if ( lex_match (lexer, T_ASTERISK) || lex_match (lexer, T_BY))
725     {
726       // lex_error (lexer, "Interactions are not yet implemented"); return false;
727       return parse_design_interaction (lexer, glm, iact);
728     }
729
730   return true;
731 }
732
733 static bool
734 parse_nested_variable (struct lexer *lexer, struct glm_spec *glm)
735 {
736   const struct variable *v = NULL;
737   if ( ! lex_match_variable (lexer, glm, &v))
738     return false;
739
740   if (lex_match (lexer, T_LPAREN))
741     {
742       if ( ! parse_nested_variable (lexer, glm))
743         return false;
744
745       if ( ! lex_force_match (lexer, T_RPAREN))
746         return false;
747     }
748
749   lex_error (lexer, "Nested variables are not yet implemented"); return false;  
750   return true;
751 }
752
753 /* A design term is an interaction OR a nested variable */
754 static bool
755 parse_design_term (struct lexer *lexer, struct glm_spec *glm)
756 {
757   struct interaction *iact = NULL;
758   if (parse_design_interaction (lexer, glm, &iact))
759     {
760       /* Interaction parsing successful.  Add to list of interactions */
761       glm->interactions = xrealloc (glm->interactions, sizeof *glm->interactions * ++glm->n_interactions);
762       glm->interactions[glm->n_interactions - 1] = iact;
763       return true;
764     }
765
766   if ( parse_nested_variable (lexer, glm))
767     return true;
768
769   return false;
770 }
771
772
773
774 /* Parse a complete DESIGN specification.
775    A design spec is a design term, optionally followed by a comma,
776    and another design spec.
777 */
778 static bool
779 parse_design_spec (struct lexer *lexer, struct glm_spec *glm)
780 {
781   if  (lex_token (lexer) == T_ENDCMD || lex_token (lexer) == T_SLASH)
782     return true;
783
784   if ( ! parse_design_term (lexer, glm))
785     return false;
786
787   lex_match (lexer, T_COMMA);
788
789   return parse_design_spec (lexer, glm);
790 }
791