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