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"
48 variables=varlist("PV_NO_SCRATCH | PV_NUMERIC");
50 +missing=miss:!analysis/listwise,
51 incl:include/!exclude;
52 format=fmt:!labels/nolabels;
53 criteria=:cin(d:criteria,"%s > 0. && %s < 1.").
59 static struct cmd_t_test cmd;
61 /* Function to use for testing for missing values */
62 static is_missing_func value_is_missing;
64 /* Variable for the GROUPS subcommand, if given. */
65 static struct variable *indep_var;
67 /* GROUPS: Number of values specified by the user; the values
70 static int n_group_values;
71 static union value groups_values[2];
72 static enum comparison criteria[2];
76 /* PAIRS: Number of pairs to be compared ; each pair. */
77 static int n_pairs = 0 ;
81 /* The variables comprising the pair */
82 struct variable *v[2];
85 /* The number of valid variable pairs */
88 /* The sum of the members */
91 /* sum of squares of the members */
94 /* Std deviation of the members */
98 /* Sample Std deviation of the members */
101 /* The means of the members */
104 /* The correlation coefficient between the variables */
107 /* The sum of the differences */
110 /* The sum of the products */
113 /* The mean of the differences */
116 /* The sum of the squares of the differences */
119 /* The std deviation of the differences */
123 static struct pair *pairs=0;
125 static int parse_value (union value * v, int type) ;
127 /* Structures and Functions for the Statistics Summary Box */
129 typedef void populate_ssbox_func(struct ssbox *ssb,
130 struct cmd_t_test *cmd);
131 typedef void finalize_ssbox_func(struct ssbox *ssb);
137 populate_ssbox_func *populate;
138 finalize_ssbox_func *finalize;
143 void ssbox_create(struct ssbox *ssb, struct cmd_t_test *cmd, int mode);
145 /* Populate a ssbox according to cmd */
146 void ssbox_populate(struct ssbox *ssb, struct cmd_t_test *cmd);
148 /* Submit and destroy a ssbox */
149 void ssbox_finalize(struct ssbox *ssb);
151 /* A function to create, populate and submit the Paired Samples Correlation
156 /* Structures and Functions for the Test Results Box */
159 typedef void populate_trbox_func(struct trbox *trb,
160 struct cmd_t_test *cmd);
161 typedef void finalize_trbox_func(struct trbox *trb);
165 populate_trbox_func *populate;
166 finalize_trbox_func *finalize;
170 void trbox_create(struct trbox *trb, struct cmd_t_test *cmd, int mode);
172 /* Populate a ssbox according to cmd */
173 void trbox_populate(struct trbox *trb, struct cmd_t_test *cmd);
175 /* Submit and destroy a ssbox */
176 void trbox_finalize(struct trbox *trb);
178 /* Which mode was T-TEST invoked */
186 static int common_calc (struct ccase *, void *);
187 static void common_precalc (void *);
188 static void common_postcalc (void *);
190 static int one_sample_calc (struct ccase *, void *);
191 static void one_sample_precalc (void *);
192 static void one_sample_postcalc (void *);
194 static int paired_calc (struct ccase *, void *);
195 static void paired_precalc (void *);
196 static void paired_postcalc (void *);
198 static void group_precalc (void *);
199 static int group_calc (struct ccase *, void *);
200 static void group_postcalc (void *);
203 static int compare_var_name (const void *a_, const void *b_, void *v_ UNUSED);
204 static unsigned hash_var_name (const void *a_, void *v_ UNUSED);
213 struct ssbox stat_summary_box;
214 struct trbox test_results_box;
216 if ( !parse_t_test(&cmd) )
219 if (! cmd.sbc_criteria)
224 if (cmd.sbc_testval) ++m;
225 if (cmd.sbc_groups) ++m;
226 if (cmd.sbc_pairs) ++m;
231 _("TESTVAL, GROUPS and PAIRS subcommands are mutually exclusive.")
239 else if (cmd.sbc_groups)
244 if ( mode == T_PAIRED)
246 if (cmd.sbc_variables)
248 msg(SE, _("VARIABLES subcommand is not appropriate with PAIRS"));
253 /* Iterate through the pairs and put each variable that is a
254 member of a pair into cmd.v_variables */
257 struct hsh_iterator hi;
258 struct hsh_table *hash;
261 hash=hsh_create(n_pairs,compare_var_name,hash_var_name,0,0);
263 for (i=0; i < n_pairs; ++i)
265 hsh_insert(hash,pairs[i].v[0]);
266 hsh_insert(hash,pairs[i].v[1]);
269 assert(cmd.n_variables == 0);
270 cmd.n_variables = hsh_count(hash);
272 cmd.v_variables = xrealloc(cmd.v_variables,
273 sizeof(struct variable) * cmd.n_variables);
274 /* Iterate through the hash */
275 for (i=0,v = (struct variable *) hsh_first(hash,&hi);
277 v=hsh_next(hash,&hi) )
278 cmd.v_variables[i++]=v;
284 /* If /MISSING=INCLUDE is set, then user missing values are ignored */
285 if (cmd.incl == TTS_INCLUDE )
286 value_is_missing = is_system_missing;
288 value_is_missing = is_missing;
290 procedure_with_splits (common_precalc, common_calc, common_postcalc, NULL);
295 procedure_with_splits (one_sample_precalc, one_sample_calc,
296 one_sample_postcalc, NULL);
299 procedure_with_splits (paired_precalc, paired_calc, paired_postcalc,
303 procedure_with_splits(group_precalc,group_calc,group_postcalc, NULL);
304 levene(indep_var, cmd.n_variables, cmd.v_variables,
305 (cmd.miss == TTS_LISTWISE)?LEV_LISTWISE:LEV_ANALYSIS ,
310 ssbox_create(&stat_summary_box,&cmd,mode);
311 ssbox_populate(&stat_summary_box,&cmd);
312 ssbox_finalize(&stat_summary_box);
314 if ( mode == T_PAIRED)
317 trbox_create(&test_results_box,&cmd,mode);
318 trbox_populate(&test_results_box,&cmd);
319 trbox_finalize(&test_results_box);
325 if ( mode == T_IND_SAMPLES)
328 /* Destroy any group statistics we created */
329 for (i= 0 ; i < cmd.n_variables ; ++i )
331 free(cmd.v_variables[i]->p.t_t.gs);
339 tts_custom_groups (struct cmd_t_test *cmd UNUSED)
344 if (token != T_ALL &&
345 (token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
348 msg(SE,_("`%s' is not a variable name"),tokid);
352 indep_var = parse_variable ();
355 lex_error ("expecting variable name in GROUPS subcommand");
359 if (indep_var->type == T_STRING && indep_var->width > MAX_SHORT_STRING)
361 msg (SE, _("Long string variable %s is not valid here."),
366 if (!lex_match ('('))
368 if (indep_var->type == NUMERIC)
370 groups_values[0].f = 1;
371 groups_values[1].f = 2;
372 criteria[0] = criteria[1] = CMP_EQ;
378 msg (SE, _("When applying GROUPS to a string variable, at "
379 "least one value must be specified."));
384 if (!parse_value (&groups_values[0],indep_var->type))
390 criteria[0] = CMP_LE;
391 criteria[1] = CMP_GT;
392 groups_values[1] = groups_values[0];
397 if (!parse_value (&groups_values[1],indep_var->type))
401 if (!lex_force_match (')'))
404 criteria[0] = criteria[1] = CMP_EQ;
410 tts_custom_pairs (struct cmd_t_test *cmd UNUSED)
412 struct variable **vars;
417 int n_after_WITH = -1;
418 int paired ; /* Was the PAIRED keyword given ? */
422 if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
425 msg(SE,_("`%s' is not a variable name"),tokid);
430 if (!parse_variables (default_dict, &vars, &n_vars,
431 PV_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH))
439 if (lex_match (T_WITH))
441 n_before_WITH = n_vars;
442 if (!parse_variables (default_dict, &vars, &n_vars,
443 PV_DUPLICATE | PV_APPEND
444 | PV_NUMERIC | PV_NO_SCRATCH))
449 n_after_WITH = n_vars - n_before_WITH;
452 paired = (lex_match ('(') && lex_match_id ("PAIRED") && lex_match (')'));
454 /* Determine the number of pairs needed */
457 if (n_before_WITH != n_after_WITH)
460 msg (SE, _("PAIRED was specified but the number of variables "
461 "preceding WITH (%d) did not match the number "
463 n_before_WITH, n_after_WITH );
466 n_pairs_local=n_before_WITH;
468 else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */
470 n_pairs_local=n_before_WITH * n_after_WITH ;
472 else /* Neither WITH nor PAIRED keyword given */
477 msg (SE, _("At least two variables must be specified "
482 /* how many ways can you pick 2 from n_vars ? */
483 n_pairs_local = n_vars * (n_vars -1 ) /2 ;
487 /* Allocate storage for the pairs */
488 pairs = xrealloc(pairs, sizeof(struct pair) * (n_pairs + n_pairs_local) );
490 /* Populate the pairs with the appropriate variables */
495 assert(n_pairs_local == n_vars/2);
496 for (i = 0; i < n_pairs_local ; ++i)
498 pairs[i].v[n_pairs+0] = vars[i];
499 pairs[i].v[n_pairs+1] = vars[i+n_pairs_local];
502 else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */
507 for(i=0 ; i < n_before_WITH ; ++i )
509 for(j=0 ; j < n_after_WITH ; ++j)
511 pairs[p].v[0] = vars[i];
512 pairs[p].v[1] = vars[j+n_before_WITH];
517 else /* Neither WITH nor PAIRED given */
522 for(i=0 ; i < n_vars ; ++i )
524 for(j=i+1 ; j < n_vars ; ++j)
526 pairs[p].v[0] = vars[i];
527 pairs[p].v[1] = vars[j];
533 n_pairs+=n_pairs_local;
538 /* Parses the current token (numeric or string, depending on type)
539 value v and returns success. */
541 parse_value (union value * v, int type )
545 if (!lex_force_num ())
551 if (!lex_force_string ())
553 strncpy (v->s, ds_value (&tokstr), ds_length (&tokstr));
562 /* Implementation of the SSBOX object */
564 void ssbox_base_init(struct ssbox *this, int cols,int rows);
566 void ssbox_base_finalize(struct ssbox *ssb);
568 void ssbox_one_sample_init(struct ssbox *this,
569 struct cmd_t_test *cmd );
571 void ssbox_independent_samples_init(struct ssbox *this,
572 struct cmd_t_test *cmd);
574 void ssbox_paired_init(struct ssbox *this,
575 struct cmd_t_test *cmd);
577 /* Factory to create an ssbox */
579 ssbox_create(struct ssbox *ssb, struct cmd_t_test *cmd, int mode)
584 ssbox_one_sample_init(ssb,cmd);
587 ssbox_independent_samples_init(ssb,cmd);
590 ssbox_paired_init(ssb,cmd);
598 /* Despatcher for the populate method */
600 ssbox_populate(struct ssbox *ssb,struct cmd_t_test *cmd)
602 ssb->populate(ssb,cmd);
606 /* Despatcher for finalize */
608 ssbox_finalize(struct ssbox *ssb)
614 /* Submit the box and clear up */
616 ssbox_base_finalize(struct ssbox *ssb)
621 /* Initialize a ssbox struct */
623 ssbox_base_init(struct ssbox *this, int cols,int rows)
625 this->finalize = ssbox_base_finalize;
626 this->t = tab_create (cols, rows, 0);
628 tab_columns (this->t, SOM_COL_DOWN, 1);
629 tab_headers (this->t,0,0,1,0);
630 tab_box (this->t, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, cols -1, rows -1 );
631 tab_hline(this->t, TAL_2,0,cols-1,1);
632 tab_dim (this->t, tab_natural_dimensions);
635 void ssbox_one_sample_populate(struct ssbox *ssb,
636 struct cmd_t_test *cmd);
638 /* Initialize the one_sample ssbox */
640 ssbox_one_sample_init(struct ssbox *this,
641 struct cmd_t_test *cmd )
644 const int vsize=cmd->n_variables+1;
646 this->populate = ssbox_one_sample_populate;
648 ssbox_base_init(this, hsize,vsize);
649 tab_title (this->t, 0, _("One-Sample Statistics"));
650 tab_vline(this->t, TAL_2, 1,0,vsize);
651 tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, _("N"));
652 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
653 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
654 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
657 void ssbox_independent_samples_populate(struct ssbox *ssb,
658 struct cmd_t_test *cmd);
660 /* Initialize the independent samples ssbox */
662 ssbox_independent_samples_init(struct ssbox *this,
663 struct cmd_t_test *cmd)
666 int vsize = cmd->n_variables*2 +1;
668 this->populate = ssbox_independent_samples_populate;
670 ssbox_base_init(this, hsize,vsize);
671 tab_title (this->t, 0, _("Group Statistics"));
672 tab_vline(this->t,0,1,0,vsize);
673 tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, indep_var->name);
674 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("N"));
675 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
676 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
677 tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
681 /* Populate the ssbox for independent samples */
683 ssbox_independent_samples_populate(struct ssbox *ssb,
684 struct cmd_t_test *cmd)
691 char prefix[2][3]={"",""};
693 if ( indep_var->type == NUMERIC )
695 val_lab0 = val_labs_find( indep_var->val_labs,groups_values[0]);
696 val_lab1 = val_labs_find( indep_var->val_labs,groups_values[1]);
700 val_lab0 = groups_values[0].s;
701 val_lab1 = groups_values[1].s;
704 if (n_group_values == 1)
706 strcpy(prefix[0],"< ");
707 strcpy(prefix[1],">=");
712 for (i=0; i < cmd->n_variables; ++i)
716 tab_text (ssb->t, 0, i*2+1, TAB_LEFT, cmd->v_variables[i]->name);
719 tab_text (ssb->t, 1, i*2+1, TAB_LEFT | TAT_PRINTF,
720 "%s%s", prefix[0], val_lab0);
722 tab_text (ssb->t, 1, i*2+1, TAB_LEFT | TAT_PRINTF,
723 "%s%g", prefix[0], groups_values[0].f);
727 tab_text (ssb->t, 1, i*2+1+1, TAB_LEFT | TAT_PRINTF,
728 "%s%s", prefix[1], val_lab1);
730 tab_text (ssb->t, 1, i*2+1+1, TAB_LEFT | TAT_PRINTF,
731 "%s%g", prefix[1], groups_values[1].f);
733 /* Fill in the group statistics */
734 for ( g=0; g < 2 ; ++g )
736 struct group_statistics *gs = &cmd->v_variables[i]->p.t_t.gs[g];
738 tab_float(ssb->t, 2 ,i*2+g+1, TAB_RIGHT, gs->n, 2, 0);
739 tab_float(ssb->t, 3 ,i*2+g+1, TAB_RIGHT, gs->mean, 8, 2);
740 tab_float(ssb->t, 4 ,i*2+g+1, TAB_RIGHT, gs->std_dev, 8, 3);
741 tab_float(ssb->t, 5 ,i*2+g+1, TAB_RIGHT, gs->se_mean, 8, 3);
747 void ssbox_paired_populate(struct ssbox *ssb,
748 struct cmd_t_test *cmd);
750 /* Initialize the paired values ssbox */
752 ssbox_paired_init(struct ssbox *this, struct cmd_t_test *cmd UNUSED)
756 int vsize = n_pairs*2+1;
758 this->populate = ssbox_paired_populate;
760 ssbox_base_init(this, hsize,vsize);
761 tab_title (this->t, 0, _("Paired Sample Statistics"));
762 tab_vline(this->t,TAL_0,1,0,vsize-1);
763 tab_vline(this->t,TAL_2,2,0,vsize-1);
764 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
765 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("N"));
766 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
767 tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
771 /* Populate the ssbox for paired values */
773 ssbox_paired_populate(struct ssbox *ssb,struct cmd_t_test *cmd UNUSED)
779 for (i=0; i < n_pairs; ++i)
783 tab_text (ssb->t, 0, i*2+1, TAB_LEFT | TAT_PRINTF , _("Pair %d"),i);
785 for (j=0 ; j < 2 ; ++j)
787 struct group_statistics *gs;
789 gs=&pairs[i].v[j]->p.t_t.ugs;
793 tab_text (ssb->t, 1, i*2+j+1, TAB_LEFT, pairs[i].v[j]->name);
796 tab_float (ssb->t,2, i*2+j+1, TAB_RIGHT, pairs[i].mean[j], 8, 2);
797 tab_float (ssb->t,3, i*2+j+1, TAB_RIGHT, pairs[i].n, 2, 0);
798 tab_float (ssb->t,4, i*2+j+1, TAB_RIGHT, pairs[i].std_dev[j], 8, 3);
799 tab_float (ssb->t,5, i*2+j+1, TAB_RIGHT, pairs[i].std_dev[j]/sqrt(pairs[i].n), 8, 3);
805 /* Populate the one sample ssbox */
807 ssbox_one_sample_populate(struct ssbox *ssb, struct cmd_t_test *cmd)
813 for (i=0; i < cmd->n_variables; ++i)
815 struct group_statistics *gs;
816 gs= &cmd->v_variables[i]->p.t_t.ugs;
818 tab_text (ssb->t, 0, i+1, TAB_LEFT, cmd->v_variables[i]->name);
819 tab_float (ssb->t,1, i+1, TAB_RIGHT, gs->n, 2, 0);
820 tab_float (ssb->t,2, i+1, TAB_RIGHT, gs->mean, 8, 2);
821 tab_float (ssb->t,3, i+1, TAB_RIGHT, gs->std_dev, 8, 2);
822 tab_float (ssb->t,4, i+1, TAB_RIGHT, gs->se_mean, 8, 3);
829 /* Implementation of the Test Results box struct */
831 void trbox_base_init(struct trbox *self,int n_vars, int cols);
832 void trbox_base_finalize(struct trbox *trb);
834 void trbox_independent_samples_init(struct trbox *trb,
835 struct cmd_t_test *cmd );
837 void trbox_independent_samples_populate(struct trbox *trb,
838 struct cmd_t_test *cmd);
840 void trbox_one_sample_init(struct trbox *self,
841 struct cmd_t_test *cmd );
843 void trbox_one_sample_populate(struct trbox *trb,
844 struct cmd_t_test *cmd);
846 void trbox_paired_init(struct trbox *self,
847 struct cmd_t_test *cmd );
849 void trbox_paired_populate(struct trbox *trb,
850 struct cmd_t_test *cmd);
854 /* Create a trbox according to mode*/
856 trbox_create(struct trbox *trb,
857 struct cmd_t_test *cmd, int mode)
862 trbox_one_sample_init(trb,cmd);
865 trbox_independent_samples_init(trb,cmd);
868 trbox_paired_init(trb,cmd);
875 /* Populate a trbox according to cmd */
877 trbox_populate(struct trbox *trb, struct cmd_t_test *cmd)
879 trb->populate(trb,cmd);
882 /* Submit and destroy a trbox */
884 trbox_finalize(struct trbox *trb)
889 /* Initialize the independent samples trbox */
891 trbox_independent_samples_init(struct trbox *self,
892 struct cmd_t_test *cmd UNUSED)
895 const int vsize=cmd->n_variables*2+3;
898 self->populate = trbox_independent_samples_populate;
900 trbox_base_init(self,cmd->n_variables*2,hsize);
901 tab_title(self->t,0,_("Independent Samples Test"));
902 tab_hline(self->t,TAL_1,2,hsize-1,1);
903 tab_vline(self->t,TAL_2,2,0,vsize-1);
904 tab_vline(self->t,TAL_1,4,0,vsize-1);
905 tab_box(self->t,-1,-1,-1,TAL_1, 2,1,hsize-2,vsize-1);
906 tab_hline(self->t,TAL_1, hsize-2,hsize-1,2);
907 tab_box(self->t,-1,-1,-1,TAL_1, hsize-2,2,hsize-1,vsize-1);
908 tab_joint_text(self->t, 2, 0, 3, 0,
909 TAB_CENTER,_("Levene's Test for Equality of Variances"));
910 tab_joint_text(self->t, 4,0,hsize-1,0,
911 TAB_CENTER,_("t-test for Equality of Means"));
913 tab_text(self->t,2,2, TAB_CENTER | TAT_TITLE,_("F"));
914 tab_text(self->t,3,2, TAB_CENTER | TAT_TITLE,_("Sig."));
915 tab_text(self->t,4,2, TAB_CENTER | TAT_TITLE,_("t"));
916 tab_text(self->t,5,2, TAB_CENTER | TAT_TITLE,_("df"));
917 tab_text(self->t,6,2, TAB_CENTER | TAT_TITLE,_("Sig. (2-tailed)"));
918 tab_text(self->t,7,2, TAB_CENTER | TAT_TITLE,_("Mean Difference"));
919 tab_text(self->t,8,2, TAB_CENTER | TAT_TITLE,_("Std. Error Difference"));
920 tab_text(self->t,9,2, TAB_CENTER | TAT_TITLE,_("Lower"));
921 tab_text(self->t,10,2, TAB_CENTER | TAT_TITLE,_("Upper"));
923 tab_joint_text(self->t, 9, 1, 10, 1, TAB_CENTER | TAT_PRINTF,
924 _("%d%% Confidence Interval of the Difference"),
925 (int)round(cmd->criteria*100.0));
929 /* Populate the independent samples trbox */
931 trbox_independent_samples_populate(struct trbox *self,
932 struct cmd_t_test *cmd )
937 for (i=0; i < cmd->n_variables; ++i)
949 double pooled_variance;
953 struct group_statistics *gs0 = &cmd->v_variables[i]->p.t_t.gs[0];
954 struct group_statistics *gs1 = &cmd->v_variables[i]->p.t_t.gs[1];
956 tab_text (self->t, 0, i*2+3, TAB_LEFT, cmd->v_variables[i]->name);
958 tab_text (self->t, 1, i*2+3, TAB_LEFT, _("Equal variances assumed"));
961 tab_float(self->t, 2, i*2+3, TAB_CENTER,
962 cmd->v_variables[i]->p.t_t.levene, 8,3);
965 /* Now work out the significance of the Levene test */
967 which=1; df1 = 1; df2 = cmd->v_variables[i]->p.t_t.ugs.n - 2;
968 cdff(&which,&p,&q,&cmd->v_variables[i]->p.t_t.levene,
969 &df1,&df2,&status,&bound);
973 msg( SE, _("Error calculating F statistic (cdff returned %d)."),status);
976 tab_float(self->t, 3, i*2+3, TAB_CENTER, q, 8,3 );
978 df = gs0->n + gs1->n - 2.0 ;
979 tab_float (self->t, 5, i*2+3, TAB_RIGHT, df, 2, 0);
981 pooled_variance = ( (gs0->n )*sqr(gs0->s_std_dev)
983 (gs1->n )*sqr(gs1->s_std_dev)
986 t = (gs0->mean - gs1->mean) / sqrt(pooled_variance) ;
987 t /= sqrt((gs0->n + gs1->n)/(gs0->n*gs1->n));
989 tab_float (self->t, 4, i*2+3, TAB_RIGHT, t, 8, 3);
992 which=1; /* get p & q from t & df */
993 cdft(&which, &p, &q, &t, &df, &status, &bound);
996 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
999 tab_float(self->t, 6, i*2+3, TAB_RIGHT, 2.0*(t>0?q:p) , 8, 3);
1001 mean_diff = gs0->mean - gs1->mean;
1002 tab_float(self->t, 7, i*2+3, TAB_RIGHT, mean_diff, 8, 3);
1005 std_err_diff = sqrt( sqr(gs0->se_mean) + sqr(gs1->se_mean));
1006 tab_float(self->t, 8, i*2+3, TAB_RIGHT, std_err_diff, 8, 3);
1009 /* Now work out the confidence interval */
1010 q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
1012 which=2; /* Calc T from p,q and df */
1013 cdft(&which, &p, &q, &t, &df, &status, &bound);
1016 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1019 tab_float(self->t, 9, i*2+3, TAB_RIGHT,
1020 mean_diff - t * std_err_diff, 8, 3);
1022 tab_float(self->t, 10, i*2+3, TAB_RIGHT,
1023 mean_diff + t * std_err_diff, 8, 3);
1028 /* Now for the \sigma_1 != \sigma_2 case */
1029 tab_text (self->t, 1, i*2+3+1,
1030 TAB_LEFT, _("Equal variances not assumed"));
1033 se2 = (sqr(gs0->s_std_dev)/(gs0->n -1) ) +
1034 (sqr(gs1->s_std_dev)/(gs1->n -1) );
1036 t = mean_diff / sqrt(se2) ;
1037 tab_float (self->t, 4, i*2+3+1, TAB_RIGHT, t, 8, 3);
1040 (sqr(sqr(gs0->s_std_dev)/(gs0->n - 1 ))
1044 (sqr(sqr(gs1->s_std_dev)/(gs1->n - 1 ))
1048 tab_float (self->t, 5, i*2+3+1, TAB_RIGHT, df, 8, 3);
1050 which=1; /* get p & q from t & df */
1051 cdft(&which, &p, &q, &t, &df, &status, &bound);
1054 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1057 tab_float(self->t, 6, i*2+3+1, TAB_RIGHT, 2.0*(t>0?q:p) , 8, 3);
1059 /* Now work out the confidence interval */
1060 q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
1062 which=2; /* Calc T from p,q and df */
1063 cdft(&which, &p, &q, &t, &df, &status, &bound);
1066 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1070 tab_float(self->t, 7, i*2+3+1, TAB_RIGHT, mean_diff, 8, 3);
1073 tab_float(self->t, 8, i*2+3+1, TAB_RIGHT, std_err_diff, 8, 3);
1076 tab_float(self->t, 9, i*2+3+1, TAB_RIGHT,
1077 mean_diff - t * std_err_diff, 8, 3);
1079 tab_float(self->t, 10, i*2+3+1, TAB_RIGHT,
1080 mean_diff + t * std_err_diff, 8, 3);
1086 /* Initialize the paired samples trbox */
1088 trbox_paired_init(struct trbox *self,
1089 struct cmd_t_test *cmd UNUSED)
1093 const int vsize=n_pairs+3;
1095 self->populate = trbox_paired_populate;
1097 trbox_base_init(self,n_pairs,hsize);
1098 tab_title (self->t, 0, _("Paired Samples Test"));
1099 tab_hline(self->t,TAL_1,2,6,1);
1100 tab_vline(self->t,TAL_2,2,0,vsize);
1101 tab_joint_text(self->t,2,0,6,0,TAB_CENTER,_("Paired Differences"));
1102 tab_box(self->t,-1,-1,-1,TAL_1, 2,1,6,vsize-1);
1103 tab_box(self->t,-1,-1,-1,TAL_1, 6,0,hsize-1,vsize-1);
1104 tab_hline(self->t,TAL_1,5,6, 2);
1105 tab_vline(self->t,TAL_0,6,0,1);
1107 tab_joint_text(self->t, 5, 1, 6, 1, TAB_CENTER | TAT_PRINTF,
1108 _("%d%% Confidence Interval of the Difference"),
1109 (int)round(cmd->criteria*100.0));
1111 tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("Mean"));
1112 tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
1113 tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Std. Error Mean"));
1114 tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
1115 tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
1116 tab_text (self->t, 7, 2, TAB_CENTER | TAT_TITLE, _("t"));
1117 tab_text (self->t, 8, 2, TAB_CENTER | TAT_TITLE, _("df"));
1118 tab_text (self->t, 9, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
1121 /* Populate the paired samples trbox */
1123 trbox_paired_populate(struct trbox *trb,
1124 struct cmd_t_test *cmd UNUSED)
1128 for (i=0; i < n_pairs; ++i)
1136 double n = pairs[i].n;
1140 tab_text (trb->t, 0, i+3, TAB_LEFT | TAT_PRINTF, _("Pair %d"),i);
1142 tab_text (trb->t, 1, i+3, TAB_LEFT | TAT_PRINTF, "%s - %s",
1143 pairs[i].v[0]->name, pairs[i].v[1]->name);
1145 tab_float(trb->t, 2, i+3, TAB_RIGHT, pairs[i].mean_diff, 8, 4);
1147 tab_float(trb->t, 3, i+3, TAB_RIGHT, pairs[i].std_dev_diff, 8, 5);
1150 se_mean = pairs[i].std_dev_diff / sqrt(n) ;
1151 tab_float(trb->t, 4, i+3, TAB_RIGHT, se_mean, 8,5 );
1153 /* Now work out the confidence interval */
1154 q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
1156 which=2; /* Calc T from p,q and df */
1157 cdft(&which, &p, &q, &t, &df, &status, &bound);
1161 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1164 tab_float(trb->t, 5, i+3, TAB_RIGHT,
1165 pairs[i].mean_diff - t * se_mean , 8, 4);
1167 tab_float(trb->t, 6, i+3, TAB_RIGHT,
1168 pairs[i].mean_diff + t * se_mean , 8, 4);
1170 t = (pairs[i].mean[0] - pairs[i].mean[1])
1172 ( sqr (pairs[i].s_std_dev[0]) + sqr (pairs[i].s_std_dev[1]) -
1173 2 * pairs[i].correlation *
1174 pairs[i].s_std_dev[0] * pairs[i].s_std_dev[1] )
1178 tab_float(trb->t, 7, i+3, TAB_RIGHT, t , 8,3 );
1180 /* Degrees of freedom */
1181 tab_float(trb->t, 8, i+3, TAB_RIGHT, df , 2, 0 );
1184 cdft(&which, &p, &q, &t, &df, &status, &bound);
1187 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1191 tab_float(trb->t, 9, i+3, TAB_RIGHT, 2.0*(t>0?q:p) , 8, 3);
1196 /* Initialize the one sample trbox */
1198 trbox_one_sample_init(struct trbox *self, struct cmd_t_test *cmd )
1201 const int vsize=cmd->n_variables+3;
1203 self->populate = trbox_one_sample_populate;
1205 trbox_base_init(self, cmd->n_variables,hsize);
1206 tab_title (self->t, 0, _("One-Sample Test"));
1207 tab_hline(self->t, TAL_1, 1, hsize - 1, 1);
1208 tab_vline(self->t, TAL_2, 1, 0, vsize);
1210 tab_joint_text(self->t, 1, 0, hsize-1,0, TAB_CENTER | TAT_PRINTF,
1211 _("Test Value = %f"),cmd->n_testval);
1213 tab_box(self->t, -1, -1, -1, TAL_1, 1,1,hsize-1,vsize-1);
1216 tab_joint_text(self->t,5,1,6,1,TAB_CENTER | TAT_PRINTF,
1217 _("%d%% Confidence Interval of the Difference"),
1218 (int)round(cmd->criteria*100.0));
1220 tab_vline(self->t,TAL_0,6,1,1);
1221 tab_hline(self->t,TAL_1,5,6,2);
1222 tab_text (self->t, 1, 2, TAB_CENTER | TAT_TITLE, _("t"));
1223 tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("df"));
1224 tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
1225 tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Mean Difference"));
1226 tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
1227 tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
1232 /* Populate the one sample trbox */
1234 trbox_one_sample_populate(struct trbox *trb, struct cmd_t_test *cmd)
1240 for (i=0; i < cmd->n_variables; ++i)
1248 struct group_statistics *gs;
1249 gs= &cmd->v_variables[i]->p.t_t.ugs;
1252 tab_text (trb->t, 0, i+3, TAB_LEFT, cmd->v_variables[i]->name);
1254 t = (gs->mean - cmd->n_testval ) * sqrt(gs->n) / gs->std_dev ;
1256 tab_float (trb->t, 1, i+3, TAB_RIGHT, t, 8,3);
1258 /* degrees of freedom */
1261 tab_float (trb->t, 2, i+3, TAB_RIGHT, df, 8,0);
1263 cdft(&which, &p, &q, &t, &df, &status, &bound);
1267 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1271 /* Multiply by 2 to get 2-tailed significance, makeing sure we've got
1273 tab_float (trb->t, 3, i+3, TAB_RIGHT, 2.0*(t>0?q:p), 8,3);
1275 tab_float (trb->t, 4, i+3, TAB_RIGHT, gs->mean_diff, 8,3);
1278 q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
1280 which=2; /* Calc T from p,q and df */
1281 cdft(&which, &p, &q, &t, &df, &status, &bound);
1284 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1287 tab_float (trb->t, 5, i+3, TAB_RIGHT,
1288 gs->mean_diff - t * gs->se_mean, 8,4);
1290 tab_float (trb->t, 6, i+3, TAB_RIGHT,
1291 gs->mean_diff + t * gs->se_mean, 8,4);
1295 /* Base initializer for the generalized trbox */
1297 trbox_base_init(struct trbox *self, int data_rows, int cols)
1299 const int rows = 3 + data_rows;
1301 self->finalize = trbox_base_finalize;
1302 self->t = tab_create (cols, rows, 0);
1303 tab_headers (self->t,0,0,3,0);
1304 tab_box (self->t, TAL_2, TAL_2, TAL_0, TAL_0, 0, 0, cols -1, rows -1);
1305 tab_hline(self->t, TAL_2,0,cols-1,3);
1306 tab_dim (self->t, tab_natural_dimensions);
1310 /* Base finalizer for the trbox */
1312 trbox_base_finalize(struct trbox *trb)
1318 /* Create , populate and submit the Paired Samples Correlation box */
1322 const int rows=1+n_pairs;
1326 struct tab_table *table;
1328 table = tab_create (cols,rows,0);
1330 tab_columns (table, SOM_COL_DOWN, 1);
1331 tab_headers (table,0,0,1,0);
1332 tab_box (table, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, cols -1, rows -1 );
1333 tab_hline(table, TAL_2, 0, cols - 1, 1);
1334 tab_vline(table, TAL_2, 2, 0, rows - 1);
1335 tab_dim(table, tab_natural_dimensions);
1336 tab_title(table, 0, _("Paired Samples Correlations"));
1338 /* column headings */
1339 tab_text(table, 2,0, TAB_CENTER | TAT_TITLE, _("N"));
1340 tab_text(table, 3,0, TAB_CENTER | TAT_TITLE, _("Correlation"));
1341 tab_text(table, 4,0, TAB_CENTER | TAT_TITLE, _("Sig."));
1343 for (i=0; i < n_pairs; ++i)
1351 double df = pairs[i].n -2;
1353 double correlation_t =
1354 pairs[i].correlation * sqrt(df) /
1355 sqrt(1 - sqr(pairs[i].correlation));
1359 tab_text(table, 0,i+1, TAB_LEFT | TAT_TITLE | TAT_PRINTF,
1362 tab_text(table, 1,i+1, TAB_LEFT | TAT_TITLE | TAT_PRINTF,
1363 _("%s & %s"), pairs[i].v[0]->name, pairs[i].v[1]->name);
1367 tab_float(table, 2, i+1, TAB_RIGHT, pairs[i].n, 4, 0);
1368 tab_float(table, 3, i+1, TAB_RIGHT, pairs[i].correlation, 8, 3);
1370 cdft(&which, &p, &q, &correlation_t, &df, &status, &bound);
1373 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1376 tab_float(table, 4, i+1, TAB_RIGHT, 2.0*(correlation_t>0?q:p), 8, 3);
1384 /* Calculation Implementation */
1386 /* Per case calculations common to all variants of the T test */
1388 common_calc (struct ccase *c, void *aux UNUSED)
1392 double weight = dict_get_case_weight(default_dict,c);
1395 /* Skip the entire case if /MISSING=LISTWISE is set */
1396 if ( cmd.miss == TTS_LISTWISE )
1398 for(i=0; i< cmd.n_variables ; ++i)
1400 struct variable *v = cmd.v_variables[i];
1401 union value *val = &c->data[v->fv];
1403 if (value_is_missing(val,v) )
1410 /* Listwise has to be implicit if the independent variable is missing ?? */
1411 if ( cmd.sbc_groups )
1413 union value *gv = &c->data[indep_var->fv];
1414 if ( value_is_missing(gv,indep_var) )
1421 for(i=0; i< cmd.n_variables ; ++i)
1423 struct group_statistics *gs;
1424 struct variable *v = cmd.v_variables[i];
1425 union value *val = &c->data[v->fv];
1427 gs= &cmd.v_variables[i]->p.t_t.ugs;
1429 if (! value_is_missing(val,v) )
1432 gs->sum+=weight * val->f;
1433 gs->ssq+=weight * val->f * val->f;
1439 /* Pre calculations common to all variants of the T test */
1441 common_precalc (void *aux UNUSED)
1445 for(i=0; i< cmd.n_variables ; ++i)
1447 struct group_statistics *gs;
1448 gs= &cmd.v_variables[i]->p.t_t.ugs;
1457 /* Post calculations common to all variants of the T test */
1459 common_postcalc (void *aux UNUSED)
1463 for(i=0; i< cmd.n_variables ; ++i)
1465 struct group_statistics *gs;
1466 gs= &cmd.v_variables[i]->p.t_t.ugs;
1468 gs->mean=gs->sum / gs->n;
1469 gs->s_std_dev= sqrt(
1470 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1475 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1478 gs->se_mean = gs->std_dev / sqrt(gs->n);
1479 gs->mean_diff= gs->sum_diff / gs->n;
1483 /* Per case calculations for one sample t test */
1485 one_sample_calc (struct ccase *c, void *aux UNUSED)
1489 double weight = dict_get_case_weight(default_dict,c);
1491 /* Skip the entire case if /MISSING=LISTWISE is set */
1492 if ( cmd.miss == TTS_LISTWISE )
1494 for(i=0; i< cmd.n_variables ; ++i)
1496 struct variable *v = cmd.v_variables[i];
1497 union value *val = &c->data[v->fv];
1499 if (value_is_missing(val,v) )
1506 for(i=0; i< cmd.n_variables ; ++i)
1508 struct group_statistics *gs;
1509 struct variable *v = cmd.v_variables[i];
1510 union value *val = &c->data[v->fv];
1512 gs= &cmd.v_variables[i]->p.t_t.ugs;
1514 if ( ! value_is_missing(val,v))
1515 gs->sum_diff += weight * (val->f - cmd.n_testval);
1521 /* Pre calculations for one sample t test */
1523 one_sample_precalc (void *aux UNUSED)
1527 for(i=0; i< cmd.n_variables ; ++i)
1529 struct group_statistics *gs;
1530 gs= &cmd.v_variables[i]->p.t_t.ugs;
1536 /* Post calculations for one sample t test */
1538 one_sample_postcalc (void *aux UNUSED)
1542 for(i=0; i< cmd.n_variables ; ++i)
1544 struct group_statistics *gs;
1545 gs= &cmd.v_variables[i]->p.t_t.ugs;
1548 gs->mean_diff = gs->sum_diff / gs->n ;
1555 compare_var_name (const void *a_, const void *b_, void *v_ UNUSED)
1557 const struct variable *a = a_;
1558 const struct variable *b = b_;
1560 return strcmp(a->name,b->name);
1564 hash_var_name (const void *a_, void *v_ UNUSED)
1566 const struct variable *a = a_;
1568 return hsh_hash_bytes (a->name, strlen(a->name));
1574 paired_precalc (void *aux UNUSED)
1578 for(i=0; i < n_pairs ; ++i )
1581 pairs[i].sum[0] = 0; pairs[i].sum[1] = 0;
1582 pairs[i].ssq[0] = 0; pairs[i].ssq[1] = 0;
1583 pairs[i].sum_of_prod = 0;
1584 pairs[i].correlation = 0;
1585 pairs[i].sum_of_diffs = 0;
1586 pairs[i].ssq_diffs = 0;
1593 paired_calc (struct ccase *c, void *aux UNUSED)
1597 double weight = dict_get_case_weight(default_dict,c);
1599 /* Skip the entire case if /MISSING=LISTWISE is set ,
1600 AND one member of a pair is missing */
1601 if ( cmd.miss == TTS_LISTWISE )
1603 for(i=0; i < n_pairs ; ++i )
1605 struct variable *v0 = pairs[i].v[0];
1606 struct variable *v1 = pairs[i].v[1];
1608 union value *val0 = &c->data[v0->fv];
1609 union value *val1 = &c->data[v1->fv];
1611 if ( value_is_missing(val0,v0) ||
1612 value_is_missing(val1,v1) )
1619 for(i=0; i < n_pairs ; ++i )
1621 struct variable *v0 = pairs[i].v[0];
1622 struct variable *v1 = pairs[i].v[1];
1624 union value *val0 = &c->data[v0->fv];
1625 union value *val1 = &c->data[v1->fv];
1627 if ( ( !value_is_missing(val0,v0) && !value_is_missing(val1,v1) ) )
1629 pairs[i].n += weight;
1630 pairs[i].sum[0] += weight * val0->f;
1631 pairs[i].sum[1] += weight * val1->f;
1633 pairs[i].ssq[0] += weight * sqr(val0->f);
1634 pairs[i].ssq[1] += weight * sqr(val1->f);
1637 pairs[i].correlation += weight *
1638 ( val0->f - pairs[i].v[0]->p.t_t.ugs.mean )
1640 ( val1->f - pairs[i].v[1]->p.t_t.ugs.mean );
1643 pairs[i].sum_of_prod += weight * val0->f * val1->f ;
1646 pairs[i].sum_of_diffs += weight * ( val0->f - val1->f ) ;
1647 pairs[i].ssq_diffs += weight * sqr(val0->f - val1->f);
1655 paired_postcalc (void *aux UNUSED)
1659 for(i=0; i < n_pairs ; ++i )
1662 const double n = pairs[i].n;
1664 for (j=0; j < 2 ; ++j)
1666 pairs[i].mean[j] = pairs[i].sum[j] / n ;
1667 pairs[i].s_std_dev[j] = sqrt((pairs[i].ssq[j] / n -
1668 sqr(pairs[i].mean[j]))
1671 pairs[i].std_dev[j] = sqrt(n/(n-1)*(pairs[i].ssq[j] / n -
1672 sqr(pairs[i].mean[j]))
1676 pairs[i].correlation = pairs[i].sum_of_prod / pairs[i].n -
1677 pairs[i].mean[0] * pairs[i].mean[1] ;
1678 /* correlation now actually contains the covariance */
1680 pairs[i].correlation /= pairs[i].std_dev[0] * pairs[i].std_dev[1];
1681 pairs[i].correlation *= pairs[i].n / ( pairs[i].n - 1 );
1684 pairs[i].correlation /= pairs[i].v[0]->p.t_t.ugs.std_dev *
1685 pairs[i].v[1]->p.t_t.ugs.std_dev ;
1686 pairs[i].correlation /= n - 1;
1690 pairs[i].mean_diff = pairs[i].sum_of_diffs / n ;
1693 pairs[i].std_dev_diff = sqrt ( n / (n - 1) * (
1694 ( pairs[i].ssq_diffs / n )
1696 sqr(pairs[i].mean_diff )
1701 /* Return the group # corresponding to the
1702 independent variable with the value val
1705 get_group(const union value *val, struct variable *indep)
1709 for (i = 0; i < 2 ; ++i )
1711 const int cmp = compare_values(val,&groups_values[i],indep->width) ;
1712 switch ( criteria[i])
1715 if ( 0 == cmp ) return i;
1718 if ( 0 > cmp ) return i;
1721 if ( cmp <= 0 ) return i;
1724 if ( cmp > 0 ) return i;
1727 if ( cmp >= 0 ) return i;
1734 /* No groups matched */
1740 group_precalc (void *aux UNUSED)
1745 for(i=0; i< cmd.n_variables ; ++i)
1747 struct t_test_proc *ttpr = &cmd.v_variables[i]->p.t_t;
1749 /* There's always 2 groups for a T - TEST */
1751 ttpr->gs = xmalloc(sizeof(struct group_statistics) * 2) ;
1753 for (j=0 ; j < 2 ; ++j)
1755 ttpr->gs[j].sum = 0;
1757 ttpr->gs[j].ssq = 0;
1759 if ( n_group_values == 2 )
1760 ttpr->gs[j].id = groups_values[j];
1762 ttpr->gs[j].id = groups_values[0];
1763 ttpr->gs[j].criterion = criteria[j];
1770 group_calc (struct ccase *c, void *aux UNUSED)
1774 union value *gv = &c->data[indep_var->fv];
1776 double weight = dict_get_case_weight(default_dict,c);
1778 if ( value_is_missing(gv,indep_var) )
1783 if ( cmd.miss == TTS_LISTWISE )
1785 for(i=0; i< cmd.n_variables ; ++i)
1787 struct variable *v = cmd.v_variables[i];
1788 union value *val = &c->data[v->fv];
1790 if (value_is_missing(val,v) )
1798 gv = &c->data[indep_var->fv];
1800 g = get_group(gv,indep_var);
1802 /* If the independent variable doesn't match either of the values
1803 for this case then move on to the next case */
1807 for(i=0; i< cmd.n_variables ; ++i)
1809 struct variable *var = cmd.v_variables[i];
1811 struct group_statistics *gs = &var->p.t_t.gs[g];
1813 union value *val=&c->data[var->fv];
1815 if ( !value_is_missing(val,var) )
1818 gs->sum+=weight * val->f;
1819 gs->ssq+=weight * sqr(val->f);
1828 group_postcalc (void *aux UNUSED)
1833 for(i=0; i< cmd.n_variables ; ++i)
1835 for (j=0 ; j < 2 ; ++j)
1837 struct group_statistics *gs;
1838 gs=&cmd.v_variables[i]->p.t_t.gs[j];
1840 gs->mean = gs->sum / gs->n;
1842 gs->s_std_dev= sqrt(
1843 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1848 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1851 gs->se_mean = gs->std_dev / sqrt(gs->n);