Added a cell-padding parameter to the sheet.
[pspp-builds.git] / src / language / stats / reliability.q
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2008, 2009 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
266       if ( c->m)
267         for (x = 0 ; x < c->n_items; ++x)
268           moments1_destroy (c->m[x]);
269
270       free (c->m);
271     }
272
273   ds_destroy (&rel.scale_name);
274   free (rel.sc);
275
276   if (ok)
277     return CMD_SUCCESS;
278
279   return CMD_FAILURE;
280 }
281
282 /* Return the sum of all the item variables in S */
283 static  double
284 append_sum (const struct ccase *c, casenumber n UNUSED, void *aux)
285 {
286   double sum = 0;
287   const struct cronbach *s = aux;
288
289   int v;
290   for (v = 0 ; v < s->n_items; ++v)
291     {
292       sum += case_data (c, s->items[v])->f;
293     }
294
295   return sum;
296 };
297
298
299 static void case_processing_summary (casenumber n_valid, casenumber n_missing);
300
301 static void
302 run_reliability (struct casereader *input, struct dataset *ds UNUSED,
303                  struct reliability *rel)
304 {
305   int i;
306   int si;
307   struct ccase *c;
308   casenumber n_missing ;
309   casenumber n_valid = 0;
310
311
312   for (si = 0 ; si < rel->n_sc; ++si)
313     {
314       struct cronbach *s = &rel->sc[si];
315
316       s->m = xzalloc (sizeof (s->m) * s->n_items);
317       s->total = moments1_create (MOMENT_VARIANCE);
318
319       for (i = 0 ; i < s->n_items ; ++i )
320         s->m[i] = moments1_create (MOMENT_VARIANCE);
321     }
322
323   input = casereader_create_filter_missing (input,
324                                             rel->variables,
325                                             rel->n_variables,
326                                             rel->exclude,
327                                             &n_missing,
328                                             NULL);
329
330   for (si = 0 ; si < rel->n_sc; ++si)
331     {
332       struct cronbach *s = &rel->sc[si];
333
334
335       s->totals_idx = casereader_get_value_cnt (input);
336       input =
337         casereader_create_append_numeric (input, append_sum,
338                                           s, NULL);
339     }
340
341   for (; (c = casereader_read (input)) != NULL; case_unref (c))
342     {
343       double weight = 1.0;
344       n_valid ++;
345
346       for (si = 0; si < rel->n_sc; ++si)
347         {
348           struct cronbach *s = &rel->sc[si];
349
350           for (i = 0 ; i < s->n_items ; ++i )
351             moments1_add (s->m[i], case_data (c, s->items[i])->f, weight);
352
353           moments1_add (s->total, case_data_idx (c, s->totals_idx)->f, weight);
354         }
355     }
356   casereader_destroy (input);
357
358   for (si = 0; si < rel->n_sc; ++si)
359     {
360       struct cronbach *s = &rel->sc[si];
361
362       s->sum_of_variances = 0;
363       for (i = 0 ; i < s->n_items ; ++i )
364         {
365           double weight, mean, variance;
366           moments1_calculate (s->m[i], &weight, &mean, &variance, NULL, NULL);
367
368           s->sum_of_variances += variance;
369         }
370
371       moments1_calculate (s->total, NULL, NULL, &s->variance_of_sums,
372                           NULL, NULL);
373
374       s->alpha =
375         alpha (s->n_items, s->sum_of_variances, s->variance_of_sums);
376     }
377
378
379   {
380     struct tab_table *tab = tab_create(1, 1, 0);
381
382     tab_dim (tab, tab_natural_dimensions);
383     tab_flags (tab, SOMF_NO_TITLE );
384
385     tab_text(tab, 0, 0, TAT_PRINTF, "Scale: %s", ds_cstr (&rel->scale_name));
386
387     tab_submit(tab);
388   }
389
390
391   case_processing_summary (n_valid, n_missing);
392 }
393
394
395 static void reliability_statistics_model_alpha (struct tab_table *tbl,
396                                                 const struct reliability *rel);
397
398 static void reliability_statistics_model_split (struct tab_table *tbl,
399                                                 const struct reliability *rel);
400
401 struct reliability_output_table
402 {
403   int n_cols;
404   int n_rows;
405   int heading_cols;
406   int heading_rows;
407   void (*populate)(struct tab_table *, const struct reliability *);
408 };
409
410 static struct reliability_output_table rol[2] =
411   {
412     { 2, 2, 1, 1, reliability_statistics_model_alpha},
413     { 4, 9, 3, 0, reliability_statistics_model_split}
414   };
415
416 static void
417 reliability_statistics (const struct reliability *rel)
418 {
419   int n_cols = rol[rel->model].n_cols;
420   int n_rows = rol[rel->model].n_rows;
421   int heading_columns = rol[rel->model].heading_cols;
422   int heading_rows = rol[rel->model].heading_rows;
423
424   struct tab_table *tbl = tab_create (n_cols, n_rows, 0);
425   tab_headers (tbl, heading_columns, 0, heading_rows, 0);
426
427   tab_dim (tbl, tab_natural_dimensions);
428
429   tab_title (tbl, _("Reliability Statistics"));
430
431   /* Vertical lines for the data only */
432   tab_box (tbl,
433            -1, -1,
434            -1, TAL_1,
435            heading_columns, 0,
436            n_cols - 1, n_rows - 1);
437
438   /* Box around table */
439   tab_box (tbl,
440            TAL_2, TAL_2,
441            -1, -1,
442            0, 0,
443            n_cols - 1, n_rows - 1);
444
445
446   tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows);
447
448   tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
449
450   if ( rel->model == MODEL_ALPHA )
451     reliability_statistics_model_alpha (tbl, rel);
452   else if (rel->model == MODEL_SPLIT )
453     reliability_statistics_model_split (tbl, rel);
454
455   tab_submit (tbl);
456 }
457
458 static void
459 reliability_summary_total (const struct reliability *rel)
460 {
461   int i;
462   const int n_cols = 5;
463   const int heading_columns = 1;
464   const int heading_rows = 1;
465   const int n_rows = rel->sc[0].n_items + heading_rows ;
466
467   struct tab_table *tbl = tab_create (n_cols, n_rows, 0);
468   tab_headers (tbl, heading_columns, 0, heading_rows, 0);
469
470   tab_dim (tbl, tab_natural_dimensions);
471
472   tab_title (tbl, _("Item-Total Statistics"));
473
474   /* Vertical lines for the data only */
475   tab_box (tbl,
476            -1, -1,
477            -1, TAL_1,
478            heading_columns, 0,
479            n_cols - 1, n_rows - 1);
480
481   /* Box around table */
482   tab_box (tbl,
483            TAL_2, TAL_2,
484            -1, -1,
485            0, 0,
486            n_cols - 1, n_rows - 1);
487
488
489   tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows);
490
491   tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
492
493   tab_text (tbl, 1, 0, TAB_CENTER | TAT_TITLE,
494             _("Scale Mean if Item Deleted"));
495
496   tab_text (tbl, 2, 0, TAB_CENTER | TAT_TITLE,
497             _("Scale Variance if Item Deleted"));
498
499   tab_text (tbl, 3, 0, TAB_CENTER | TAT_TITLE,
500             _("Corrected Item-Total Correlation"));
501
502   tab_text (tbl, 4, 0, TAB_CENTER | TAT_TITLE,
503             _("Cronbach's Alpha if Item Deleted"));
504
505
506   for (i = 0 ; i < rel->sc[0].n_items; ++i)
507     {
508       double cov, item_to_total_r;
509       double mean, weight, var;
510
511       const struct cronbach *s = &rel->sc[rel->total_start + i];
512       tab_text (tbl, 0, heading_rows + i, TAB_LEFT| TAT_TITLE,
513                 var_to_string (rel->sc[0].items[i]));
514
515       moments1_calculate (s->total, &weight, &mean, &var, 0, 0);
516
517       tab_float (tbl, 1, heading_rows + i, TAB_RIGHT,
518                  mean, 8, 3);
519
520       tab_float (tbl, 2, heading_rows + i, TAB_RIGHT,
521                  s->variance_of_sums, 8, 3);
522
523       tab_float (tbl, 4, heading_rows + i, TAB_RIGHT,
524                  s->alpha, 8, 3);
525
526
527       moments1_calculate (rel->sc[0].m[i], &weight, &mean, &var, 0,0);
528       cov = rel->sc[0].variance_of_sums + var - s->variance_of_sums;
529       cov /= 2.0;
530
531       item_to_total_r = (cov - var) / (sqrt(var) * sqrt (s->variance_of_sums));
532
533
534       tab_float (tbl, 3, heading_rows + i, TAB_RIGHT,
535                  item_to_total_r, 8, 3);
536     }
537
538
539   tab_submit (tbl);
540 }
541
542
543 static void
544 reliability_statistics_model_alpha (struct tab_table *tbl,
545                                     const struct reliability *rel)
546 {
547   const struct cronbach *s = &rel->sc[0];
548
549   tab_text (tbl, 0, 0, TAB_CENTER | TAT_TITLE,
550                 _("Cronbach's Alpha"));
551
552   tab_text (tbl, 1, 0, TAB_CENTER | TAT_TITLE,
553                 _("N of items"));
554
555   tab_float (tbl, 0, 1, TAB_RIGHT, s->alpha, 8, 3);
556
557   tab_float (tbl, 1, 1, TAB_RIGHT, s->n_items, 8, 0);
558 }
559
560
561 static void
562 reliability_statistics_model_split (struct tab_table *tbl,
563                                     const struct reliability *rel)
564 {
565   tab_text (tbl, 0, 0, TAB_LEFT,
566             _("Cronbach's Alpha"));
567
568   tab_text (tbl, 1, 0, TAB_LEFT,
569             _("Part 1"));
570
571   tab_text (tbl, 2, 0, TAB_LEFT,
572             _("Value"));
573
574   tab_text (tbl, 2, 1, TAB_LEFT,
575             _("N of Items"));
576
577
578
579   tab_text (tbl, 1, 2, TAB_LEFT,
580             _("Part 2"));
581
582   tab_text (tbl, 2, 2, TAB_LEFT,
583             _("Value"));
584
585   tab_text (tbl, 2, 3, TAB_LEFT,
586             _("N of Items"));
587
588
589
590   tab_text (tbl, 1, 4, TAB_LEFT,
591             _("Total N of Items"));
592
593   tab_text (tbl, 0, 5, TAB_LEFT,
594             _("Correlation Between Forms"));
595
596
597   tab_text (tbl, 0, 6, TAB_LEFT,
598             _("Spearman-Brown Coefficient"));
599
600   tab_text (tbl, 1, 6, TAB_LEFT,
601             _("Equal Length"));
602
603   tab_text (tbl, 1, 7, TAB_LEFT,
604             _("Unequal Length"));
605
606
607   tab_text (tbl, 0, 8, TAB_LEFT,
608             _("Guttman Split-Half Coefficient"));
609
610
611
612   tab_float (tbl, 3, 0, TAB_RIGHT, rel->sc[1].alpha, 8, 3);
613   tab_float (tbl, 3, 2, TAB_RIGHT, rel->sc[2].alpha, 8, 3);
614
615   tab_float (tbl, 3, 1, TAB_RIGHT, rel->sc[1].n_items, 8, 0);
616   tab_float (tbl, 3, 3, TAB_RIGHT, rel->sc[2].n_items, 8, 0);
617
618   tab_float (tbl, 3, 4, TAB_RIGHT,
619              rel->sc[1].n_items + rel->sc[2].n_items, 8, 0);
620
621   {
622     /* R is the correlation between the two parts */
623     double r = rel->sc[0].variance_of_sums -
624       rel->sc[1].variance_of_sums -
625       rel->sc[2].variance_of_sums ;
626
627     /* Guttman Split Half Coefficient */
628     double g = 2 * r / rel->sc[0].variance_of_sums;
629
630     /* Unequal Length Spearman Brown Coefficient, and
631      intermediate value used in the computation thereof */
632     double uly, tmp;
633
634     r /= sqrt (rel->sc[1].variance_of_sums);
635     r /= sqrt (rel->sc[2].variance_of_sums);
636     r /= 2.0;
637
638     tab_float (tbl, 3, 5, TAB_RIGHT, r, 8, 3);
639
640     /* Equal length Spearman-Brown Coefficient */
641     tab_float (tbl, 3, 6, TAB_RIGHT, 2 * r / (1.0 + r), 8, 3);
642
643     tab_float (tbl, 3, 8, TAB_RIGHT, g, 8, 3);
644
645     tmp = (1.0 - r*r) * rel->sc[1].n_items * rel->sc[2].n_items /
646       pow2 (rel->sc[0].n_items);
647
648     uly = sqrt( pow4 (r) + 4 * pow2 (r) * tmp);
649     uly -= pow2 (r);
650     uly /= 2 * tmp;
651
652     tab_float (tbl, 3, 7, TAB_RIGHT, uly, 8, 3);
653
654   }
655 }
656
657
658
659 static void
660 case_processing_summary (casenumber n_valid, casenumber n_missing)
661 {
662   casenumber total;
663   int n_cols = 4;
664   int n_rows = 4;
665   int heading_columns = 2;
666   int heading_rows = 1;
667   struct tab_table *tbl;
668   tbl = tab_create (n_cols, n_rows, 0);
669   tab_headers (tbl, heading_columns, 0, heading_rows, 0);
670
671   tab_dim (tbl, tab_natural_dimensions);
672
673   tab_title (tbl, _("Case Processing Summary"));
674
675   /* Vertical lines for the data only */
676   tab_box (tbl,
677            -1, -1,
678            -1, TAL_1,
679            heading_columns, 0,
680            n_cols - 1, n_rows - 1);
681
682   /* Box around table */
683   tab_box (tbl,
684            TAL_2, TAL_2,
685            -1, -1,
686            0, 0,
687            n_cols - 1, n_rows - 1);
688
689
690   tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows);
691
692   tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
693
694
695   tab_text (tbl, 0, heading_rows, TAB_LEFT | TAT_TITLE,
696                 _("Cases"));
697
698   tab_text (tbl, 1, heading_rows, TAB_LEFT | TAT_TITLE,
699                 _("Valid"));
700
701   tab_text (tbl, 1, heading_rows + 1, TAB_LEFT | TAT_TITLE,
702                 _("Excluded"));
703
704   tab_text (tbl, 1, heading_rows + 2, TAB_LEFT | TAT_TITLE,
705                 _("Total"));
706
707   tab_text (tbl, heading_columns, 0, TAB_CENTER | TAT_TITLE,
708                 _("N"));
709
710   tab_text (tbl, heading_columns + 1, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF,
711                 _("%%"));
712
713   total = n_missing + n_valid;
714
715   tab_float (tbl, 2, heading_rows, TAB_RIGHT,
716              n_valid, 8, 0);
717
718
719   tab_float (tbl, 2, heading_rows + 1, TAB_RIGHT,
720              n_missing, 8, 0);
721
722
723   tab_float (tbl, 2, heading_rows + 2, TAB_RIGHT,
724              total, 8, 0);
725
726
727   tab_float (tbl, 3, heading_rows, TAB_RIGHT,
728              100 * n_valid / (double) total, 8, 1);
729
730
731   tab_float (tbl, 3, heading_rows + 1, TAB_RIGHT,
732              100 * n_missing / (double) total, 8, 1);
733
734
735   tab_float (tbl, 3, heading_rows + 2, TAB_RIGHT,
736              100 * total / (double) total, 8, 1);
737
738
739   tab_submit (tbl);
740 }
741
742 static int
743 rel_custom_model (struct lexer *lexer, struct dataset *ds UNUSED,
744                   struct cmd_reliability *cmd UNUSED, void *aux)
745 {
746   struct reliability *rel = aux;
747
748   if (lex_match_id (lexer, "ALPHA"))
749     {
750       rel->model = MODEL_ALPHA;
751     }
752   else if (lex_match_id (lexer, "SPLIT"))
753     {
754       rel->model = MODEL_SPLIT;
755       rel->split_point = -1;
756       if ( lex_match (lexer, '('))
757         {
758           lex_force_num (lexer);
759           rel->split_point = lex_number (lexer);
760           lex_get (lexer);
761           lex_force_match (lexer, ')');
762         }
763     }
764   else
765     return 0;
766
767   return 1;
768 }
769
770
771
772 static int
773 rel_custom_scale (struct lexer *lexer, struct dataset *ds UNUSED,
774                   struct cmd_reliability *p, void *aux)
775 {
776   struct const_var_set *vs;
777   struct reliability *rel = aux;
778   struct cronbach *scale;
779
780   rel->n_sc = 1;
781   rel->sc = xzalloc (sizeof (struct cronbach) * rel->n_sc);
782   scale = &rel->sc[0];
783
784   if ( ! lex_force_match (lexer, '(')) return 0;
785
786   if ( ! lex_force_string (lexer) ) return 0;
787
788   ds_init_string (&rel->scale_name, lex_tokstr (lexer));
789
790   lex_get (lexer);
791
792   if ( ! lex_force_match (lexer, ')')) return 0;
793
794   lex_match (lexer, '=');
795
796   vs = const_var_set_create_from_array (p->v_variables, p->n_variables);
797
798   if (!parse_const_var_set_vars (lexer, vs, &scale->items, &scale->n_items, 0))
799     {
800       const_var_set_destroy (vs);
801       return 2;
802     }
803
804   const_var_set_destroy (vs);
805   return 1;
806 }
807
808 /*
809    Local Variables:
810    mode: c
811    End:
812 */