Implemented the reliability command.
[pspp-builds.git] / src / language / stats / reliability.q
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2008 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 "xalloc.h"
20 #include "xmalloca.h"
21
22 #include "gettext.h"
23 #define _(msgid) gettext (msgid)
24 #define N_(msgid) msgid
25
26 #include <data/variable.h>
27 #include <data/dictionary.h>
28 #include <data/procedure.h>
29 #include <data/casereader.h>
30 #include <data/casegrouper.h>
31 #include <math/moments.h>
32 #include <data/case.h>
33
34 #include <language/command.h>
35
36 #include <output/manager.h>
37 #include <output/table.h>
38
39 /* (headers) */
40
41 /* (specification)
42    reliability (rel_):
43      *^variables=varlist("PV_NO_SCRATCH | PV_NUMERIC");
44      scale=custom;
45      missing=miss:!exclude/include;
46      model=custom;
47      method=covariance;
48      +summary[sum_]=total.
49 */
50 /* (declarations) */
51 /* (functions) */
52
53
54 static int rel_custom_scale (struct lexer *lexer, struct dataset *ds,
55                       struct cmd_reliability *p, void *aux);
56
57 static int rel_custom_model (struct lexer *, struct dataset *,
58                              struct cmd_reliability *, void *);
59
60 int cmd_reliability (struct lexer *lexer, struct dataset *ds);
61
62 struct cronbach
63 {
64   const struct variable **items;
65   size_t n_items;
66   double alpha;
67   double sum_of_variances;
68   double variance_of_sums;
69   int totals_idx;          /* Casereader index into the totals */
70
71   struct moments1 **m ;    /* Moments of the items */
72   struct moments1 *total ; /* Moments of the totals */
73 };
74
75 #if 0
76 static void
77 dump_cronbach (const struct cronbach *s)
78 {
79   int i;
80   printf ("N items %d\n", s->n_items);
81   for (i = 0 ; i < s->n_items; ++i)
82     {
83       printf ("%s\n", var_get_name (s->items[i]));
84     }
85
86   printf ("Totals idx %d\n", s->totals_idx);
87
88   printf ("scale variance %g\n", s->variance_of_sums);
89   printf ("alpha %g\n", s->alpha);
90   putchar ('\n');
91 }
92 #endif
93
94 enum model
95   {
96     MODEL_ALPHA,
97     MODEL_SPLIT
98   };
99
100
101 struct reliability
102 {
103   const struct variable **variables;
104   int n_variables;
105   enum mv_class exclude;
106
107   struct cronbach *sc;
108   int n_sc;
109
110   int total_start;
111
112   struct string scale_name;
113
114   enum model model;
115   int split_point;
116 };
117
118
119 static double
120 alpha (int k, double sum_of_variances, double variance_of_sums)
121 {
122   return k / ( k - 1.0) * ( 1 - sum_of_variances / variance_of_sums);
123 }
124
125 static void reliability_summary_total (const struct reliability *rel);
126
127 static void reliability_statistics (const struct reliability *rel);
128
129
130
131 static void
132 run_reliability (struct casereader *group, struct dataset *ds,
133                  struct reliability *rel);
134
135
136 int
137 cmd_reliability (struct lexer *lexer, struct dataset *ds)
138 {
139   int i;
140   bool ok = false;
141   struct casegrouper *grouper;
142   struct casereader *group;
143   struct cmd_reliability cmd;
144
145   struct reliability rel = {
146     NULL, 0, MV_ANY, NULL, 0, -1,
147     DS_EMPTY_INITIALIZER,
148     MODEL_ALPHA, 0};
149
150   cmd.v_variables = NULL;
151
152   if ( ! parse_reliability (lexer, ds, &cmd, &rel) )
153     {
154       goto done;
155     }
156
157   rel.variables = cmd.v_variables;
158   rel.n_variables = cmd.n_variables;
159   rel.exclude = MV_ANY;
160
161
162   if (NULL == rel.sc)
163     {
164       struct cronbach *c;
165       /* Create a default Scale */
166
167       rel.n_sc = 1;
168       rel.sc = xzalloc (sizeof (struct cronbach) * rel.n_sc);
169
170       ds_init_cstr (&rel.scale_name, "ANY");
171
172       c = &rel.sc[0];
173       c->n_items = cmd.n_variables;
174       c->items = xzalloc (sizeof (struct variable*) * c->n_items);
175
176       for (i = 0 ; i < c->n_items ; ++i)
177         c->items[i] = cmd.v_variables[i];
178     }
179
180   if ( cmd.miss == REL_INCLUDE)
181     rel.exclude = MV_SYSTEM;
182
183   if ( rel.model == MODEL_SPLIT)
184     {
185       int i;
186       const struct cronbach *s;
187
188       rel.n_sc += 2 ;
189       rel.sc = xrealloc (rel.sc, sizeof (struct cronbach) * rel.n_sc);
190
191       s = &rel.sc[0];
192
193       rel.sc[1].n_items =
194         (rel.split_point == -1) ? s->n_items / 2 : rel.split_point;
195
196       rel.sc[2].n_items = s->n_items - rel.sc[1].n_items;
197       rel.sc[1].items = xzalloc (sizeof (struct variable *)
198                                  * rel.sc[1].n_items);
199
200       rel.sc[2].items = xzalloc (sizeof (struct variable *) *
201                                  rel.sc[2].n_items);
202
203       for  (i = 0; i < rel.sc[1].n_items ; ++i)
204         rel.sc[1].items[i] = s->items[i];
205
206       while (i < s->n_items)
207         {
208           rel.sc[2].items[i - rel.sc[1].n_items] = s->items[i];
209           i++;
210         }
211     }
212
213   if (cmd.a_summary[REL_SUM_TOTAL])
214     {
215       int i;
216       const int base_sc = rel.n_sc;
217
218       rel.total_start = base_sc;
219
220       rel.n_sc +=  rel.sc[0].n_items ;
221       rel.sc = xrealloc (rel.sc, sizeof (struct cronbach) * rel.n_sc);
222
223       for (i = 0 ; i < rel.sc[0].n_items; ++i )
224         {
225           int v_src;
226           int v_dest = 0;
227           struct cronbach *s = &rel.sc[i + base_sc];
228
229           s->n_items = rel.sc[0].n_items - 1;
230           s->items = xzalloc (sizeof (struct variable *) * s->n_items);
231           for (v_src = 0 ; v_src < rel.sc[0].n_items ; ++v_src)
232             {
233               if ( v_src != i)
234                 s->items[v_dest++] = rel.sc[0].items[v_src];
235             }
236         }
237     }
238
239   /* Data pass. */
240   grouper = casegrouper_create_splits (proc_open (ds), dataset_dict (ds));
241   while (casegrouper_get_next_group (grouper, &group))
242     {
243       run_reliability (group, ds, &rel);
244
245       reliability_statistics (&rel);
246
247       if (cmd.a_summary[REL_SUM_TOTAL])
248         reliability_summary_total (&rel);
249     }
250   ok = casegrouper_destroy (grouper);
251   ok = proc_commit (ds) && ok;
252
253   free_reliability (&cmd);
254
255  done:
256
257   /* Free all the stuff */
258   for (i = 0 ; i < rel.n_sc; ++i)
259     {
260       int x;
261       struct cronbach *c = &rel.sc[i];
262       free (c->items);
263
264       moments1_destroy (c->total);
265       for (x = 0 ; x < c->n_items; ++x)
266         moments1_destroy (c->m[x]);
267       free (c->m);
268     }
269
270   ds_destroy (&rel.scale_name);
271   free (rel.sc);
272
273   if (ok)
274     return CMD_SUCCESS;
275
276   return CMD_FAILURE;
277 }
278
279 /* Return the sum of all the item variables in S */
280 static  double
281 append_sum (const struct ccase *c, casenumber n UNUSED, void *aux)
282 {
283   double sum = 0;
284   const struct cronbach *s = aux;
285
286   int v;
287   for (v = 0 ; v < s->n_items; ++v)
288     {
289       sum += case_data (c, s->items[v])->f;
290     }
291
292   return sum;
293 };
294
295
296 static void case_processing_summary (casenumber n_valid, casenumber n_missing);
297
298 static void
299 run_reliability (struct casereader *input, struct dataset *ds UNUSED,
300                  struct reliability *rel)
301 {
302   int i;
303   int si;
304   struct ccase c;
305   casenumber n_missing ;
306   casenumber n_valid = 0;
307
308
309   for (si = 0 ; si < rel->n_sc; ++si)
310     {
311       struct cronbach *s = &rel->sc[si];
312
313       s->m = xzalloc (sizeof (s->m) * s->n_items);
314       s->total = moments1_create (MOMENT_VARIANCE);
315
316       for (i = 0 ; i < s->n_items ; ++i )
317         s->m[i] = moments1_create (MOMENT_VARIANCE);
318     }
319
320   input = casereader_create_filter_missing (input,
321                                             rel->variables,
322                                             rel->n_variables,
323                                             rel->exclude,
324                                             &n_missing,
325                                             NULL);
326
327   for (si = 0 ; si < rel->n_sc; ++si)
328     {
329       struct cronbach *s = &rel->sc[si];
330
331
332       s->totals_idx = casereader_get_value_cnt (input);
333       input =
334         casereader_create_append_numeric (input, append_sum,
335                                           s, NULL);
336     }
337
338   for (; casereader_read (input, &c); case_destroy (&c))
339     {
340       double weight = 1.0;
341       n_valid ++;
342
343       for (si = 0; si < rel->n_sc; ++si)
344         {
345           struct cronbach *s = &rel->sc[si];
346
347           for (i = 0 ; i < s->n_items ; ++i )
348             moments1_add (s->m[i], case_data (&c, s->items[i])->f, weight);
349
350           moments1_add (s->total, case_data_idx (&c, s->totals_idx)->f, weight);
351         }
352     }
353   casereader_destroy (input);
354
355   for (si = 0; si < rel->n_sc; ++si)
356     {
357       struct cronbach *s = &rel->sc[si];
358
359       s->sum_of_variances = 0;
360       for (i = 0 ; i < s->n_items ; ++i )
361         {
362           double weight, mean, variance;
363           moments1_calculate (s->m[i], &weight, &mean, &variance, NULL, NULL);
364
365           s->sum_of_variances += variance;
366         }
367
368       moments1_calculate (s->total, NULL, NULL, &s->variance_of_sums,
369                           NULL, NULL);
370
371       s->alpha =
372         alpha (s->n_items, s->sum_of_variances, s->variance_of_sums);
373     }
374
375
376   {
377     struct tab_table *tab = tab_create(1, 1, 0);
378
379     tab_dim (tab, tab_natural_dimensions);
380     tab_flags (tab, SOMF_NO_TITLE );
381
382     tab_text(tab, 0, 0, TAT_PRINTF, "Scale: %s", ds_cstr (&rel->scale_name));
383
384     tab_submit(tab);
385   }
386
387
388   case_processing_summary (n_valid, n_missing);
389 }
390
391
392 static void reliability_statistics_model_alpha (struct tab_table *tbl,
393                                                 const struct reliability *rel);
394
395 static void reliability_statistics_model_split (struct tab_table *tbl,
396                                                 const struct reliability *rel);
397
398 struct reliability_output_table
399 {
400   int n_cols;
401   int n_rows;
402   int heading_cols;
403   int heading_rows;
404   void (*populate)(struct tab_table *, const struct reliability *);
405 };
406
407 static struct reliability_output_table rol[2] =
408   {
409     { 2, 2, 1, 1, reliability_statistics_model_alpha},
410     { 4, 9, 3, 0, reliability_statistics_model_split}
411   };
412
413 static void
414 reliability_statistics (const struct reliability *rel)
415 {
416   int n_cols = rol[rel->model].n_cols;
417   int n_rows = rol[rel->model].n_rows;
418   int heading_columns = rol[rel->model].heading_cols;
419   int heading_rows = rol[rel->model].heading_rows;
420
421   struct tab_table *tbl = tab_create (n_cols, n_rows, 0);
422   tab_headers (tbl, heading_columns, 0, heading_rows, 0);
423
424   tab_dim (tbl, tab_natural_dimensions);
425
426   tab_title (tbl, _("Reliability Statistics"));
427
428   /* Vertical lines for the data only */
429   tab_box (tbl,
430            -1, -1,
431            -1, TAL_1,
432            heading_columns, 0,
433            n_cols - 1, n_rows - 1);
434
435   /* Box around table */
436   tab_box (tbl,
437            TAL_2, TAL_2,
438            -1, -1,
439            0, 0,
440            n_cols - 1, n_rows - 1);
441
442
443   tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows);
444
445   tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
446
447   if ( rel->model == MODEL_ALPHA )
448     reliability_statistics_model_alpha (tbl, rel);
449   else if (rel->model == MODEL_SPLIT )
450     reliability_statistics_model_split (tbl, rel);
451
452   tab_submit (tbl);
453 }
454
455 static void
456 reliability_summary_total (const struct reliability *rel)
457 {
458   int i;
459   const int n_cols = 5;
460   const int heading_columns = 1;
461   const int heading_rows = 1;
462   const int n_rows = rel->sc[0].n_items + heading_rows ;
463
464   struct tab_table *tbl = tab_create (n_cols, n_rows, 0);
465   tab_headers (tbl, heading_columns, 0, heading_rows, 0);
466
467   tab_dim (tbl, tab_natural_dimensions);
468
469   tab_title (tbl, _("Item-Total Statistics"));
470
471   /* Vertical lines for the data only */
472   tab_box (tbl,
473            -1, -1,
474            -1, TAL_1,
475            heading_columns, 0,
476            n_cols - 1, n_rows - 1);
477
478   /* Box around table */
479   tab_box (tbl,
480            TAL_2, TAL_2,
481            -1, -1,
482            0, 0,
483            n_cols - 1, n_rows - 1);
484
485
486   tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows);
487
488   tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
489
490   tab_text (tbl, 1, 0, TAB_CENTER | TAT_TITLE,
491             _("Scale Mean if Item Deleted"));
492
493   tab_text (tbl, 2, 0, TAB_CENTER | TAT_TITLE,
494             _("Scale Variance if Item Deleted"));
495
496   tab_text (tbl, 3, 0, TAB_CENTER | TAT_TITLE,
497             _("Corrected Item-Total Correlation"));
498
499   tab_text (tbl, 4, 0, TAB_CENTER | TAT_TITLE,
500             _("Cronbach's Alpha if Item Deleted"));
501
502
503   for (i = 0 ; i < rel->sc[0].n_items; ++i)
504     {
505       double cov, item_to_total_r;
506       double mean, weight, var;
507
508       const struct cronbach *s = &rel->sc[rel->total_start + i];
509       tab_text (tbl, 0, heading_rows + i, TAB_LEFT| TAT_TITLE,
510                 var_to_string (rel->sc[0].items[i]));
511
512       moments1_calculate (s->total, &weight, &mean, &var, 0, 0);
513
514       tab_float (tbl, 1, heading_rows + i, TAB_RIGHT,
515                  mean, 8, 3);
516
517       tab_float (tbl, 2, heading_rows + i, TAB_RIGHT,
518                  s->variance_of_sums, 8, 3);
519
520       tab_float (tbl, 4, heading_rows + i, TAB_RIGHT,
521                  s->alpha, 8, 3);
522
523
524       moments1_calculate (rel->sc[0].m[i], &weight, &mean, &var, 0,0);
525       cov = rel->sc[0].variance_of_sums + var - s->variance_of_sums;
526       cov /= 2.0;
527
528       item_to_total_r = (cov - var) / (sqrt(var) * sqrt (s->variance_of_sums));
529
530
531       tab_float (tbl, 3, heading_rows + i, TAB_RIGHT,
532                  item_to_total_r, 8, 3);
533     }
534
535
536   tab_submit (tbl);
537 }
538
539
540 static void
541 reliability_statistics_model_alpha (struct tab_table *tbl,
542                                     const struct reliability *rel)
543 {
544   const struct cronbach *s = &rel->sc[0];
545
546   tab_text (tbl, 0, 0, TAB_CENTER | TAT_TITLE,
547                 _("Cronbach's Alpha"));
548
549   tab_text (tbl, 1, 0, TAB_CENTER | TAT_TITLE,
550                 _("N of items"));
551
552   tab_float (tbl, 0, 1, TAB_RIGHT, s->alpha, 8, 3);
553
554   tab_float (tbl, 1, 1, TAB_RIGHT, s->n_items, 8, 0);
555 }
556
557
558 static void
559 reliability_statistics_model_split (struct tab_table *tbl,
560                                     const struct reliability *rel)
561 {
562   tab_text (tbl, 0, 0, TAB_LEFT,
563             _("Cronbach's Alpha"));
564
565   tab_text (tbl, 1, 0, TAB_LEFT,
566             _("Part 1"));
567
568   tab_text (tbl, 2, 0, TAB_LEFT,
569             _("Value"));
570
571   tab_text (tbl, 2, 1, TAB_LEFT,
572             _("N of Items"));
573
574
575
576   tab_text (tbl, 1, 2, TAB_LEFT,
577             _("Part 2"));
578
579   tab_text (tbl, 2, 2, TAB_LEFT,
580             _("Value"));
581
582   tab_text (tbl, 2, 3, TAB_LEFT,
583             _("N of Items"));
584
585
586
587   tab_text (tbl, 1, 4, TAB_LEFT,
588             _("Total N of Items"));
589
590   tab_text (tbl, 0, 5, TAB_LEFT,
591             _("Correlation Between Forms"));
592
593
594   tab_text (tbl, 0, 6, TAB_LEFT,
595             _("Spearman-Brown Coefficient"));
596
597   tab_text (tbl, 1, 6, TAB_LEFT,
598             _("Equal Length"));
599
600   tab_text (tbl, 1, 7, TAB_LEFT,
601             _("Unequal Length"));
602
603
604   tab_text (tbl, 0, 8, TAB_LEFT,
605             _("Guttman Split-Half Coefficient"));
606
607
608
609   tab_float (tbl, 3, 0, TAB_RIGHT, rel->sc[1].alpha, 8, 3);
610   tab_float (tbl, 3, 2, TAB_RIGHT, rel->sc[2].alpha, 8, 3);
611
612   tab_float (tbl, 3, 1, TAB_RIGHT, rel->sc[1].n_items, 8, 0);
613   tab_float (tbl, 3, 3, TAB_RIGHT, rel->sc[2].n_items, 8, 0);
614
615   tab_float (tbl, 3, 4, TAB_RIGHT,
616              rel->sc[1].n_items + rel->sc[2].n_items, 8, 0);
617
618   {
619     /* R is the correlation between the two parts */
620     double r = rel->sc[0].variance_of_sums -
621       rel->sc[1].variance_of_sums -
622       rel->sc[2].variance_of_sums ;
623
624     /* Guttman Split Half Coefficient */
625     double g = 2 * r / rel->sc[0].variance_of_sums;
626
627     /* Unequal Length Spearman Brown Coefficient, and
628      intermediate value used in the computation thereof */
629     double uly, tmp;
630
631     r /= sqrt (rel->sc[1].variance_of_sums);
632     r /= sqrt (rel->sc[2].variance_of_sums);
633     r /= 2.0;
634
635     tab_float (tbl, 3, 5, TAB_RIGHT, r, 8, 3);
636
637     /* Equal length Spearman-Brown Coefficient */
638     tab_float (tbl, 3, 6, TAB_RIGHT, 2 * r / (1.0 + r), 8, 3);
639
640     tab_float (tbl, 3, 8, TAB_RIGHT, g, 8, 3);
641
642     tmp = (1.0 - r*r) * rel->sc[1].n_items * rel->sc[2].n_items /
643       SQR (rel->sc[0].n_items);
644
645     uly = sqrt( SQR (SQR (r)) + 4 * SQR (r) * tmp);
646     uly -= SQR (r);
647     uly /= 2 * tmp;
648
649     tab_float (tbl, 3, 7, TAB_RIGHT, uly, 8, 3);
650
651   }
652 }
653
654
655
656 static void
657 case_processing_summary (casenumber n_valid, casenumber n_missing)
658 {
659   casenumber total;
660   int n_cols = 4;
661   int n_rows = 4;
662   int heading_columns = 2;
663   int heading_rows = 1;
664   struct tab_table *tbl;
665   tbl = tab_create (n_cols, n_rows, 0);
666   tab_headers (tbl, heading_columns, 0, heading_rows, 0);
667
668   tab_dim (tbl, tab_natural_dimensions);
669
670   tab_title (tbl, _("Case Processing Summary"));
671
672   /* Vertical lines for the data only */
673   tab_box (tbl,
674            -1, -1,
675            -1, TAL_1,
676            heading_columns, 0,
677            n_cols - 1, n_rows - 1);
678
679   /* Box around table */
680   tab_box (tbl,
681            TAL_2, TAL_2,
682            -1, -1,
683            0, 0,
684            n_cols - 1, n_rows - 1);
685
686
687   tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows);
688
689   tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
690
691
692   tab_text (tbl, 0, heading_rows, TAB_LEFT | TAT_TITLE,
693                 _("Cases"));
694
695   tab_text (tbl, 1, heading_rows, TAB_LEFT | TAT_TITLE,
696                 _("Valid"));
697
698   tab_text (tbl, 1, heading_rows + 1, TAB_LEFT | TAT_TITLE,
699                 _("Excluded"));
700
701   tab_text (tbl, 1, heading_rows + 2, TAB_LEFT | TAT_TITLE,
702                 _("Total"));
703
704   tab_text (tbl, heading_columns, 0, TAB_CENTER | TAT_TITLE,
705                 _("N"));
706
707   tab_text (tbl, heading_columns + 1, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF,
708                 _("%%"));
709
710   total = n_missing + n_valid;
711
712   tab_float (tbl, 2, heading_rows, TAB_RIGHT,
713              n_valid, 8, 0);
714
715
716   tab_float (tbl, 2, heading_rows + 1, TAB_RIGHT,
717              n_missing, 8, 0);
718
719
720   tab_float (tbl, 2, heading_rows + 2, TAB_RIGHT,
721              total, 8, 0);
722
723
724   tab_float (tbl, 3, heading_rows, TAB_RIGHT,
725              100 * n_valid / (double) total, 8, 1);
726
727
728   tab_float (tbl, 3, heading_rows + 1, TAB_RIGHT,
729              100 * n_missing / (double) total, 8, 1);
730
731
732   tab_float (tbl, 3, heading_rows + 2, TAB_RIGHT,
733              100 * total / (double) total, 8, 1);
734
735
736   tab_submit (tbl);
737 }
738
739 static int
740 rel_custom_model (struct lexer *lexer, struct dataset *ds UNUSED,
741                   struct cmd_reliability *cmd UNUSED, void *aux)
742 {
743   struct reliability *rel = aux;
744
745   if (lex_match_id (lexer, "ALPHA"))
746     {
747       rel->model = MODEL_ALPHA;
748     }
749   else if (lex_match_id (lexer, "SPLIT"))
750     {
751       rel->model = MODEL_SPLIT;
752       rel->split_point = -1;
753       if ( lex_match (lexer, '('))
754         {
755           lex_force_num (lexer);
756           rel->split_point = lex_number (lexer);
757           lex_get (lexer);
758           lex_force_match (lexer, ')');
759         }
760     }
761   else
762     return 0;
763
764   return 1;
765 }
766
767
768
769 static int
770 rel_custom_scale (struct lexer *lexer, struct dataset *ds UNUSED,
771                   struct cmd_reliability *p, void *aux)
772 {
773   struct const_var_set *vs;
774   struct reliability *rel = aux;
775   struct cronbach *scale;
776
777   rel->n_sc = 1;
778   rel->sc = xzalloc (sizeof (struct cronbach) * rel->n_sc);
779   scale = &rel->sc[0];
780
781   if ( ! lex_force_match (lexer, '(')) return 0;
782
783   if ( ! lex_force_string (lexer) ) return 0;
784
785   ds_init_string (&rel->scale_name, lex_tokstr (lexer));
786
787   lex_get (lexer);
788
789   if ( ! lex_force_match (lexer, ')')) return 0;
790
791   lex_match (lexer, '=');
792
793   vs = const_var_set_create_from_array (p->v_variables, p->n_variables);
794
795   if (!parse_const_var_set_vars (lexer, vs, &scale->items, &scale->n_items, 0))
796     {
797       const_var_set_destroy (vs);
798       return 2;
799     }
800
801   const_var_set_destroy (vs);
802   return 1;
803 }
804
805 /*
806    Local Variables:
807    mode: c
808    End:
809 */