Rewritten the t-test (no calculations yet).
[pspp-builds.git] / src / t-test.q
1 /* PSPP - computes sample statistics. -*-c-*-
2
3    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4    Written by John Williams <johnr.williams@stonebow.otago.ac.nz>.
5    Almost completly re-written by John Darrington 2004
6
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation; either version 2 of the
10    License, or (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20    02111-1307, USA. */
21
22 #include <config.h>
23 #include <assert.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <math.h>
27 #include "alloc.h"
28 #include "str.h"
29 #include "dcdflib/cdflib.h"
30 #include "command.h"
31 #include "lexer.h"
32 #include "error.h"
33 #include "magic.h"
34 #include "tab.h"
35 #include "som.h"
36 #include "value-labels.h"
37 #include "var.h"
38 #include "vfm.h"
39 #include "pool.h"
40
41 /* (specification)
42    "T-TEST" (tts_):
43      groups=custom;
44      testval=double;
45      variables=varlist("PV_NO_SCRATCH | PV_NUMERIC");
46      pairs=custom;
47      +missing=miss:!analysis/listwise,
48              incl:include/!exclude;
49      format=fmt:!labels/nolabels;
50      criteria=:cin(d:criteria,"%s > 0. && %s < 1.").
51 */
52 /* (declarations) */
53 /* (functions) */
54
55 static struct cmd_t_test cmd;
56
57
58 static struct pool *t_test_pool ;
59
60 /* Variable for the GROUPS subcommand, if given. */
61 static struct variable *groups;
62
63 /* GROUPS: Number of values specified by the user; the values
64    specified if any. */
65 static int n_groups_values;
66 static union value groups_values[2];
67
68 /* PAIRS: Number of pairs to be compared ; each pair. */
69 static int n_pairs ;
70 typedef struct variable *pair_t[2] ;
71 static pair_t *pairs;
72
73
74 static int parse_value (union value * v, int type) ;
75
76
77 /* Structures and Functions for the Statistics Summary Box */
78 struct ssbox;
79 typedef void populate_ssbox_func(struct ssbox *ssb,
80                                             struct cmd_t_test *cmd);
81 typedef void finalize_ssbox_func(struct ssbox *ssb);
82
83 struct ssbox
84 {
85   struct tab_table *t;
86
87   populate_ssbox_func *populate;
88   finalize_ssbox_func *finalize;
89
90 };
91
92 /* Create a ssbox */
93 void ssbox_create(struct ssbox *ssb,   struct cmd_t_test *cmd, int mode);
94
95 /* Populate a ssbox according to cmd */
96 void ssbox_populate(struct ssbox *ssb, struct cmd_t_test *cmd);
97
98 /* Submit and destroy a ssbox */
99 void ssbox_finalize(struct ssbox *ssb);
100
101
102
103 /* Structures and Functions for the Test Results Box */
104 struct trbox;
105
106 typedef void populate_trbox_func(struct trbox *trb,
107                                  struct cmd_t_test *cmd);
108 typedef void finalize_trbox_func(struct trbox *trb);
109
110 struct trbox {
111   struct tab_table *t;
112   populate_trbox_func *populate;
113   finalize_trbox_func *finalize;
114 };
115
116 /* Create a trbox */
117 void trbox_create(struct trbox *trb,   struct cmd_t_test *cmd, int mode);
118
119 /* Populate a ssbox according to cmd */
120 void trbox_populate(struct trbox *trb, struct cmd_t_test *cmd);
121
122 /* Submit and destroy a ssbox */
123 void trbox_finalize(struct trbox *trb);
124
125 /* Which mode was T-TEST invoked */
126 enum {
127   T_1_SAMPLE = 0 ,
128   T_IND_SAMPLES, 
129   T_PAIRED
130 };
131
132 int
133 cmd_t_test(void)
134 {
135   int mode;
136
137   struct ssbox stat_summary_box;
138   struct trbox test_results_box;
139
140   
141   if (!lex_force_match_id ("T"))
142     return CMD_FAILURE;
143
144   lex_match ('-');
145   lex_match_id ("TEST");
146
147   if ( !parse_t_test(&cmd) )
148     return CMD_FAILURE;
149
150
151   if (! cmd.sbc_criteria)
152     cmd.criteria=0.95;
153
154
155   if ( cmd.sbc_testval + cmd.sbc_groups + cmd.sbc_pairs != 1 ) 
156     {
157       msg(SE, 
158           _("Exactly one of TESTVAL, GROUPS or PAIRS subcommands is required")
159           );
160       return CMD_FAILURE;
161     }
162
163   if (cmd.sbc_testval) 
164     mode=T_1_SAMPLE;
165   else if (cmd.sbc_groups)
166     mode=T_IND_SAMPLES;
167   else
168     mode=T_PAIRED;
169
170   if ( mode == T_PAIRED && cmd.sbc_variables) 
171     {
172       msg(SE, _("VARIABLES subcommand is not appropriate with PAIRS"));
173       return CMD_FAILURE;
174     }
175
176
177
178   t_test_pool = pool_create ();
179
180   ssbox_create(&stat_summary_box,&cmd,mode);
181   trbox_create(&test_results_box,&cmd,mode);
182
183   ssbox_populate(&stat_summary_box,&cmd);
184   trbox_populate(&test_results_box,&cmd);
185
186   ssbox_finalize(&stat_summary_box);
187   trbox_finalize(&test_results_box);
188
189   pool_destroy (t_test_pool);
190
191   t_test_pool=0;
192
193     
194   return CMD_SUCCESS;
195 }
196
197
198 static int
199 tts_custom_groups (struct cmd_t_test *cmd unused)
200 {
201   lex_match('=');
202
203   if (token != T_ALL && 
204       (token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
205      ) 
206   {
207     msg(SE,_("`%s' is not a variable name"),tokid);
208     return 0;
209   }
210
211   groups = parse_variable ();
212   if (!groups)
213     {
214       lex_error ("expecting variable name in GROUPS subcommand");
215       return 0;
216     }
217
218   if (groups->type == T_STRING && groups->width > MAX_SHORT_STRING)
219     {
220       msg (SE, _("Long string variable %s is not valid here."),
221            groups->name);
222       return 0;
223     }
224
225   if (!lex_match ('('))
226     {
227
228       if (groups->type == NUMERIC)
229         {
230           n_groups_values = 2;
231           groups_values[0].f = 1;
232           groups_values[1].f = 2;
233           return 1;
234         }
235       else
236         {
237           msg (SE, _("When applying GROUPS to a string variable, at "
238                      "least one value must be specified."));
239           return 0;
240         }
241     }
242
243   if (!parse_value (&groups_values[0],groups->type))
244     return 0;
245   n_groups_values = 1;
246
247   lex_match (',');
248
249   if (lex_match (')'))
250     return 1;
251
252   if (!parse_value (&groups_values[1],groups->type))
253     return 0;
254   n_groups_values = 2;
255
256   if (!lex_force_match (')'))
257     return 0;
258
259   return 1;
260 }
261
262 static int
263 tts_custom_pairs (struct cmd_t_test *cmd unused)
264 {
265   struct variable **vars;
266   int n_vars;
267   int n_before_WITH ;
268   int n_after_WITH =-1;
269   int paired ; /* Was the PAIRED keyword given ? */
270
271   lex_match('=');
272
273   if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
274       && token != T_ALL)
275     {
276       msg(SE,_("`%s' is not a variable name"),tokid);
277       return 0;
278     }
279
280   n_vars=0;
281   if (!parse_variables (default_dict, &vars, &n_vars,
282                         PV_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH))
283     {
284       free (vars);
285       return 0;
286     }
287   
288   
289   assert (n_vars);
290
291   n_before_WITH=0;
292   if (lex_match (T_WITH))
293     {
294       n_before_WITH = n_vars;
295
296       if (!parse_variables (default_dict, &vars, &n_vars,
297                             PV_DUPLICATE | PV_APPEND
298                             | PV_NUMERIC | PV_NO_SCRATCH))
299         {
300           free (vars);
301           return 0;
302         }
303
304       n_after_WITH = n_vars - n_before_WITH;
305     }
306
307
308   paired = (lex_match ('(') && lex_match_id ("PAIRED") && lex_match (')'));
309
310   
311   /* Determine the number of pairs needed */
312
313   if (paired)
314     {
315       if (n_before_WITH != n_after_WITH)
316         {
317           free (vars);
318           msg (SE, _("PAIRED was specified but the number of variables "
319                      "preceding WITH (%d) did not match the number "
320                      "following (%d)."),
321                n_before_WITH, n_after_WITH );
322           return 0;
323         }
324
325       n_pairs=n_before_WITH;
326
327     }
328   else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */
329     {
330       n_pairs=n_before_WITH * n_after_WITH ;
331     }
332   else /* Neither WITH nor PAIRED keyword given */
333     {
334       if (n_vars < 2)
335         {
336           free (vars);
337           msg (SE, _("At least two variables must be specified "
338                      "on PAIRS."));
339           return 0;
340         }
341
342       /* how many ways can you pick 2 from n_vars ? */
343       n_pairs = n_vars * (n_vars -1 ) /2 ;
344     }
345
346   /* Allocate storage for the pairs */
347
348   pairs = xrealloc(pairs,sizeof(pair_t) *n_pairs);
349
350
351   /* Populate the pairs with the appropriate variables */
352   
353   if ( paired ) 
354     {
355       int i;
356
357       assert(n_pairs == n_vars/2);
358       for (i = 0; i < n_pairs ; ++i)
359         {
360           pairs[i][0] = vars[i];
361           pairs[i][1] = vars[i+n_pairs];
362         }
363     }
364   else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */
365     {
366       int i,j;
367       int p=0;
368
369       for(i=0 ; i < n_before_WITH ; ++i ) 
370         {
371           for(j=0 ; j < n_after_WITH ; ++j)
372             {
373               pairs[p][0] = vars[i];
374               pairs[p][1] = vars[j+n_before_WITH];
375               ++p;
376             }
377         }
378     }
379   else /* Neither WITH nor PAIRED given */
380     {
381       int i,j;
382       int p=0;
383       
384       for(i=0 ; i < n_vars ; ++i ) 
385         {
386           for(j=i+1 ; j < n_vars ; ++j)
387             {
388               pairs[p][0] = vars[i];
389               pairs[p][1] = vars[j];
390               ++p;
391             }
392         }
393     }
394
395   return 1;
396 }
397
398
399 /* Parses the current token (numeric or string, depending on type)
400     value v and returns success. */
401 static int
402 parse_value (union value * v, int type )
403 {
404   if (type == NUMERIC)
405     {
406       if (!lex_force_num ())
407         return 0;
408       v->f = tokval;
409     }
410   else
411     {
412       if (!lex_force_string ())
413         return 0;
414       strncpy (v->s, ds_value (&tokstr), ds_length (&tokstr));
415     }
416
417   lex_get ();
418
419   return 1;
420 }
421
422
423 /* *******************************************************************
424                               SSBOX Implementation
425
426    ***************************************************************** */
427
428
429
430 void ssbox_base_init(struct ssbox *this, int cols,int rows);
431
432 void ssbox_base_finalize(struct ssbox *ssb);
433
434 void ssbox_one_sample_init(struct ssbox *this, 
435                            struct cmd_t_test *cmd );
436
437 void ssbox_independent_samples_init(struct ssbox *this,
438                                     struct cmd_t_test *cmd);
439
440 void ssbox_paired_init(struct ssbox *this,
441                            struct cmd_t_test *cmd);
442
443 /* Factory to create an ssbox */
444 void 
445 ssbox_create(struct ssbox *ssb, struct cmd_t_test *cmd, int mode)
446 {
447
448     switch (mode) 
449       {
450       case T_1_SAMPLE:
451         ssbox_one_sample_init(ssb,cmd);
452         break;
453       case T_IND_SAMPLES:
454         ssbox_independent_samples_init(ssb,cmd);
455         break;
456       case T_PAIRED:
457         ssbox_paired_init(ssb,cmd);
458         break;
459       default:
460         assert(0);
461       }
462
463 }
464
465
466 void
467 ssbox_populate(struct ssbox *ssb,struct cmd_t_test *cmd)
468 {
469   ssb->populate(ssb,cmd);
470 }
471
472
473 void
474 ssbox_finalize(struct ssbox *ssb)
475 {
476   ssb->finalize(ssb);
477 }
478
479
480
481 void 
482 ssbox_base_finalize(struct ssbox *ssb)
483 {
484   tab_submit(ssb->t);
485 }
486
487
488 void 
489 ssbox_base_init(struct ssbox *this, int cols,int rows)
490 {
491   this->finalize = ssbox_base_finalize;
492   this->t = tab_create (cols, rows, 0);
493
494   tab_columns (this->t, SOM_COL_DOWN, 1);
495
496   tab_headers (this->t,0,0,1,0); 
497
498   tab_box (this->t, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, cols -1, rows -1 );
499
500   tab_hline(this->t, TAL_2,0,cols-1,1);
501
502   tab_dim (this->t, tab_natural_dimensions);
503
504 }
505
506
507
508 void  ssbox_one_sample_populate(struct ssbox *ssb,
509                               struct cmd_t_test *cmd);
510
511
512
513 void 
514 ssbox_one_sample_init(struct ssbox *this, 
515                            struct cmd_t_test *cmd )
516 {
517   const int hsize=5;
518   const int vsize=cmd->n_variables+1;
519
520   this->populate = ssbox_one_sample_populate;
521
522   ssbox_base_init(this, hsize,vsize);
523
524
525   tab_title (this->t, 0, _("One-Sample Statistics"));
526
527   tab_vline(this->t, TAL_2, 1,0,vsize);
528
529   tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, _("N"));
530   tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
531   tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
532   tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
533
534
535 }
536
537
538 void ssbox_independent_samples_populate(struct ssbox *ssb,
539                                         struct cmd_t_test *cmd);
540
541
542 void 
543 ssbox_independent_samples_init(struct ssbox *this, 
544         struct cmd_t_test *cmd)
545
546 {
547   int hsize=6;
548   int vsize = cmd->n_variables*2 +1;
549
550   this->populate = ssbox_independent_samples_populate;
551
552   ssbox_base_init(this, hsize,vsize);
553
554   tab_title (this->t, 0, _("Group Statistics"));
555
556   tab_vline(this->t,0,1,0,vsize);
557
558   tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, groups->name);
559
560   tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("N"));
561   tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
562   tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
563   tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
564
565
566 }
567
568
569 void 
570 ssbox_independent_samples_populate(struct ssbox *ssb,
571                               struct cmd_t_test *cmd)
572 {
573   int i;
574
575   char *val_lab1=0;
576   char *val_lab2=0;
577
578   if ( groups->type == NUMERIC ) 
579     {
580       val_lab1 = val_labs_find( groups->val_labs,groups_values[0]); 
581       val_lab2 = val_labs_find( groups->val_labs,groups_values[1]);
582     }
583   else
584     {
585       val_lab1 = groups_values[0].s;
586       val_lab2 = groups_values[1].s;
587     }
588
589
590   assert(ssb->t);
591
592   for (i=0; i < cmd->n_variables; ++i)
593     {
594       tab_text (ssb->t, 0, i*2+1, 
595                 TAB_LEFT, cmd->v_variables[i]->name);
596
597       if (val_lab1)
598         tab_text (ssb->t, 1, i*2+1,
599                 TAB_LEFT, val_lab1);
600       else
601         tab_float(ssb->t, 1 ,i*2+1,
602                   TAB_LEFT, groups_values[0].f, 2,0);
603
604
605       if (val_lab2)
606         tab_text (ssb->t, 1, i*2+1+1,
607                   TAB_LEFT, val_lab2);
608       else
609         tab_float(ssb->t, 1 ,i*2+1+1,
610                   TAB_LEFT, groups_values[1].f,2,0);
611
612
613     }
614
615 }
616
617
618 void ssbox_paired_populate(struct ssbox *ssb,
619                            struct cmd_t_test *cmd);
620
621
622 void 
623 ssbox_paired_init(struct ssbox *this, 
624                            struct cmd_t_test *cmd unused)
625 {
626   int hsize=6;
627
628   int vsize = n_pairs*2+1;
629
630   this->populate = ssbox_paired_populate;
631
632   ssbox_base_init(this, hsize,vsize);
633
634   tab_title (this->t, 0, _("Paired Sample Statistics"));
635
636   tab_vline(this->t,TAL_0,1,0,vsize-1);
637   tab_vline(this->t,TAL_2,2,0,vsize-1);
638
639   tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
640   tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("N"));
641   tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
642   tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
643
644
645 }
646
647
648 void 
649 ssbox_paired_populate(struct ssbox *ssb,
650                               struct cmd_t_test *cmd unused)
651 {
652   int i;
653   struct string ds;
654
655   assert(ssb->t);
656
657   ds_init(t_test_pool,&ds,15);
658
659
660   for (i=0; i < n_pairs; ++i)
661     {
662
663       ds_clear(&ds);
664
665       ds_printf(&ds,_("Pair %d"),i);
666
667       tab_text (ssb->t, 0, i*2+1, TAB_LEFT, ds.string);
668
669       tab_text (ssb->t, 1, i*2+1, TAB_LEFT, pairs[i][0]->name);
670       tab_text (ssb->t, 1, i*2+2, TAB_LEFT, pairs[i][1]->name);
671     }
672
673   ds_destroy(&ds);
674 }
675
676
677 void 
678 ssbox_one_sample_populate(struct ssbox *ssb,
679                               struct cmd_t_test *cmd)
680 {
681   int i;
682
683   assert(ssb->t);
684
685   for (i=0; i < cmd->n_variables; ++i)
686     {
687       tab_text (ssb->t, 0, i+1, 
688                 TAB_LEFT, cmd->v_variables[i]->name);
689     }
690   
691 }
692
693
694 /* ****************************************************************
695
696       TEST RESULT BOX Implementation
697
698    *****************************************************************/   
699
700 void trbox_base_init(struct trbox *self,int n_vars, int cols);
701 void trbox_base_finalize(struct trbox *trb);
702
703 void trbox_independent_samples_init(struct trbox *trb,
704                                     struct cmd_t_test *cmd );
705
706 void trbox_independent_samples_populate(struct trbox *trb,
707                                         struct cmd_t_test *cmd);
708
709 void trbox_one_sample_init(struct trbox *self,
710                       struct cmd_t_test *cmd );
711
712 void trbox_one_sample_populate(struct trbox *trb,
713                                struct cmd_t_test *cmd);
714
715 void trbox_paired_init(struct trbox *self,
716                        struct cmd_t_test *cmd );
717
718 void trbox_paired_populate(struct trbox *trb,
719                       struct cmd_t_test *cmd);
720
721
722
723 /* Create a trbox */
724 void 
725 trbox_create(struct trbox *trb,   
726              struct cmd_t_test *cmd, int mode)
727 {
728
729     switch (mode) 
730       {
731       case T_1_SAMPLE:
732         trbox_one_sample_init(trb,cmd);
733         break;
734
735
736       case T_IND_SAMPLES:
737         trbox_independent_samples_init(trb,cmd);
738         break;
739
740
741       case T_PAIRED:
742         trbox_paired_init(trb,cmd);
743         break;
744         
745       default:
746         assert(0);
747       }
748
749 }
750
751 /* Populate a trbox according to cmd */
752 void 
753 trbox_populate(struct trbox *trb, struct cmd_t_test *cmd)
754 {
755   trb->populate(trb,cmd);
756 }
757
758 /* Submit and destroy a trbox */
759 void 
760 trbox_finalize(struct trbox *trb)
761 {
762   trb->finalize(trb);
763 }
764
765
766 void 
767 trbox_independent_samples_init(struct trbox *self,
768                            struct cmd_t_test *cmd unused)
769 {
770   const int hsize=11;
771   const int vsize=cmd->n_variables*2+3;
772
773   struct string ds;
774
775   assert(self);
776
777   self->populate = trbox_independent_samples_populate;
778
779   trbox_base_init(self,cmd->n_variables*2,hsize);
780
781   tab_title(self->t,0,_("Independent Samples Test"));
782
783   tab_hline(self->t,TAL_1,2,hsize-1,1);
784   tab_vline(self->t,TAL_2,2,0,vsize-1);
785
786   tab_vline(self->t,TAL_1,4,0,vsize-1);
787
788   tab_box(self->t,-1,-1,-1,TAL_1,
789           2,1,hsize-2,vsize-1);
790
791
792   tab_hline(self->t,TAL_1,
793             hsize-2,hsize-1,2);
794
795   tab_box(self->t,-1,-1,-1,TAL_1,
796           hsize-2,2,hsize-1,vsize-1);
797
798
799   tab_joint_text(self->t, 2,0,3,0,
800                  TAB_CENTER,_("Levine's Test for Equality of Variances"));
801
802   tab_joint_text(self->t, 4,0,hsize-1,0,
803                  TAB_CENTER,_("t-test for Equality of Means"));
804
805
806   tab_text(self->t,2,2, TAB_CENTER | TAT_TITLE,_("F"));
807   tab_text(self->t,3,2, TAB_CENTER | TAT_TITLE,_("Sig."));
808   tab_text(self->t,4,2, TAB_CENTER | TAT_TITLE,_("t"));
809   tab_text(self->t,5,2, TAB_CENTER | TAT_TITLE,_("df"));
810   tab_text(self->t,6,2, TAB_CENTER | TAT_TITLE,_("Sig. (2-tailed)"));
811   tab_text(self->t,7,2, TAB_CENTER | TAT_TITLE,_("Mean Difference"));
812   tab_text(self->t,8,2, TAB_CENTER | TAT_TITLE,_("Std. Error Difference"));
813   tab_text(self->t,9,2, TAB_CENTER | TAT_TITLE,_("Lower"));
814   tab_text(self->t,10,2, TAB_CENTER | TAT_TITLE,_("Upper"));
815
816
817   ds_init(t_test_pool,&ds,80);
818                 
819   ds_printf(&ds,_("%d%% Confidence Interval of the Difference"),
820             (int)round(cmd->criteria*100.0));
821
822   tab_joint_text(self->t,9,1,10,1,TAB_CENTER,
823                  ds.string);
824
825
826   ds_destroy(&ds);
827
828
829
830 }
831
832 void 
833 trbox_independent_samples_populate(struct trbox *self,
834                            struct cmd_t_test *cmd )
835 {
836   int i;
837
838   assert(self);
839
840   for (i=0; i < cmd->n_variables; ++i)
841     {
842       tab_text (self->t, 0, i*2+3, 
843                 TAB_LEFT, cmd->v_variables[i]->name);
844
845       tab_text (self->t, 1, i*2+3, 
846                 TAB_LEFT, _("Equal variances assumed"));
847
848       tab_text (self->t, 1, i*2+3+1, 
849                 TAB_LEFT, _("Equal variances not assumed"));
850
851
852     }
853
854 }
855
856
857 void 
858 trbox_paired_init(struct trbox *self,
859                            struct cmd_t_test *cmd unused)
860 {
861
862   const int hsize=10;
863   const int vsize=n_pairs*2+3;
864
865   struct string ds;
866
867   self->populate = trbox_paired_populate;
868
869   trbox_base_init(self,n_pairs*2,hsize);
870
871
872   tab_title (self->t, 0, _("Paired Samples Test"));
873
874
875   tab_hline(self->t,TAL_1,2,6,1);
876   tab_vline(self->t,TAL_2,2,0,vsize);
877
878
879
880   tab_joint_text(self->t,2,0,6,0,TAB_CENTER,_("Paired Differences"));
881
882
883   tab_box(self->t,-1,-1,-1,TAL_1,
884           2,1,6,vsize-1);
885
886
887   tab_box(self->t,-1,-1,-1,TAL_1,
888           6,0,hsize-1,vsize-1);
889
890
891
892   tab_hline(self->t,TAL_1,5,6, 2);
893   tab_vline(self->t,TAL_0,6,0,1);
894
895
896   ds_init(t_test_pool,&ds,80);
897                 
898   ds_printf(&ds,_("%d%% Confidence Interval of the Difference"),
899             (int)round(cmd->criteria*100.0));
900
901   tab_joint_text(self->t,5,1,6,1,TAB_CENTER,
902                  ds.string);
903
904
905   ds_destroy(&ds);
906
907   tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("Mean"));
908   tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
909   tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Std. Error Mean"));
910   tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
911   tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
912   tab_text (self->t, 7, 2, TAB_CENTER | TAT_TITLE, _("t"));
913   tab_text (self->t, 8, 2, TAB_CENTER | TAT_TITLE, _("df"));
914   tab_text (self->t, 9, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
915
916
917
918
919   
920
921
922 }
923
924
925 void 
926 trbox_paired_populate(struct trbox *trb,
927                               struct cmd_t_test *cmd unused)
928 {
929   int i;
930   struct string ds;
931
932
933   ds_init(t_test_pool,&ds,15);  
934
935   for (i=0; i < n_pairs; ++i)
936     {
937
938       ds_clear(&ds);
939
940       ds_printf(&ds,_("Pair %d"),i);
941
942       tab_text (trb->t, 0, i*2+3, TAB_LEFT, ds.string);
943
944       tab_text (trb->t, 1, i*2+3, TAB_LEFT, pairs[i][0]->name);
945       tab_text (trb->t, 1, i*2+4, TAB_LEFT, pairs[i][1]->name);
946     }
947
948
949   ds_destroy(&ds);
950
951 }
952
953
954 void 
955 trbox_one_sample_init(struct trbox *self,
956                            struct cmd_t_test *cmd )
957 {
958   const int hsize=7;
959   const int vsize=cmd->n_variables+3;
960
961   struct string ds;
962   
963   self->populate = trbox_one_sample_populate;
964
965   trbox_base_init(self,cmd->n_variables,hsize);
966
967
968   tab_title (self->t, 0, _("One-Sample Test"));
969
970   tab_hline(self->t,TAL_1,1,hsize-1,1);
971   tab_vline(self->t,TAL_2,1,0,vsize);
972
973   ds_init(t_test_pool,&ds,80);
974
975   ds_printf(&ds,_("Test Value = %f"),cmd->n_testval);
976
977   tab_joint_text(self->t,1,0,hsize-1,0,TAB_CENTER,ds.string);
978   
979   tab_box(self->t,-1,-1,-1,TAL_1,
980           1,1,hsize-1,vsize-1);
981
982
983   ds_clear(&ds);
984                 
985   ds_printf(&ds,_("%d%% Confidence Interval of the Difference"),
986             (int)round(cmd->criteria*100.0));
987
988   tab_joint_text(self->t,5,1,6,1,TAB_CENTER,
989                  ds.string);
990
991   ds_destroy(&ds);
992
993   tab_vline(self->t,TAL_0,6,1,1);
994   tab_hline(self->t,TAL_1,5,6,2);
995
996
997   tab_text (self->t, 1, 2, TAB_CENTER | TAT_TITLE, _("t"));
998   tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("df"));
999   tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
1000   tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Mean Difference"));
1001   tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
1002   tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
1003
1004
1005 }
1006
1007
1008
1009 void 
1010 trbox_one_sample_populate(struct trbox *trb,
1011                               struct cmd_t_test *cmd)
1012 {
1013   int i;
1014
1015   assert(trb->t);
1016
1017   for (i=0; i < cmd->n_variables; ++i)
1018     {
1019       tab_text (trb->t, 0, i+3, 
1020                 TAB_LEFT, cmd->v_variables[i]->name);
1021     }
1022   
1023 }
1024
1025
1026 void 
1027 trbox_base_init(struct trbox *self, int data_rows,int cols)
1028 {
1029   const int rows=3+data_rows;
1030
1031   self->finalize = trbox_base_finalize;
1032   self->t = tab_create (cols, rows, 0);
1033
1034
1035   tab_headers (self->t,0,0,3,0); 
1036
1037
1038   tab_box (self->t, TAL_2, TAL_2, TAL_0, TAL_0, 0, 0, cols -1, rows -1);
1039
1040   tab_hline(self->t, TAL_2,0,cols-1,3);
1041
1042   tab_dim (self->t, tab_natural_dimensions);
1043
1044 }
1045
1046
1047 void 
1048 trbox_base_finalize(struct trbox *trb)
1049 {
1050   tab_submit(trb->t);
1051 }