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 (!lex_force_match_id ("T"))
220 lex_match_id ("TEST");
222 if ( !parse_t_test(&cmd) )
225 if (! cmd.sbc_criteria)
230 if (cmd.sbc_testval) ++m;
231 if (cmd.sbc_groups) ++m;
232 if (cmd.sbc_pairs) ++m;
237 _("TESTVAL, GROUPS and PAIRS subcommands are mutually exclusive.")
245 else if (cmd.sbc_groups)
250 if ( mode == T_PAIRED)
252 if (cmd.sbc_variables)
254 msg(SE, _("VARIABLES subcommand is not appropriate with PAIRS"));
259 /* Iterate through the pairs and put each variable that is a
260 member of a pair into cmd.v_variables */
263 struct hsh_iterator hi;
264 struct hsh_table *hash;
267 hash=hsh_create(n_pairs,compare_var_name,hash_var_name,0,0);
269 for (i=0; i < n_pairs; ++i)
271 hsh_insert(hash,pairs[i].v[0]);
272 hsh_insert(hash,pairs[i].v[1]);
275 assert(cmd.n_variables == 0);
276 cmd.n_variables = hsh_count(hash);
278 cmd.v_variables = xrealloc(cmd.v_variables,
279 sizeof(struct variable) * cmd.n_variables);
280 /* Iterate through the hash */
281 for (i=0,v = (struct variable *) hsh_first(hash,&hi);
283 v=hsh_next(hash,&hi) )
284 cmd.v_variables[i++]=v;
290 /* If /MISSING=INCLUDE is set, then user missing values are ignored */
291 if (cmd.incl == TTS_INCLUDE )
292 value_is_missing = is_system_missing;
294 value_is_missing = is_missing;
296 procedure_with_splits (common_precalc, common_calc, common_postcalc, NULL);
301 procedure_with_splits (one_sample_precalc, one_sample_calc,
302 one_sample_postcalc, NULL);
305 procedure_with_splits (paired_precalc, paired_calc, paired_postcalc,
309 procedure_with_splits(group_precalc,group_calc,group_postcalc, NULL);
310 levene(indep_var, cmd.n_variables, cmd.v_variables,
311 (cmd.miss == TTS_LISTWISE)?LEV_LISTWISE:LEV_ANALYSIS ,
316 ssbox_create(&stat_summary_box,&cmd,mode);
317 ssbox_populate(&stat_summary_box,&cmd);
318 ssbox_finalize(&stat_summary_box);
320 if ( mode == T_PAIRED)
323 trbox_create(&test_results_box,&cmd,mode);
324 trbox_populate(&test_results_box,&cmd);
325 trbox_finalize(&test_results_box);
331 if ( mode == T_IND_SAMPLES)
334 /* Destroy any group statistics we created */
335 for (i= 0 ; i < cmd.n_variables ; ++i )
337 free(cmd.v_variables[i]->p.t_t.gs);
345 tts_custom_groups (struct cmd_t_test *cmd UNUSED)
350 if (token != T_ALL &&
351 (token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
354 msg(SE,_("`%s' is not a variable name"),tokid);
358 indep_var = parse_variable ();
361 lex_error ("expecting variable name in GROUPS subcommand");
365 if (indep_var->type == T_STRING && indep_var->width > MAX_SHORT_STRING)
367 msg (SE, _("Long string variable %s is not valid here."),
372 if (!lex_match ('('))
374 if (indep_var->type == NUMERIC)
376 groups_values[0].f = 1;
377 groups_values[1].f = 2;
378 criteria[0] = criteria[1] = CMP_EQ;
384 msg (SE, _("When applying GROUPS to a string variable, at "
385 "least one value must be specified."));
390 if (!parse_value (&groups_values[0],indep_var->type))
396 criteria[0] = CMP_LE;
397 criteria[1] = CMP_GT;
398 groups_values[1] = groups_values[0];
403 if (!parse_value (&groups_values[1],indep_var->type))
407 if (!lex_force_match (')'))
410 criteria[0] = criteria[1] = CMP_EQ;
416 tts_custom_pairs (struct cmd_t_test *cmd UNUSED)
418 struct variable **vars;
423 int n_after_WITH = -1;
424 int paired ; /* Was the PAIRED keyword given ? */
428 if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
431 msg(SE,_("`%s' is not a variable name"),tokid);
436 if (!parse_variables (default_dict, &vars, &n_vars,
437 PV_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH))
445 if (lex_match (T_WITH))
447 n_before_WITH = n_vars;
448 if (!parse_variables (default_dict, &vars, &n_vars,
449 PV_DUPLICATE | PV_APPEND
450 | PV_NUMERIC | PV_NO_SCRATCH))
455 n_after_WITH = n_vars - n_before_WITH;
458 paired = (lex_match ('(') && lex_match_id ("PAIRED") && lex_match (')'));
460 /* Determine the number of pairs needed */
463 if (n_before_WITH != n_after_WITH)
466 msg (SE, _("PAIRED was specified but the number of variables "
467 "preceding WITH (%d) did not match the number "
469 n_before_WITH, n_after_WITH );
472 n_pairs_local=n_before_WITH;
474 else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */
476 n_pairs_local=n_before_WITH * n_after_WITH ;
478 else /* Neither WITH nor PAIRED keyword given */
483 msg (SE, _("At least two variables must be specified "
488 /* how many ways can you pick 2 from n_vars ? */
489 n_pairs_local = n_vars * (n_vars -1 ) /2 ;
493 /* Allocate storage for the pairs */
494 pairs = xrealloc(pairs, sizeof(struct pair) * (n_pairs + n_pairs_local) );
496 /* Populate the pairs with the appropriate variables */
501 assert(n_pairs_local == n_vars/2);
502 for (i = 0; i < n_pairs_local ; ++i)
504 pairs[i].v[n_pairs+0] = vars[i];
505 pairs[i].v[n_pairs+1] = vars[i+n_pairs_local];
508 else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */
513 for(i=0 ; i < n_before_WITH ; ++i )
515 for(j=0 ; j < n_after_WITH ; ++j)
517 pairs[p].v[0] = vars[i];
518 pairs[p].v[1] = vars[j+n_before_WITH];
523 else /* Neither WITH nor PAIRED given */
528 for(i=0 ; i < n_vars ; ++i )
530 for(j=i+1 ; j < n_vars ; ++j)
532 pairs[p].v[0] = vars[i];
533 pairs[p].v[1] = vars[j];
539 n_pairs+=n_pairs_local;
544 /* Parses the current token (numeric or string, depending on type)
545 value v and returns success. */
547 parse_value (union value * v, int type )
551 if (!lex_force_num ())
557 if (!lex_force_string ())
559 strncpy (v->s, ds_value (&tokstr), ds_length (&tokstr));
568 /* Implementation of the SSBOX object */
570 void ssbox_base_init(struct ssbox *this, int cols,int rows);
572 void ssbox_base_finalize(struct ssbox *ssb);
574 void ssbox_one_sample_init(struct ssbox *this,
575 struct cmd_t_test *cmd );
577 void ssbox_independent_samples_init(struct ssbox *this,
578 struct cmd_t_test *cmd);
580 void ssbox_paired_init(struct ssbox *this,
581 struct cmd_t_test *cmd);
583 /* Factory to create an ssbox */
585 ssbox_create(struct ssbox *ssb, struct cmd_t_test *cmd, int mode)
590 ssbox_one_sample_init(ssb,cmd);
593 ssbox_independent_samples_init(ssb,cmd);
596 ssbox_paired_init(ssb,cmd);
604 /* Despatcher for the populate method */
606 ssbox_populate(struct ssbox *ssb,struct cmd_t_test *cmd)
608 ssb->populate(ssb,cmd);
612 /* Despatcher for finalize */
614 ssbox_finalize(struct ssbox *ssb)
620 /* Submit the box and clear up */
622 ssbox_base_finalize(struct ssbox *ssb)
627 /* Initialize a ssbox struct */
629 ssbox_base_init(struct ssbox *this, int cols,int rows)
631 this->finalize = ssbox_base_finalize;
632 this->t = tab_create (cols, rows, 0);
634 tab_columns (this->t, SOM_COL_DOWN, 1);
635 tab_headers (this->t,0,0,1,0);
636 tab_box (this->t, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, cols -1, rows -1 );
637 tab_hline(this->t, TAL_2,0,cols-1,1);
638 tab_dim (this->t, tab_natural_dimensions);
641 void ssbox_one_sample_populate(struct ssbox *ssb,
642 struct cmd_t_test *cmd);
644 /* Initialize the one_sample ssbox */
646 ssbox_one_sample_init(struct ssbox *this,
647 struct cmd_t_test *cmd )
650 const int vsize=cmd->n_variables+1;
652 this->populate = ssbox_one_sample_populate;
654 ssbox_base_init(this, hsize,vsize);
655 tab_title (this->t, 0, _("One-Sample Statistics"));
656 tab_vline(this->t, TAL_2, 1,0,vsize);
657 tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, _("N"));
658 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
659 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
660 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
663 void ssbox_independent_samples_populate(struct ssbox *ssb,
664 struct cmd_t_test *cmd);
666 /* Initialize the independent samples ssbox */
668 ssbox_independent_samples_init(struct ssbox *this,
669 struct cmd_t_test *cmd)
672 int vsize = cmd->n_variables*2 +1;
674 this->populate = ssbox_independent_samples_populate;
676 ssbox_base_init(this, hsize,vsize);
677 tab_title (this->t, 0, _("Group Statistics"));
678 tab_vline(this->t,0,1,0,vsize);
679 tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, indep_var->name);
680 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("N"));
681 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
682 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
683 tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
687 /* Populate the ssbox for independent samples */
689 ssbox_independent_samples_populate(struct ssbox *ssb,
690 struct cmd_t_test *cmd)
697 char prefix[2][3]={"",""};
699 if ( indep_var->type == NUMERIC )
701 val_lab0 = val_labs_find( indep_var->val_labs,groups_values[0]);
702 val_lab1 = val_labs_find( indep_var->val_labs,groups_values[1]);
706 val_lab0 = groups_values[0].s;
707 val_lab1 = groups_values[1].s;
710 if (n_group_values == 1)
712 strcpy(prefix[0],"< ");
713 strcpy(prefix[1],">=");
718 for (i=0; i < cmd->n_variables; ++i)
722 tab_text (ssb->t, 0, i*2+1, TAB_LEFT, cmd->v_variables[i]->name);
725 tab_text (ssb->t, 1, i*2+1, TAB_LEFT | TAT_PRINTF,
726 "%s%s", prefix[0], val_lab0);
728 tab_text (ssb->t, 1, i*2+1, TAB_LEFT | TAT_PRINTF,
729 "%s%g", prefix[0], groups_values[0].f);
733 tab_text (ssb->t, 1, i*2+1+1, TAB_LEFT | TAT_PRINTF,
734 "%s%s", prefix[1], val_lab1);
736 tab_text (ssb->t, 1, i*2+1+1, TAB_LEFT | TAT_PRINTF,
737 "%s%g", prefix[1], groups_values[1].f);
739 /* Fill in the group statistics */
740 for ( g=0; g < 2 ; ++g )
742 struct group_statistics *gs = &cmd->v_variables[i]->p.t_t.gs[g];
744 tab_float(ssb->t, 2 ,i*2+g+1, TAB_RIGHT, gs->n, 2, 0);
745 tab_float(ssb->t, 3 ,i*2+g+1, TAB_RIGHT, gs->mean, 8, 2);
746 tab_float(ssb->t, 4 ,i*2+g+1, TAB_RIGHT, gs->std_dev, 8, 3);
747 tab_float(ssb->t, 5 ,i*2+g+1, TAB_RIGHT, gs->se_mean, 8, 3);
753 void ssbox_paired_populate(struct ssbox *ssb,
754 struct cmd_t_test *cmd);
756 /* Initialize the paired values ssbox */
758 ssbox_paired_init(struct ssbox *this, struct cmd_t_test *cmd UNUSED)
762 int vsize = n_pairs*2+1;
764 this->populate = ssbox_paired_populate;
766 ssbox_base_init(this, hsize,vsize);
767 tab_title (this->t, 0, _("Paired Sample Statistics"));
768 tab_vline(this->t,TAL_0,1,0,vsize-1);
769 tab_vline(this->t,TAL_2,2,0,vsize-1);
770 tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean"));
771 tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("N"));
772 tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
773 tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean"));
777 /* Populate the ssbox for paired values */
779 ssbox_paired_populate(struct ssbox *ssb,struct cmd_t_test *cmd UNUSED)
785 for (i=0; i < n_pairs; ++i)
789 tab_text (ssb->t, 0, i*2+1, TAB_LEFT | TAT_PRINTF , _("Pair %d"),i);
791 for (j=0 ; j < 2 ; ++j)
793 struct group_statistics *gs;
795 gs=&pairs[i].v[j]->p.t_t.ugs;
799 tab_text (ssb->t, 1, i*2+j+1, TAB_LEFT, pairs[i].v[j]->name);
802 tab_float (ssb->t,2, i*2+j+1, TAB_RIGHT, pairs[i].mean[j], 8, 2);
803 tab_float (ssb->t,3, i*2+j+1, TAB_RIGHT, pairs[i].n, 2, 0);
804 tab_float (ssb->t,4, i*2+j+1, TAB_RIGHT, pairs[i].std_dev[j], 8, 3);
805 tab_float (ssb->t,5, i*2+j+1, TAB_RIGHT, pairs[i].std_dev[j]/sqrt(pairs[i].n), 8, 3);
811 /* Populate the one sample ssbox */
813 ssbox_one_sample_populate(struct ssbox *ssb, struct cmd_t_test *cmd)
819 for (i=0; i < cmd->n_variables; ++i)
821 struct group_statistics *gs;
822 gs= &cmd->v_variables[i]->p.t_t.ugs;
824 tab_text (ssb->t, 0, i+1, TAB_LEFT, cmd->v_variables[i]->name);
825 tab_float (ssb->t,1, i+1, TAB_RIGHT, gs->n, 2, 0);
826 tab_float (ssb->t,2, i+1, TAB_RIGHT, gs->mean, 8, 2);
827 tab_float (ssb->t,3, i+1, TAB_RIGHT, gs->std_dev, 8, 2);
828 tab_float (ssb->t,4, i+1, TAB_RIGHT, gs->se_mean, 8, 3);
835 /* Implementation of the Test Results box struct */
837 void trbox_base_init(struct trbox *self,int n_vars, int cols);
838 void trbox_base_finalize(struct trbox *trb);
840 void trbox_independent_samples_init(struct trbox *trb,
841 struct cmd_t_test *cmd );
843 void trbox_independent_samples_populate(struct trbox *trb,
844 struct cmd_t_test *cmd);
846 void trbox_one_sample_init(struct trbox *self,
847 struct cmd_t_test *cmd );
849 void trbox_one_sample_populate(struct trbox *trb,
850 struct cmd_t_test *cmd);
852 void trbox_paired_init(struct trbox *self,
853 struct cmd_t_test *cmd );
855 void trbox_paired_populate(struct trbox *trb,
856 struct cmd_t_test *cmd);
860 /* Create a trbox according to mode*/
862 trbox_create(struct trbox *trb,
863 struct cmd_t_test *cmd, int mode)
868 trbox_one_sample_init(trb,cmd);
871 trbox_independent_samples_init(trb,cmd);
874 trbox_paired_init(trb,cmd);
881 /* Populate a trbox according to cmd */
883 trbox_populate(struct trbox *trb, struct cmd_t_test *cmd)
885 trb->populate(trb,cmd);
888 /* Submit and destroy a trbox */
890 trbox_finalize(struct trbox *trb)
895 /* Initialize the independent samples trbox */
897 trbox_independent_samples_init(struct trbox *self,
898 struct cmd_t_test *cmd UNUSED)
901 const int vsize=cmd->n_variables*2+3;
904 self->populate = trbox_independent_samples_populate;
906 trbox_base_init(self,cmd->n_variables*2,hsize);
907 tab_title(self->t,0,_("Independent Samples Test"));
908 tab_hline(self->t,TAL_1,2,hsize-1,1);
909 tab_vline(self->t,TAL_2,2,0,vsize-1);
910 tab_vline(self->t,TAL_1,4,0,vsize-1);
911 tab_box(self->t,-1,-1,-1,TAL_1, 2,1,hsize-2,vsize-1);
912 tab_hline(self->t,TAL_1, hsize-2,hsize-1,2);
913 tab_box(self->t,-1,-1,-1,TAL_1, hsize-2,2,hsize-1,vsize-1);
914 tab_joint_text(self->t, 2, 0, 3, 0,
915 TAB_CENTER,_("Levene's Test for Equality of Variances"));
916 tab_joint_text(self->t, 4,0,hsize-1,0,
917 TAB_CENTER,_("t-test for Equality of Means"));
919 tab_text(self->t,2,2, TAB_CENTER | TAT_TITLE,_("F"));
920 tab_text(self->t,3,2, TAB_CENTER | TAT_TITLE,_("Sig."));
921 tab_text(self->t,4,2, TAB_CENTER | TAT_TITLE,_("t"));
922 tab_text(self->t,5,2, TAB_CENTER | TAT_TITLE,_("df"));
923 tab_text(self->t,6,2, TAB_CENTER | TAT_TITLE,_("Sig. (2-tailed)"));
924 tab_text(self->t,7,2, TAB_CENTER | TAT_TITLE,_("Mean Difference"));
925 tab_text(self->t,8,2, TAB_CENTER | TAT_TITLE,_("Std. Error Difference"));
926 tab_text(self->t,9,2, TAB_CENTER | TAT_TITLE,_("Lower"));
927 tab_text(self->t,10,2, TAB_CENTER | TAT_TITLE,_("Upper"));
929 tab_joint_text(self->t, 9, 1, 10, 1, TAB_CENTER | TAT_PRINTF,
930 _("%d%% Confidence Interval of the Difference"),
931 (int)round(cmd->criteria*100.0));
935 /* Populate the independent samples trbox */
937 trbox_independent_samples_populate(struct trbox *self,
938 struct cmd_t_test *cmd )
943 for (i=0; i < cmd->n_variables; ++i)
955 double pooled_variance;
959 struct group_statistics *gs0 = &cmd->v_variables[i]->p.t_t.gs[0];
960 struct group_statistics *gs1 = &cmd->v_variables[i]->p.t_t.gs[1];
962 tab_text (self->t, 0, i*2+3, TAB_LEFT, cmd->v_variables[i]->name);
964 tab_text (self->t, 1, i*2+3, TAB_LEFT, _("Equal variances assumed"));
967 tab_float(self->t, 2, i*2+3, TAB_CENTER,
968 cmd->v_variables[i]->p.t_t.levene, 8,3);
971 /* Now work out the significance of the Levene test */
973 which=1; df1 = 1; df2 = cmd->v_variables[i]->p.t_t.ugs.n - 2;
974 cdff(&which,&p,&q,&cmd->v_variables[i]->p.t_t.levene,
975 &df1,&df2,&status,&bound);
979 msg( SE, _("Error calculating F statistic (cdff returned %d)."),status);
982 tab_float(self->t, 3, i*2+3, TAB_CENTER, q, 8,3 );
984 df = gs0->n + gs1->n - 2.0 ;
985 tab_float (self->t, 5, i*2+3, TAB_RIGHT, df, 2, 0);
987 pooled_variance = ( (gs0->n )*sqr(gs0->s_std_dev)
989 (gs1->n )*sqr(gs1->s_std_dev)
992 t = (gs0->mean - gs1->mean) / sqrt(pooled_variance) ;
993 t /= sqrt((gs0->n + gs1->n)/(gs0->n*gs1->n));
995 tab_float (self->t, 4, i*2+3, TAB_RIGHT, t, 8, 3);
998 which=1; /* get p & q from t & df */
999 cdft(&which, &p, &q, &t, &df, &status, &bound);
1002 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1005 tab_float(self->t, 6, i*2+3, TAB_RIGHT, 2.0*(t>0?q:p) , 8, 3);
1007 mean_diff = gs0->mean - gs1->mean;
1008 tab_float(self->t, 7, i*2+3, TAB_RIGHT, mean_diff, 8, 3);
1011 std_err_diff = sqrt( sqr(gs0->se_mean) + sqr(gs1->se_mean));
1012 tab_float(self->t, 8, i*2+3, TAB_RIGHT, std_err_diff, 8, 3);
1015 /* Now work out the confidence interval */
1016 q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
1018 which=2; /* Calc T from p,q and df */
1019 cdft(&which, &p, &q, &t, &df, &status, &bound);
1022 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1025 tab_float(self->t, 9, i*2+3, TAB_RIGHT,
1026 mean_diff - t * std_err_diff, 8, 3);
1028 tab_float(self->t, 10, i*2+3, TAB_RIGHT,
1029 mean_diff + t * std_err_diff, 8, 3);
1034 /* Now for the \sigma_1 != \sigma_2 case */
1035 tab_text (self->t, 1, i*2+3+1,
1036 TAB_LEFT, _("Equal variances not assumed"));
1039 se2 = (sqr(gs0->s_std_dev)/(gs0->n -1) ) +
1040 (sqr(gs1->s_std_dev)/(gs1->n -1) );
1042 t = mean_diff / sqrt(se2) ;
1043 tab_float (self->t, 4, i*2+3+1, TAB_RIGHT, t, 8, 3);
1046 (sqr(sqr(gs0->s_std_dev)/(gs0->n - 1 ))
1050 (sqr(sqr(gs1->s_std_dev)/(gs1->n - 1 ))
1054 tab_float (self->t, 5, i*2+3+1, TAB_RIGHT, df, 8, 3);
1056 which=1; /* get p & q from t & df */
1057 cdft(&which, &p, &q, &t, &df, &status, &bound);
1060 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1063 tab_float(self->t, 6, i*2+3+1, TAB_RIGHT, 2.0*(t>0?q:p) , 8, 3);
1065 /* Now work out the confidence interval */
1066 q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
1068 which=2; /* Calc T from p,q and df */
1069 cdft(&which, &p, &q, &t, &df, &status, &bound);
1072 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1076 tab_float(self->t, 7, i*2+3+1, TAB_RIGHT, mean_diff, 8, 3);
1079 tab_float(self->t, 8, i*2+3+1, TAB_RIGHT, std_err_diff, 8, 3);
1082 tab_float(self->t, 9, i*2+3+1, TAB_RIGHT,
1083 mean_diff - t * std_err_diff, 8, 3);
1085 tab_float(self->t, 10, i*2+3+1, TAB_RIGHT,
1086 mean_diff + t * std_err_diff, 8, 3);
1092 /* Initialize the paired samples trbox */
1094 trbox_paired_init(struct trbox *self,
1095 struct cmd_t_test *cmd UNUSED)
1099 const int vsize=n_pairs+3;
1101 self->populate = trbox_paired_populate;
1103 trbox_base_init(self,n_pairs,hsize);
1104 tab_title (self->t, 0, _("Paired Samples Test"));
1105 tab_hline(self->t,TAL_1,2,6,1);
1106 tab_vline(self->t,TAL_2,2,0,vsize);
1107 tab_joint_text(self->t,2,0,6,0,TAB_CENTER,_("Paired Differences"));
1108 tab_box(self->t,-1,-1,-1,TAL_1, 2,1,6,vsize-1);
1109 tab_box(self->t,-1,-1,-1,TAL_1, 6,0,hsize-1,vsize-1);
1110 tab_hline(self->t,TAL_1,5,6, 2);
1111 tab_vline(self->t,TAL_0,6,0,1);
1113 tab_joint_text(self->t, 5, 1, 6, 1, TAB_CENTER | TAT_PRINTF,
1114 _("%d%% Confidence Interval of the Difference"),
1115 (int)round(cmd->criteria*100.0));
1117 tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("Mean"));
1118 tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
1119 tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Std. Error Mean"));
1120 tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
1121 tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
1122 tab_text (self->t, 7, 2, TAB_CENTER | TAT_TITLE, _("t"));
1123 tab_text (self->t, 8, 2, TAB_CENTER | TAT_TITLE, _("df"));
1124 tab_text (self->t, 9, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
1127 /* Populate the paired samples trbox */
1129 trbox_paired_populate(struct trbox *trb,
1130 struct cmd_t_test *cmd UNUSED)
1134 for (i=0; i < n_pairs; ++i)
1142 double n = pairs[i].n;
1146 tab_text (trb->t, 0, i+3, TAB_LEFT | TAT_PRINTF, _("Pair %d"),i);
1148 tab_text (trb->t, 1, i+3, TAB_LEFT | TAT_PRINTF, "%s - %s",
1149 pairs[i].v[0]->name, pairs[i].v[1]->name);
1151 tab_float(trb->t, 2, i+3, TAB_RIGHT, pairs[i].mean_diff, 8, 4);
1153 tab_float(trb->t, 3, i+3, TAB_RIGHT, pairs[i].std_dev_diff, 8, 5);
1156 se_mean = pairs[i].std_dev_diff / sqrt(n) ;
1157 tab_float(trb->t, 4, i+3, TAB_RIGHT, se_mean, 8,5 );
1159 /* Now work out the confidence interval */
1160 q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
1162 which=2; /* Calc T from p,q and df */
1163 cdft(&which, &p, &q, &t, &df, &status, &bound);
1167 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1170 tab_float(trb->t, 5, i+3, TAB_RIGHT,
1171 pairs[i].mean_diff - t * se_mean , 8, 4);
1173 tab_float(trb->t, 6, i+3, TAB_RIGHT,
1174 pairs[i].mean_diff + t * se_mean , 8, 4);
1176 t = (pairs[i].mean[0] - pairs[i].mean[1])
1178 ( sqr (pairs[i].s_std_dev[0]) + sqr (pairs[i].s_std_dev[1]) -
1179 2 * pairs[i].correlation *
1180 pairs[i].s_std_dev[0] * pairs[i].s_std_dev[1] )
1184 tab_float(trb->t, 7, i+3, TAB_RIGHT, t , 8,3 );
1186 /* Degrees of freedom */
1187 tab_float(trb->t, 8, i+3, TAB_RIGHT, df , 2, 0 );
1190 cdft(&which, &p, &q, &t, &df, &status, &bound);
1193 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1197 tab_float(trb->t, 9, i+3, TAB_RIGHT, 2.0*(t>0?q:p) , 8, 3);
1202 /* Initialize the one sample trbox */
1204 trbox_one_sample_init(struct trbox *self, struct cmd_t_test *cmd )
1207 const int vsize=cmd->n_variables+3;
1209 self->populate = trbox_one_sample_populate;
1211 trbox_base_init(self, cmd->n_variables,hsize);
1212 tab_title (self->t, 0, _("One-Sample Test"));
1213 tab_hline(self->t, TAL_1, 1, hsize - 1, 1);
1214 tab_vline(self->t, TAL_2, 1, 0, vsize);
1216 tab_joint_text(self->t, 1, 0, hsize-1,0, TAB_CENTER | TAT_PRINTF,
1217 _("Test Value = %f"),cmd->n_testval);
1219 tab_box(self->t, -1, -1, -1, TAL_1, 1,1,hsize-1,vsize-1);
1222 tab_joint_text(self->t,5,1,6,1,TAB_CENTER | TAT_PRINTF,
1223 _("%d%% Confidence Interval of the Difference"),
1224 (int)round(cmd->criteria*100.0));
1226 tab_vline(self->t,TAL_0,6,1,1);
1227 tab_hline(self->t,TAL_1,5,6,2);
1228 tab_text (self->t, 1, 2, TAB_CENTER | TAT_TITLE, _("t"));
1229 tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("df"));
1230 tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
1231 tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Mean Difference"));
1232 tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
1233 tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
1238 /* Populate the one sample trbox */
1240 trbox_one_sample_populate(struct trbox *trb, struct cmd_t_test *cmd)
1246 for (i=0; i < cmd->n_variables; ++i)
1254 struct group_statistics *gs;
1255 gs= &cmd->v_variables[i]->p.t_t.ugs;
1258 tab_text (trb->t, 0, i+3, TAB_LEFT, cmd->v_variables[i]->name);
1260 t = (gs->mean - cmd->n_testval ) * sqrt(gs->n) / gs->std_dev ;
1262 tab_float (trb->t, 1, i+3, TAB_RIGHT, t, 8,3);
1264 /* degrees of freedom */
1267 tab_float (trb->t, 2, i+3, TAB_RIGHT, df, 8,0);
1269 cdft(&which, &p, &q, &t, &df, &status, &bound);
1273 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1277 /* Multiply by 2 to get 2-tailed significance, makeing sure we've got
1279 tab_float (trb->t, 3, i+3, TAB_RIGHT, 2.0*(t>0?q:p), 8,3);
1281 tab_float (trb->t, 4, i+3, TAB_RIGHT, gs->mean_diff, 8,3);
1284 q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
1286 which=2; /* Calc T from p,q and df */
1287 cdft(&which, &p, &q, &t, &df, &status, &bound);
1290 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1293 tab_float (trb->t, 5, i+3, TAB_RIGHT,
1294 gs->mean_diff - t * gs->se_mean, 8,4);
1296 tab_float (trb->t, 6, i+3, TAB_RIGHT,
1297 gs->mean_diff + t * gs->se_mean, 8,4);
1301 /* Base initializer for the generalized trbox */
1303 trbox_base_init(struct trbox *self, int data_rows, int cols)
1305 const int rows = 3 + data_rows;
1307 self->finalize = trbox_base_finalize;
1308 self->t = tab_create (cols, rows, 0);
1309 tab_headers (self->t,0,0,3,0);
1310 tab_box (self->t, TAL_2, TAL_2, TAL_0, TAL_0, 0, 0, cols -1, rows -1);
1311 tab_hline(self->t, TAL_2,0,cols-1,3);
1312 tab_dim (self->t, tab_natural_dimensions);
1316 /* Base finalizer for the trbox */
1318 trbox_base_finalize(struct trbox *trb)
1324 /* Create , populate and submit the Paired Samples Correlation box */
1328 const int rows=1+n_pairs;
1332 struct tab_table *table;
1334 table = tab_create (cols,rows,0);
1336 tab_columns (table, SOM_COL_DOWN, 1);
1337 tab_headers (table,0,0,1,0);
1338 tab_box (table, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, cols -1, rows -1 );
1339 tab_hline(table, TAL_2, 0, cols - 1, 1);
1340 tab_vline(table, TAL_2, 2, 0, rows - 1);
1341 tab_dim(table, tab_natural_dimensions);
1342 tab_title(table, 0, _("Paired Samples Correlations"));
1344 /* column headings */
1345 tab_text(table, 2,0, TAB_CENTER | TAT_TITLE, _("N"));
1346 tab_text(table, 3,0, TAB_CENTER | TAT_TITLE, _("Correlation"));
1347 tab_text(table, 4,0, TAB_CENTER | TAT_TITLE, _("Sig."));
1349 for (i=0; i < n_pairs; ++i)
1357 double df = pairs[i].n -2;
1359 double correlation_t =
1360 pairs[i].correlation * sqrt(df) /
1361 sqrt(1 - sqr(pairs[i].correlation));
1365 tab_text(table, 0,i+1, TAB_LEFT | TAT_TITLE | TAT_PRINTF,
1368 tab_text(table, 1,i+1, TAB_LEFT | TAT_TITLE | TAT_PRINTF,
1369 _("%s & %s"), pairs[i].v[0]->name, pairs[i].v[1]->name);
1373 tab_float(table, 2, i+1, TAB_RIGHT, pairs[i].n, 4, 0);
1374 tab_float(table, 3, i+1, TAB_RIGHT, pairs[i].correlation, 8, 3);
1376 cdft(&which, &p, &q, &correlation_t, &df, &status, &bound);
1379 msg( SE, _("Error calculating T statistic (cdft returned %d)."),status);
1382 tab_float(table, 4, i+1, TAB_RIGHT, 2.0*(correlation_t>0?q:p), 8, 3);
1390 /* Calculation Implementation */
1392 /* Per case calculations common to all variants of the T test */
1394 common_calc (struct ccase *c, void *aux UNUSED)
1398 double weight = dict_get_case_weight(default_dict,c);
1401 /* Skip the entire case if /MISSING=LISTWISE is set */
1402 if ( cmd.miss == TTS_LISTWISE )
1404 for(i=0; i< cmd.n_variables ; ++i)
1406 struct variable *v = cmd.v_variables[i];
1407 union value *val = &c->data[v->fv];
1409 if (value_is_missing(val,v) )
1416 /* Listwise has to be implicit if the independent variable is missing ?? */
1417 if ( cmd.sbc_groups )
1419 union value *gv = &c->data[indep_var->fv];
1420 if ( value_is_missing(gv,indep_var) )
1427 for(i=0; i< cmd.n_variables ; ++i)
1429 struct group_statistics *gs;
1430 struct variable *v = cmd.v_variables[i];
1431 union value *val = &c->data[v->fv];
1433 gs= &cmd.v_variables[i]->p.t_t.ugs;
1435 if (! value_is_missing(val,v) )
1438 gs->sum+=weight * val->f;
1439 gs->ssq+=weight * val->f * val->f;
1445 /* Pre calculations common to all variants of the T test */
1447 common_precalc (void *aux UNUSED)
1451 for(i=0; i< cmd.n_variables ; ++i)
1453 struct group_statistics *gs;
1454 gs= &cmd.v_variables[i]->p.t_t.ugs;
1463 /* Post calculations common to all variants of the T test */
1465 common_postcalc (void *aux UNUSED)
1469 for(i=0; i< cmd.n_variables ; ++i)
1471 struct group_statistics *gs;
1472 gs= &cmd.v_variables[i]->p.t_t.ugs;
1474 gs->mean=gs->sum / gs->n;
1475 gs->s_std_dev= sqrt(
1476 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1481 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1484 gs->se_mean = gs->std_dev / sqrt(gs->n);
1485 gs->mean_diff= gs->sum_diff / gs->n;
1489 /* Per case calculations for one sample t test */
1491 one_sample_calc (struct ccase *c, void *aux UNUSED)
1495 double weight = dict_get_case_weight(default_dict,c);
1497 /* Skip the entire case if /MISSING=LISTWISE is set */
1498 if ( cmd.miss == TTS_LISTWISE )
1500 for(i=0; i< cmd.n_variables ; ++i)
1502 struct variable *v = cmd.v_variables[i];
1503 union value *val = &c->data[v->fv];
1505 if (value_is_missing(val,v) )
1512 for(i=0; i< cmd.n_variables ; ++i)
1514 struct group_statistics *gs;
1515 struct variable *v = cmd.v_variables[i];
1516 union value *val = &c->data[v->fv];
1518 gs= &cmd.v_variables[i]->p.t_t.ugs;
1520 if ( ! value_is_missing(val,v))
1521 gs->sum_diff += weight * (val->f - cmd.n_testval);
1527 /* Pre calculations for one sample t test */
1529 one_sample_precalc (void *aux UNUSED)
1533 for(i=0; i< cmd.n_variables ; ++i)
1535 struct group_statistics *gs;
1536 gs= &cmd.v_variables[i]->p.t_t.ugs;
1542 /* Post calculations for one sample t test */
1544 one_sample_postcalc (void *aux UNUSED)
1548 for(i=0; i< cmd.n_variables ; ++i)
1550 struct group_statistics *gs;
1551 gs= &cmd.v_variables[i]->p.t_t.ugs;
1554 gs->mean_diff = gs->sum_diff / gs->n ;
1561 compare_var_name (const void *a_, const void *b_, void *v_ UNUSED)
1563 const struct variable *a = a_;
1564 const struct variable *b = b_;
1566 return strcmp(a->name,b->name);
1570 hash_var_name (const void *a_, void *v_ UNUSED)
1572 const struct variable *a = a_;
1574 return hsh_hash_bytes (a->name, strlen(a->name));
1580 paired_precalc (void *aux UNUSED)
1584 for(i=0; i < n_pairs ; ++i )
1587 pairs[i].sum[0] = 0; pairs[i].sum[1] = 0;
1588 pairs[i].ssq[0] = 0; pairs[i].ssq[1] = 0;
1589 pairs[i].sum_of_prod = 0;
1590 pairs[i].correlation = 0;
1591 pairs[i].sum_of_diffs = 0;
1592 pairs[i].ssq_diffs = 0;
1599 paired_calc (struct ccase *c, void *aux UNUSED)
1603 double weight = dict_get_case_weight(default_dict,c);
1605 /* Skip the entire case if /MISSING=LISTWISE is set ,
1606 AND one member of a pair is missing */
1607 if ( cmd.miss == TTS_LISTWISE )
1609 for(i=0; i < n_pairs ; ++i )
1611 struct variable *v0 = pairs[i].v[0];
1612 struct variable *v1 = pairs[i].v[1];
1614 union value *val0 = &c->data[v0->fv];
1615 union value *val1 = &c->data[v1->fv];
1617 if ( value_is_missing(val0,v0) ||
1618 value_is_missing(val1,v1) )
1625 for(i=0; i < n_pairs ; ++i )
1627 struct variable *v0 = pairs[i].v[0];
1628 struct variable *v1 = pairs[i].v[1];
1630 union value *val0 = &c->data[v0->fv];
1631 union value *val1 = &c->data[v1->fv];
1633 if ( ( !value_is_missing(val0,v0) && !value_is_missing(val1,v1) ) )
1635 pairs[i].n += weight;
1636 pairs[i].sum[0] += weight * val0->f;
1637 pairs[i].sum[1] += weight * val1->f;
1639 pairs[i].ssq[0] += weight * sqr(val0->f);
1640 pairs[i].ssq[1] += weight * sqr(val1->f);
1643 pairs[i].correlation += weight *
1644 ( val0->f - pairs[i].v[0]->p.t_t.ugs.mean )
1646 ( val1->f - pairs[i].v[1]->p.t_t.ugs.mean );
1649 pairs[i].sum_of_prod += weight * val0->f * val1->f ;
1652 pairs[i].sum_of_diffs += weight * ( val0->f - val1->f ) ;
1653 pairs[i].ssq_diffs += weight * sqr(val0->f - val1->f);
1661 paired_postcalc (void *aux UNUSED)
1665 for(i=0; i < n_pairs ; ++i )
1668 const double n = pairs[i].n;
1670 for (j=0; j < 2 ; ++j)
1672 pairs[i].mean[j] = pairs[i].sum[j] / n ;
1673 pairs[i].s_std_dev[j] = sqrt((pairs[i].ssq[j] / n -
1674 sqr(pairs[i].mean[j]))
1677 pairs[i].std_dev[j] = sqrt(n/(n-1)*(pairs[i].ssq[j] / n -
1678 sqr(pairs[i].mean[j]))
1682 pairs[i].correlation = pairs[i].sum_of_prod / pairs[i].n -
1683 pairs[i].mean[0] * pairs[i].mean[1] ;
1684 /* correlation now actually contains the covariance */
1686 pairs[i].correlation /= pairs[i].std_dev[0] * pairs[i].std_dev[1];
1687 pairs[i].correlation *= pairs[i].n / ( pairs[i].n - 1 );
1690 pairs[i].correlation /= pairs[i].v[0]->p.t_t.ugs.std_dev *
1691 pairs[i].v[1]->p.t_t.ugs.std_dev ;
1692 pairs[i].correlation /= n - 1;
1696 pairs[i].mean_diff = pairs[i].sum_of_diffs / n ;
1699 pairs[i].std_dev_diff = sqrt ( n / (n - 1) * (
1700 ( pairs[i].ssq_diffs / n )
1702 sqr(pairs[i].mean_diff )
1707 /* Return the group # corresponding to the
1708 independent variable with the value val
1711 get_group(const union value *val, struct variable *indep)
1715 for (i = 0; i < 2 ; ++i )
1717 const int cmp = compare_values(val,&groups_values[i],indep->width) ;
1718 switch ( criteria[i])
1721 if ( 0 == cmp ) return i;
1724 if ( 0 > cmp ) return i;
1727 if ( cmp <= 0 ) return i;
1730 if ( cmp > 0 ) return i;
1733 if ( cmp >= 0 ) return i;
1740 /* No groups matched */
1746 group_precalc (void *aux UNUSED)
1751 for(i=0; i< cmd.n_variables ; ++i)
1753 struct t_test_proc *ttpr = &cmd.v_variables[i]->p.t_t;
1755 /* There's always 2 groups for a T - TEST */
1757 ttpr->gs = xmalloc(sizeof(struct group_statistics) * 2) ;
1759 for (j=0 ; j < 2 ; ++j)
1761 ttpr->gs[j].sum = 0;
1763 ttpr->gs[j].ssq = 0;
1765 if ( n_group_values == 2 )
1766 ttpr->gs[j].id = groups_values[j];
1768 ttpr->gs[j].id = groups_values[0];
1769 ttpr->gs[j].criterion = criteria[j];
1776 group_calc (struct ccase *c, void *aux UNUSED)
1780 union value *gv = &c->data[indep_var->fv];
1782 double weight = dict_get_case_weight(default_dict,c);
1784 if ( value_is_missing(gv,indep_var) )
1789 if ( cmd.miss == TTS_LISTWISE )
1791 for(i=0; i< cmd.n_variables ; ++i)
1793 struct variable *v = cmd.v_variables[i];
1794 union value *val = &c->data[v->fv];
1796 if (value_is_missing(val,v) )
1804 gv = &c->data[indep_var->fv];
1806 g = get_group(gv,indep_var);
1808 /* If the independent variable doesn't match either of the values
1809 for this case then move on to the next case */
1813 for(i=0; i< cmd.n_variables ; ++i)
1815 struct variable *var = cmd.v_variables[i];
1817 struct group_statistics *gs = &var->p.t_t.gs[g];
1819 union value *val=&c->data[var->fv];
1821 if ( !value_is_missing(val,var) )
1824 gs->sum+=weight * val->f;
1825 gs->ssq+=weight * sqr(val->f);
1834 group_postcalc (void *aux UNUSED)
1839 for(i=0; i< cmd.n_variables ; ++i)
1841 for (j=0 ; j < 2 ; ++j)
1843 struct group_statistics *gs;
1844 gs=&cmd.v_variables[i]->p.t_t.gs[j];
1846 gs->mean = gs->sum / gs->n;
1848 gs->s_std_dev= sqrt(
1849 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1854 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1857 gs->se_mean = gs->std_dev / sqrt(gs->n);