1 /* PSPP - computes sample statistics. -*-c-*-
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
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.
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.
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
29 #include "dcdflib/cdflib.h"
36 #include "value-labels.h"
45 variables=varlist("PV_NO_SCRATCH | PV_NUMERIC");
47 +missing=miss:!analysis/listwise,
48 incl:include/!exclude;
49 format=fmt:!labels/nolabels;
50 criteria=:cin(d:criteria,"%s > 0. && %s < 1.").
55 static struct cmd_t_test cmd;
59 static struct pool *t_test_pool ;
61 /* Variable for the GROUPS subcommand, if given. */
62 static struct variable *groups;
64 /* GROUPS: Number of values specified by the user; the values
66 static int n_groups_values;
67 static union value groups_values[2];
69 /* PAIRS: Number of pairs to be compared ; each pair. */
71 typedef struct variable *pair_t[2] ;
75 static int parse_value (union value * v, int type) ;
78 /* Structures and Functions for the Statistics Summary Box */
80 typedef void populate_ssbox_func(struct ssbox *ssb,
81 struct cmd_t_test *cmd);
82 typedef void finalize_ssbox_func(struct ssbox *ssb);
88 populate_ssbox_func *populate;
89 finalize_ssbox_func *finalize;
94 void ssbox_create(struct ssbox *ssb, struct cmd_t_test *cmd, int mode);
96 /* Populate a ssbox according to cmd */
97 void ssbox_populate(struct ssbox *ssb, struct cmd_t_test *cmd);
99 /* Submit and destroy a ssbox */
100 void ssbox_finalize(struct ssbox *ssb);
104 /* Structures and Functions for the Test Results Box */
107 typedef void populate_trbox_func(struct trbox *trb,
108 struct cmd_t_test *cmd);
109 typedef void finalize_trbox_func(struct trbox *trb);
113 populate_trbox_func *populate;
114 finalize_trbox_func *finalize;
118 void trbox_create(struct trbox *trb, struct cmd_t_test *cmd, int mode);
120 /* Populate a ssbox according to cmd */
121 void trbox_populate(struct trbox *trb, struct cmd_t_test *cmd);
123 /* Submit and destroy a ssbox */
124 void trbox_finalize(struct trbox *trb);
126 /* Which mode was T-TEST invoked */
134 static int common_calc (struct ccase *);
135 static void common_precalc (void);
136 static void common_postcalc (void);
138 static int one_sample_calc (struct ccase *);
139 static void one_sample_precalc (void);
140 static void one_sample_postcalc (void);
148 struct ssbox stat_summary_box;
149 struct trbox test_results_box;
151 if (!lex_force_match_id ("T"))
155 lex_match_id ("TEST");
157 if ( !parse_t_test(&cmd) )
160 if (! cmd.sbc_criteria)
163 if ( cmd.sbc_testval + cmd.sbc_groups + cmd.sbc_pairs != 1 )
166 _("Exactly one of TESTVAL, GROUPS or PAIRS subcommands is required")
173 else if (cmd.sbc_groups)
178 if ( mode == T_PAIRED && cmd.sbc_variables)
180 msg(SE, _("VARIABLES subcommand is not appropriate with PAIRS"));
184 procedure(common_precalc,common_calc,common_postcalc);
186 if (mode == T_1_SAMPLE)
187 procedure(one_sample_precalc,one_sample_calc,one_sample_postcalc);
189 t_test_pool = pool_create ();
191 ssbox_create(&stat_summary_box,&cmd,mode);
192 trbox_create(&test_results_box,&cmd,mode);
194 ssbox_populate(&stat_summary_box,&cmd);
195 trbox_populate(&test_results_box,&cmd);
197 ssbox_finalize(&stat_summary_box);
198 trbox_finalize(&test_results_box);
200 pool_destroy (t_test_pool);
208 tts_custom_groups (struct cmd_t_test *cmd unused)
212 if (token != T_ALL &&
213 (token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
216 msg(SE,_("`%s' is not a variable name"),tokid);
220 groups = parse_variable ();
223 lex_error ("expecting variable name in GROUPS subcommand");
227 if (groups->type == T_STRING && groups->width > MAX_SHORT_STRING)
229 msg (SE, _("Long string variable %s is not valid here."),
234 if (!lex_match ('('))
236 if (groups->type == NUMERIC)
239 groups_values[0].f = 1;
240 groups_values[1].f = 2;
245 msg (SE, _("When applying GROUPS to a string variable, at "
246 "least one value must be specified."));
251 if (!parse_value (&groups_values[0],groups->type))
259 if (!parse_value (&groups_values[1],groups->type))
263 if (!lex_force_match (')'))
273 tts_custom_pairs (struct cmd_t_test *cmd unused)
275 struct variable **vars;
279 int n_after_WITH = -1;
280 int paired ; /* Was the PAIRED keyword given ? */
284 if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
287 msg(SE,_("`%s' is not a variable name"),tokid);
292 if (!parse_variables (default_dict, &vars, &n_vars,
293 PV_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH))
301 if (lex_match (T_WITH))
303 n_before_WITH = n_vars;
304 if (!parse_variables (default_dict, &vars, &n_vars,
305 PV_DUPLICATE | PV_APPEND
306 | PV_NUMERIC | PV_NO_SCRATCH))
311 n_after_WITH = n_vars - n_before_WITH;
314 paired = (lex_match ('(') && lex_match_id ("PAIRED") && lex_match (')'));
316 /* Determine the number of pairs needed */
319 if (n_before_WITH != n_after_WITH)
322 msg (SE, _("PAIRED was specified but the number of variables "
323 "preceding WITH (%d) did not match the number "
325 n_before_WITH, n_after_WITH );
328 n_pairs=n_before_WITH;
330 else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */
332 n_pairs=n_before_WITH * n_after_WITH ;
334 else /* Neither WITH nor PAIRED keyword given */
339 msg (SE, _("At least two variables must be specified "
344 /* how many ways can you pick 2 from n_vars ? */
345 n_pairs = n_vars * (n_vars -1 ) /2 ;
348 /* Allocate storage for the pairs */
349 pairs = xrealloc(pairs,sizeof(pair_t) *n_pairs);
351 /* Populate the pairs with the appropriate variables */
356 assert(n_pairs == n_vars/2);
357 for (i = 0; i < n_pairs ; ++i)
359 pairs[i][0] = vars[i];
360 pairs[i][1] = vars[i+n_pairs];
363 else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */
368 for(i=0 ; i < n_before_WITH ; ++i )
370 for(j=0 ; j < n_after_WITH ; ++j)
372 pairs[p][0] = vars[i];
373 pairs[p][1] = vars[j+n_before_WITH];
378 else /* Neither WITH nor PAIRED given */
383 for(i=0 ; i < n_vars ; ++i )
385 for(j=i+1 ; j < n_vars ; ++j)
387 pairs[p][0] = vars[i];
388 pairs[p][1] = vars[j];
397 /* Parses the current token (numeric or string, depending on type)
398 value v and returns success. */
400 parse_value (union value * v, int type )
404 if (!lex_force_num ())
410 if (!lex_force_string ())
412 strncpy (v->s, ds_value (&tokstr), ds_length (&tokstr));
421 /* Implementation of the SSBOX object */
423 void ssbox_base_init(struct ssbox *this, int cols,int rows);
425 void ssbox_base_finalize(struct ssbox *ssb);
427 void ssbox_one_sample_init(struct ssbox *this,
428 struct cmd_t_test *cmd );
430 void ssbox_independent_samples_init(struct ssbox *this,
431 struct cmd_t_test *cmd);
433 void ssbox_paired_init(struct ssbox *this,
434 struct cmd_t_test *cmd);
436 /* Factory to create an ssbox */
438 ssbox_create(struct ssbox *ssb, struct cmd_t_test *cmd, int mode)
443 ssbox_one_sample_init(ssb,cmd);
446 ssbox_independent_samples_init(ssb,cmd);
449 ssbox_paired_init(ssb,cmd);
457 /* Despatcher for the populate method */
459 ssbox_populate(struct ssbox *ssb,struct cmd_t_test *cmd)
461 ssb->populate(ssb,cmd);
465 /* Despatcher for finalize */
467 ssbox_finalize(struct ssbox *ssb)
473 /* Submit the box and clear up */
475 ssbox_base_finalize(struct ssbox *ssb)
480 /* Initialize a ssbox struct */
482 ssbox_base_init(struct ssbox *this, int cols,int rows)
484 this->finalize = ssbox_base_finalize;
485 this->t = tab_create (cols, rows, 0);
487 tab_columns (this->t, SOM_COL_DOWN, 1);
488 tab_headers (this->t,0,0,1,0);
489 tab_box (this->t, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, cols -1, rows -1 );
490 tab_hline(this->t, TAL_2,0,cols-1,1);
491 tab_dim (this->t, tab_natural_dimensions);
494 void ssbox_one_sample_populate(struct ssbox *ssb,
495 struct cmd_t_test *cmd);
497 /* Initialize the one_sample ssbox */
499 ssbox_one_sample_init(struct ssbox *this,
500 struct cmd_t_test *cmd )
503 const int vsize=cmd->n_variables+1;
505 this->populate = ssbox_one_sample_populate;
507 ssbox_base_init(this, hsize,vsize);
508 tab_title (this->t, 0, _("One-Sample Statistics"));
509 tab_vline(this->t, TAL_2, 1,0,vsize);
510 tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, _("N"));
511 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
512 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
513 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
516 void ssbox_independent_samples_populate(struct ssbox *ssb,
517 struct cmd_t_test *cmd);
519 /* Initialize the independent samples ssbox */
521 ssbox_independent_samples_init(struct ssbox *this,
522 struct cmd_t_test *cmd)
525 int vsize = cmd->n_variables*2 +1;
527 this->populate = ssbox_independent_samples_populate;
529 ssbox_base_init(this, hsize,vsize);
530 tab_title (this->t, 0, _("Group Statistics"));
531 tab_vline(this->t,0,1,0,vsize);
532 tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, groups->name);
533 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("N"));
534 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
535 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
536 tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
540 /* Populate the ssbox for independent samples */
542 ssbox_independent_samples_populate(struct ssbox *ssb,
543 struct cmd_t_test *cmd)
550 if ( groups->type == NUMERIC )
552 val_lab1 = val_labs_find( groups->val_labs,groups_values[0]);
553 val_lab2 = val_labs_find( groups->val_labs,groups_values[1]);
557 val_lab1 = groups_values[0].s;
558 val_lab2 = groups_values[1].s;
563 for (i=0; i < cmd->n_variables; ++i)
565 tab_text (ssb->t, 0, i*2+1, TAB_LEFT, cmd->v_variables[i]->name);
568 tab_text (ssb->t, 1, i*2+1, TAB_LEFT, val_lab1);
570 tab_float(ssb->t, 1 ,i*2+1, TAB_LEFT, groups_values[0].f, 2,0);
573 tab_text (ssb->t, 1, i*2+1+1, TAB_LEFT, val_lab2);
575 tab_float(ssb->t, 1 ,i*2+1+1, TAB_LEFT, groups_values[1].f,2,0);
580 void ssbox_paired_populate(struct ssbox *ssb,
581 struct cmd_t_test *cmd);
583 /* Initialize the paired values ssbox */
585 ssbox_paired_init(struct ssbox *this, struct cmd_t_test *cmd unused)
589 int vsize = n_pairs*2+1;
591 this->populate = ssbox_paired_populate;
593 ssbox_base_init(this, hsize,vsize);
594 tab_title (this->t, 0, _("Paired Sample Statistics"));
595 tab_vline(this->t,TAL_0,1,0,vsize-1);
596 tab_vline(this->t,TAL_2,2,0,vsize-1);
597 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
598 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("N"));
599 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
600 tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
604 /* Populate the ssbox for paired values */
606 ssbox_paired_populate(struct ssbox *ssb,struct cmd_t_test *cmd unused)
612 ds_init(t_test_pool,&ds,15);
614 for (i=0; i < n_pairs; ++i)
618 ds_printf(&ds,_("Pair %d"),i);
620 tab_text (ssb->t, 0, i*2+1, TAB_LEFT, ds.string);
621 tab_text (ssb->t, 1, i*2+1, TAB_LEFT, pairs[i][0]->name);
622 tab_text (ssb->t, 1, i*2+2, TAB_LEFT, pairs[i][1]->name);
628 /* Populate the one sample ssbox */
630 ssbox_one_sample_populate(struct ssbox *ssb, struct cmd_t_test *cmd)
636 for (i=0; i < cmd->n_variables; ++i)
638 struct t_test_proc *ttp;
639 ttp= &cmd->v_variables[i]->p.t_t;
641 tab_text (ssb->t, 0, i+1, TAB_LEFT, cmd->v_variables[i]->name);
642 tab_float (ssb->t,1, i+1, TAB_RIGHT, ttp->n, 2, 0);
643 tab_float (ssb->t,2, i+1, TAB_RIGHT, ttp->mean, 8, 2);
644 tab_float (ssb->t,3, i+1, TAB_RIGHT, ttp->std_dev, 8, 2);
645 tab_float (ssb->t,4, i+1, TAB_RIGHT, ttp->se_mean, 8, 3);
652 /* Implementation of the Test Results box struct */
654 void trbox_base_init(struct trbox *self,int n_vars, int cols);
655 void trbox_base_finalize(struct trbox *trb);
657 void trbox_independent_samples_init(struct trbox *trb,
658 struct cmd_t_test *cmd );
660 void trbox_independent_samples_populate(struct trbox *trb,
661 struct cmd_t_test *cmd);
663 void trbox_one_sample_init(struct trbox *self,
664 struct cmd_t_test *cmd );
666 void trbox_one_sample_populate(struct trbox *trb,
667 struct cmd_t_test *cmd);
669 void trbox_paired_init(struct trbox *self,
670 struct cmd_t_test *cmd );
672 void trbox_paired_populate(struct trbox *trb,
673 struct cmd_t_test *cmd);
677 /* Create a trbox according to mode*/
679 trbox_create(struct trbox *trb,
680 struct cmd_t_test *cmd, int mode)
685 trbox_one_sample_init(trb,cmd);
688 trbox_independent_samples_init(trb,cmd);
691 trbox_paired_init(trb,cmd);
698 /* Populate a trbox according to cmd */
700 trbox_populate(struct trbox *trb, struct cmd_t_test *cmd)
702 trb->populate(trb,cmd);
705 /* Submit and destroy a trbox */
707 trbox_finalize(struct trbox *trb)
712 /* Initialize the independent samples trbox */
714 trbox_independent_samples_init(struct trbox *self,
715 struct cmd_t_test *cmd unused)
718 const int vsize=cmd->n_variables*2+3;
723 self->populate = trbox_independent_samples_populate;
725 trbox_base_init(self,cmd->n_variables*2,hsize);
726 tab_title(self->t,0,_("Independent Samples Test"));
727 tab_hline(self->t,TAL_1,2,hsize-1,1);
728 tab_vline(self->t,TAL_2,2,0,vsize-1);
729 tab_vline(self->t,TAL_1,4,0,vsize-1);
730 tab_box(self->t,-1,-1,-1,TAL_1, 2,1,hsize-2,vsize-1);
731 tab_hline(self->t,TAL_1, hsize-2,hsize-1,2);
732 tab_box(self->t,-1,-1,-1,TAL_1, hsize-2,2,hsize-1,vsize-1);
733 tab_joint_text(self->t, 2, 0, 3, 0,
734 TAB_CENTER,_("Levine's Test for Equality of Variances"));
735 tab_joint_text(self->t, 4,0,hsize-1,0,
736 TAB_CENTER,_("t-test for Equality of Means"));
738 tab_text(self->t,2,2, TAB_CENTER | TAT_TITLE,_("F"));
739 tab_text(self->t,3,2, TAB_CENTER | TAT_TITLE,_("Sig."));
740 tab_text(self->t,4,2, TAB_CENTER | TAT_TITLE,_("t"));
741 tab_text(self->t,5,2, TAB_CENTER | TAT_TITLE,_("df"));
742 tab_text(self->t,6,2, TAB_CENTER | TAT_TITLE,_("Sig. (2-tailed)"));
743 tab_text(self->t,7,2, TAB_CENTER | TAT_TITLE,_("Mean Difference"));
744 tab_text(self->t,8,2, TAB_CENTER | TAT_TITLE,_("Std. Error Difference"));
745 tab_text(self->t,9,2, TAB_CENTER | TAT_TITLE,_("Lower"));
746 tab_text(self->t,10,2, TAB_CENTER | TAT_TITLE,_("Upper"));
748 ds_init(t_test_pool,&ds,80);
750 ds_printf(&ds,_("%d%% Confidence Interval of the Difference"),
751 (int)round(cmd->criteria*100.0));
753 tab_joint_text(self->t,9,1,10,1,TAB_CENTER, ds.string);
758 /* Populate the independent samples trbox */
760 trbox_independent_samples_populate(struct trbox *self,
761 struct cmd_t_test *cmd )
766 for (i=0; i < cmd->n_variables; ++i)
768 tab_text (self->t, 0, i*2+3, TAB_LEFT, cmd->v_variables[i]->name);
770 tab_text (self->t, 1, i*2+3, TAB_LEFT, _("Equal variances assumed"));
772 tab_text (self->t, 1, i*2+3+1,
773 TAB_LEFT, _("Equal variances not assumed"));
777 /* Initialize the paired samples trbox */
779 trbox_paired_init(struct trbox *self,
780 struct cmd_t_test *cmd unused)
784 const int vsize=n_pairs*2+3;
788 self->populate = trbox_paired_populate;
790 trbox_base_init(self,n_pairs*2,hsize);
791 tab_title (self->t, 0, _("Paired Samples Test"));
792 tab_hline(self->t,TAL_1,2,6,1);
793 tab_vline(self->t,TAL_2,2,0,vsize);
794 tab_joint_text(self->t,2,0,6,0,TAB_CENTER,_("Paired Differences"));
795 tab_box(self->t,-1,-1,-1,TAL_1, 2,1,6,vsize-1);
796 tab_box(self->t,-1,-1,-1,TAL_1, 6,0,hsize-1,vsize-1);
797 tab_hline(self->t,TAL_1,5,6, 2);
798 tab_vline(self->t,TAL_0,6,0,1);
800 ds_init(t_test_pool,&ds,80);
802 ds_printf(&ds,_("%d%% Confidence Interval of the Difference"),
803 (int)round(cmd->criteria*100.0));
805 tab_joint_text(self->t,5,1,6,1,TAB_CENTER, ds.string);
809 tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("Mean"));
810 tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
811 tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Std. Error Mean"));
812 tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
813 tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
814 tab_text (self->t, 7, 2, TAB_CENTER | TAT_TITLE, _("t"));
815 tab_text (self->t, 8, 2, TAB_CENTER | TAT_TITLE, _("df"));
816 tab_text (self->t, 9, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
819 /* Populate the paired samples trbox */
821 trbox_paired_populate(struct trbox *trb,
822 struct cmd_t_test *cmd unused)
827 ds_init(t_test_pool,&ds,15);
829 for (i=0; i < n_pairs; ++i)
832 ds_printf(&ds,_("Pair %d"),i);
834 tab_text (trb->t, 0, i*2+3, TAB_LEFT, ds.string);
835 tab_text (trb->t, 1, i*2+3, TAB_LEFT, pairs[i][0]->name);
836 tab_text (trb->t, 1, i*2+4, TAB_LEFT, pairs[i][1]->name);
841 /* Initialize the one sample trbox */
843 trbox_one_sample_init(struct trbox *self, struct cmd_t_test *cmd )
846 const int vsize=cmd->n_variables+3;
850 self->populate = trbox_one_sample_populate;
852 trbox_base_init(self, cmd->n_variables,hsize);
853 tab_title (self->t, 0, _("One-Sample Test"));
854 tab_hline(self->t, TAL_1, 1, hsize - 1, 1);
855 tab_vline(self->t, TAL_2, 1, 0, vsize);
856 ds_init(t_test_pool, &ds, 80);
857 ds_printf(&ds,_("Test Value = %f"),cmd->n_testval);
858 tab_joint_text(self->t, 1, 0, hsize-1,0, TAB_CENTER,ds.string);
859 tab_box(self->t, -1, -1, -1, TAL_1, 1,1,hsize-1,vsize-1);
862 ds_printf(&ds,_("%d%% Confidence Interval of the Difference"),
863 (int)round(cmd->criteria*100.0));
864 tab_joint_text(self->t,5,1,6,1,TAB_CENTER, ds.string);
866 tab_vline(self->t,TAL_0,6,1,1);
867 tab_hline(self->t,TAL_1,5,6,2);
868 tab_text (self->t, 1, 2, TAB_CENTER | TAT_TITLE, _("t"));
869 tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("df"));
870 tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
871 tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Mean Difference"));
872 tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
873 tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
878 /* Populate the one sample trbox */
880 trbox_one_sample_populate(struct trbox *trb, struct cmd_t_test *cmd)
886 for (i=0; i < cmd->n_variables; ++i)
894 struct t_test_proc *ttp;
895 ttp= &cmd->v_variables[i]->p.t_t;
898 tab_text (trb->t, 0, i+3, TAB_LEFT, cmd->v_variables[i]->name);
900 t = (ttp->mean - cmd->n_testval ) * sqrt(ttp->n) / ttp->std_dev ;
902 tab_float (trb->t, 1, i+3, TAB_RIGHT, t, 8,3);
904 /* degrees of freedom */
907 tab_float (trb->t, 2, i+3, TAB_RIGHT, df, 8,0);
909 cdft(&which, &p, &q, &t, &df, &status, &bound);
913 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
917 /* Multiply by 2 to get 2-tailed significance */
918 tab_float (trb->t, 3, i+3, TAB_RIGHT, q*2.0, 8,3);
920 tab_float (trb->t, 4, i+3, TAB_RIGHT, ttp->mean_diff, 8,3);
923 q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
925 which=2; /* Calc T from p,q and df */
926 cdft(&which, &p, &q, &t, &df, &status, &bound);
929 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
932 tab_float (trb->t, 5, i+3, TAB_RIGHT,
933 ttp->mean_diff - t * ttp->se_mean, 8,4);
935 tab_float (trb->t, 6, i+3, TAB_RIGHT,
936 ttp->mean_diff + t * ttp->se_mean, 8,4);
940 /* Base initializer for the generalized trbox */
942 trbox_base_init(struct trbox *self, int data_rows, int cols)
944 const int rows = 3 + data_rows;
946 self->finalize = trbox_base_finalize;
947 self->t = tab_create (cols, rows, 0);
948 tab_headers (self->t,0,0,3,0);
949 tab_box (self->t, TAL_2, TAL_2, TAL_0, TAL_0, 0, 0, cols -1, rows -1);
950 tab_hline(self->t, TAL_2,0,cols-1,3);
951 tab_dim (self->t, tab_natural_dimensions);
955 /* Base finalizer for the trbox */
957 trbox_base_finalize(struct trbox *trb)
963 /* Calculation Implementation */
965 /* Per case calculations common to all variants of the T test */
967 common_calc (struct ccase *c)
971 double weight = dict_get_case_weight(default_dict,c);
973 for(i=0; i< cmd.n_variables ; ++i)
975 struct t_test_proc *ttp;
976 struct variable *v = cmd.v_variables[i];
977 union value *val = &c->data[v->fv];
979 ttp= &cmd.v_variables[i]->p.t_t;
981 if (val->f != SYSMIS)
984 ttp->sum+=weight * val->f;
985 ttp->ssq+=weight * val->f * val->f;
991 /* Pre calculations common to all variants of the T test */
993 common_precalc (void)
997 for(i=0; i< cmd.n_variables ; ++i)
999 struct t_test_proc *ttp;
1000 ttp= &cmd.v_variables[i]->p.t_t;
1009 /* Post calculations common to all variants of the T test */
1011 common_postcalc (void)
1015 for(i=0; i< cmd.n_variables ; ++i)
1017 struct t_test_proc *ttp;
1018 ttp= &cmd.v_variables[i]->p.t_t;
1020 ttp->mean=ttp->sum / ttp->n;
1023 ( (ttp->ssq / ttp->n ) - ttp->mean * ttp->mean )
1026 ttp->se_mean = ttp->std_dev / sqrt(ttp->n);
1028 ttp->mean_diff= ttp->sum_diff / ttp->n;
1032 /* Per case calculations for one sample t test */
1034 one_sample_calc (struct ccase *c)
1038 double weight = dict_get_case_weight(default_dict,c);
1040 for(i=0; i< cmd.n_variables ; ++i)
1042 struct t_test_proc *ttp;
1043 struct variable *v = cmd.v_variables[i];
1044 union value *val = &c->data[v->fv];
1046 ttp= &cmd.v_variables[i]->p.t_t;
1048 if (val->f != SYSMIS)
1049 ttp->sum_diff += weight * (val->f - cmd.n_testval);
1055 /* Pre calculations for one sample t test */
1057 one_sample_precalc (void)
1061 for(i=0; i< cmd.n_variables ; ++i)
1063 struct t_test_proc *ttp;
1064 ttp= &cmd.v_variables[i]->p.t_t;
1070 /* Post calculations for one sample t test */
1072 one_sample_postcalc (void)
1076 for(i=0; i< cmd.n_variables ; ++i)
1078 struct t_test_proc *ttp;
1079 ttp= &cmd.v_variables[i]->p.t_t;
1082 ttp->mean_diff = ttp->sum_diff / ttp->n ;