1 /* PSPP - One way ANOVA. -*-c-*-
3 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 Author: John Darrington 2004
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 #include <gsl/gsl_cdf.h>
37 #include "value-labels.h"
42 #include "group_proc.h"
49 +missing=miss:!analysis/listwise,
50 incl:include/!exclude;
51 contrast= double list;
52 statistics[st_]=descriptives,homogeneity.
59 static int bad_weight_warn = 1;
62 static struct cmd_oneway cmd;
64 /* The independent variable */
65 static struct variable *indep_var;
67 /* Number of dependent variables */
70 /* The dependent variables */
71 static struct variable **vars;
74 /* A hash table containing all the distinct values of the independent
76 static struct hsh_table *global_group_hash ;
78 /* The number of distinct values of the independent variable, when all
79 missing values are disregarded */
80 static int ostensible_number_of_groups=-1;
83 /* Function to use for testing for missing values */
84 static is_missing_func value_is_missing;
87 static void calculate(const struct casefile *cf, void *_mode);
90 /* Routines to show the output tables */
91 static void show_anova_table(void);
92 static void show_descriptives(void);
93 static void show_homogeneity(void);
94 static void show_contrast_coeffs(void);
95 static void show_contrast_tests(void);
104 if ( !parse_oneway(&cmd) )
107 /* If /MISSING=INCLUDE is set, then user missing values are ignored */
108 if (cmd.incl == ONEWAY_INCLUDE )
109 value_is_missing = is_system_missing;
111 value_is_missing = is_missing;
113 multipass_procedure_with_splits (calculate, &cmd);
115 /* Check the sanity of the given contrast values */
116 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
121 if ( subc_list_double_count(&cmd.dl_contrast[i]) !=
122 ostensible_number_of_groups )
125 _("Number of contrast coefficients must equal the number of groups"));
129 for (j=0; j < ostensible_number_of_groups ; ++j )
130 sum += subc_list_double_at(&cmd.dl_contrast[i],j);
133 msg(SW,_("Coefficients for contrast %d do not total zero"),i + 1);
138 /* Show the statistics tables */
139 if ( cmd.sbc_statistics )
141 for (i = 0 ; i < ONEWAY_ST_count ; ++i )
143 if ( ! cmd.a_statistics[i] ) continue;
146 case ONEWAY_ST_DESCRIPTIVES:
149 case ONEWAY_ST_HOMOGENEITY:
159 if (cmd.sbc_contrast)
161 show_contrast_coeffs();
162 show_contrast_tests();
167 for (i = 0 ; i < n_vars ; ++i )
169 struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash;
171 hsh_destroy(group_hash);
174 hsh_destroy(global_group_hash);
183 /* Parser for the variables sub command */
185 oneway_custom_variables(struct cmd_oneway *cmd UNUSED)
190 if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
195 if (!parse_variables (default_dict, &vars, &n_vars,
197 | PV_NUMERIC | PV_NO_SCRATCH) )
205 if ( ! lex_match(T_BY))
209 indep_var = parse_variable();
213 msg(SE,_("`%s' is not a variable name"),tokid);
222 /* Show the ANOVA table */
224 show_anova_table(void)
228 int n_rows = n_vars * 3 + 1;
233 t = tab_create (n_cols,n_rows,0);
234 tab_headers (t, 2, 0, 1, 0);
235 tab_dim (t, tab_natural_dimensions);
242 n_cols - 1, n_rows - 1);
244 tab_hline (t, TAL_2, 0, n_cols - 1, 1 );
245 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
246 tab_vline (t, TAL_0, 1, 0, 0);
248 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
249 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
250 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
251 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
252 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
255 for ( i=0 ; i < n_vars ; ++i )
257 struct group_statistics *totals = &vars[i]->p.grp_data.ugs;
258 struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash;
259 struct hsh_iterator g;
260 struct group_statistics *gs;
264 for (gs = hsh_first (group_hash,&g);
266 gs = hsh_next(group_hash,&g))
268 ssa += (gs->sum * gs->sum)/gs->n;
271 ssa -= ( totals->sum * totals->sum ) / totals->n ;
273 const char *s = (vars[i]->label) ? vars[i]->label : vars[i]->name;
276 tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s);
277 tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups"));
278 tab_text (t, 1, i * 3 + 2, TAB_LEFT | TAT_TITLE, _("Within Groups"));
279 tab_text (t, 1, i * 3 + 3, TAB_LEFT | TAT_TITLE, _("Total"));
282 tab_hline(t, TAL_1, 0, n_cols - 1 , i * 3 + 1);
285 const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ;
286 const double df1 = vars[i]->p.grp_data.n_groups - 1;
287 const double df2 = totals->n - vars[i]->p.grp_data.n_groups ;
288 const double msa = ssa / df1;
290 vars[i]->p.grp_data.mse = (sst - ssa) / df2;
293 /* Sums of Squares */
294 tab_float (t, 2, i * 3 + 1, 0, ssa, 10, 2);
295 tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2);
296 tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2);
299 /* Degrees of freedom */
300 tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0);
301 tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0);
302 tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
305 tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3);
306 tab_float (t, 4, i * 3 + 2, TAB_RIGHT, vars[i]->p.grp_data.mse, 8, 3);
310 const double F = msa/vars[i]->p.grp_data.mse ;
313 tab_float (t, 5, i * 3 + 1, 0, F, 8, 3);
315 /* The significance */
316 tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
324 tab_title (t, 0, _("ANOVA"));
330 /* Show the descriptives table */
332 show_descriptives(void)
339 const double confidence=0.95;
340 const double q = (1.0 - confidence) / 2.0;
347 for ( v = 0 ; v < n_vars ; ++v )
348 n_rows += vars[v]->p.grp_data.n_groups + 1;
350 t = tab_create (n_cols,n_rows,0);
351 tab_headers (t, 2, 0, 2, 0);
352 tab_dim (t, tab_natural_dimensions);
355 /* Put a frame around the entire box, and vertical lines inside */
360 n_cols - 1, n_rows - 1);
362 /* Underline headers */
363 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
364 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
366 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
367 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
368 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
369 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
372 tab_vline(t, TAL_0, 7, 0, 0);
373 tab_hline(t, TAL_1, 6, 7, 1);
374 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
376 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
377 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
379 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
380 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
383 tab_title (t, 0, _("Descriptives"));
387 for ( v=0 ; v < n_vars ; ++v )
393 struct hsh_iterator g;
394 struct group_statistics *gs;
395 struct group_statistics *totals = &vars[v]->p.grp_data.ugs;
398 char *s = (vars[v]->label) ? vars[v]->label : vars[v]->name;
400 struct hsh_table *group_hash = vars[v]->p.grp_data.group_hash;
403 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
405 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
408 for (gs = hsh_first (group_hash,&g);
410 gs = hsh_next(group_hash,&g))
412 const char *s = val_labs_find(indep_var->val_labs, gs->id );
415 tab_text (t, 1, row + count,
416 TAB_LEFT | TAT_TITLE ,s);
417 else if ( indep_var->width != 0 )
418 tab_text (t, 1, row + count,
419 TAB_LEFT | TAT_TITLE, gs->id.s);
421 tab_text (t, 1, row + count,
422 TAB_LEFT | TAT_TITLE | TAT_PRINTF, "%g", gs->id.f);
425 /* Now fill in the numbers ... */
427 tab_float (t, 2, row + count, 0, gs->n, 8,0);
429 tab_float (t, 3, row + count, 0, gs->mean,8,2);
431 tab_float (t, 4, row + count, 0, gs->std_dev,8,2);
433 std_error = gs->std_dev/sqrt(gs->n) ;
434 tab_float (t, 5, row + count, 0,
437 /* Now the confidence interval */
439 T = gsl_cdf_tdist_Qinv(q,gs->n - 1);
441 tab_float(t, 6, row + count, 0,
442 gs->mean - T * std_error, 8, 2);
444 tab_float(t, 7, row + count, 0,
445 gs->mean + T * std_error, 8, 2);
449 tab_float(t, 8, row + count, 0, gs->minimum, 8, 2);
450 tab_float(t, 9, row + count, 0, gs->maximum, 8, 2);
455 tab_text (t, 1, row + count,
456 TAB_LEFT | TAT_TITLE ,_("Total"));
458 tab_float (t, 2, row + count, 0, totals->n, 8,0);
460 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
462 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
464 std_error = totals->std_dev/sqrt(totals->n) ;
466 tab_float (t, 5, row + count, 0, std_error, 8,2);
468 /* Now the confidence interval */
470 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
472 tab_float(t, 6, row + count, 0,
473 totals->mean - T * std_error, 8, 2);
475 tab_float(t, 7, row + count, 0,
476 totals->mean + T * std_error, 8, 2);
480 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
481 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
483 row += vars[v]->p.grp_data.n_groups + 1;
492 /* Show the homogeneity table */
494 show_homogeneity(void)
498 int n_rows = n_vars + 1;
503 t = tab_create (n_cols,n_rows,0);
504 tab_headers (t, 1, 0, 1, 0);
505 tab_dim (t, tab_natural_dimensions);
507 /* Put a frame around the entire box, and vertical lines inside */
512 n_cols - 1, n_rows - 1);
515 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
516 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
519 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
520 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
521 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
522 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
525 tab_title (t, 0, _("Test of Homogeneity of Variances"));
527 for ( v=0 ; v < n_vars ; ++v )
529 char *s = (vars[v]->label) ? vars[v]->label : vars[v]->name;
530 struct group_statistics *totals = &vars[v]->p.grp_data.ugs;
532 const double df1 = vars[v]->p.grp_data.n_groups - 1;
533 const double df2 = totals->n - vars[v]->p.grp_data.n_groups ;
536 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
540 tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0);
541 tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0);
550 /* Show the contrast coefficients table */
552 show_contrast_coeffs(void)
555 int n_cols = 2 + ostensible_number_of_groups;
556 int n_rows = 2 + cmd.sbc_contrast;
557 struct hsh_iterator g;
558 union value *group_value;
565 t = tab_create (n_cols,n_rows,0);
566 tab_headers (t, 2, 0, 2, 0);
567 tab_dim (t, tab_natural_dimensions);
569 /* Put a frame around the entire box, and vertical lines inside */
574 n_cols - 1, n_rows - 1);
590 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
593 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
594 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
597 tab_title (t, 0, _("Contrast Coefficients"));
599 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
601 s = (indep_var->label) ? indep_var->label : indep_var->name;
603 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE, s);
605 for (group_value = hsh_first (global_group_hash,&g);
607 group_value = hsh_next(global_group_hash,&g))
612 lab = val_labs_find(indep_var->val_labs,*group_value);
615 tab_text (t, count + 2, 1,
616 TAB_CENTER | TAT_TITLE ,lab);
618 tab_text (t, count + 2, 1,
619 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%g", group_value->f);
621 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
623 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
624 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
625 subc_list_double_at(&cmd.dl_contrast[i],count)
637 /* Show the results of the contrast tests */
639 show_contrast_tests(void)
643 int n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
647 t = tab_create (n_cols,n_rows,0);
648 tab_headers (t, 3, 0, 1, 0);
649 tab_dim (t, tab_natural_dimensions);
651 /* Put a frame around the entire box, and vertical lines inside */
656 n_cols - 1, n_rows - 1);
664 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
665 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
668 tab_title (t, 0, _("Contrast Tests"));
670 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
671 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
672 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
673 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
674 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
675 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
677 for ( v = 0 ; v < n_vars ; ++v )
680 int lines_per_variable = 2 * cmd.sbc_contrast;
683 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
684 vars[v]->label?vars[v]->label:vars[v]->name);
688 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
691 double contrast_value = 0.0;
692 double coef_msq = 0.0;
693 struct group_proc *grp_data = &vars[v]->p.grp_data ;
694 struct hsh_table *group_hash = grp_data->group_hash;
695 struct hsh_iterator g;
696 struct group_statistics *gs;
699 double std_error_contrast ;
704 /* Note: The calculation of the degrees of freedom in the variances
705 not equal case is painfull!!
706 The following formula may help to understand it:
707 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
710 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
715 double df_denominator = 0.0;
716 double df_numerator = 0.0;
721 tab_text (t, 1, (v * lines_per_variable) + i + 1,
722 TAB_LEFT | TAT_TITLE,
723 _("Assume equal variances"));
725 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
726 TAB_LEFT | TAT_TITLE,
727 _("Does not assume equal"));
730 tab_text (t, 2, (v * lines_per_variable) + i + 1,
731 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
734 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
735 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
737 /* FIXME: Potential danger here.
738 We're ASSUMING THE array is in the order corresponding to the
740 for (ci = 0, gs = hsh_first (group_hash,&g);
742 ++ci, gs = hsh_next(group_hash,&g))
745 const double coef = subc_list_double_at(&cmd.dl_contrast[i],ci);
746 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
748 contrast_value += coef * gs->mean;
750 coef_msq += (coef * coef) / gs->n ;
752 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
754 df_numerator += (coef * coef) * winv;
755 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
758 sec_vneq = sqrt(sec_vneq);
761 df_numerator = pow2(df_numerator);
764 tab_float (t, 3, (v * lines_per_variable) + i + 1,
765 TAB_RIGHT, contrast_value, 8,2);
767 tab_float (t, 3, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
768 TAB_RIGHT, contrast_value, 8,2);
771 std_error_contrast = sqrt(vars[v]->p.grp_data.mse * coef_msq);
774 tab_float (t, 4, (v * lines_per_variable) + i + 1,
775 TAB_RIGHT, std_error_contrast,
778 T = fabs(contrast_value / std_error_contrast) ;
782 tab_float (t, 5, (v * lines_per_variable) + i + 1,
786 df = grp_data->ugs.n - grp_data->n_groups;
788 /* Degrees of Freedom */
789 tab_float (t, 6, (v * lines_per_variable) + i + 1,
794 /* Significance TWO TAILED !!*/
795 tab_float (t, 7, (v * lines_per_variable) + i + 1,
796 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
800 /* Now for the Variances NOT Equal case */
804 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
809 T = contrast_value / sec_vneq;
811 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
816 df = df_numerator / df_denominator;
819 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
823 /* The Significance */
825 tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
826 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
833 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
841 /* ONEWAY ANOVA Calculations */
843 static void postcalc ( struct cmd_oneway *cmd UNUSED );
845 static void precalc ( struct cmd_oneway *cmd UNUSED );
849 /* Pre calculations */
851 precalc ( struct cmd_oneway *cmd UNUSED )
855 for(i=0; i< n_vars ; ++i)
857 struct group_statistics *totals = &vars[i]->p.grp_data.ugs;
859 /* Create a hash for each of the dependent variables.
860 The hash contains a group_statistics structure,
861 and is keyed by value of the independent variable */
863 vars[i]->p.grp_data.group_hash =
865 (hsh_compare_func *) compare_group,
866 (hsh_hash_func *) hash_group,
867 (hsh_free_func *) free_group,
868 (void *) indep_var->width );
875 totals->maximum = - DBL_MAX;
876 totals->minimum = DBL_MAX;
882 calculate(const struct casefile *cf, void *cmd_)
884 struct casereader *r;
888 struct cmd_oneway *cmd = (struct cmd_oneway *) cmd_;
890 global_group_hash = hsh_create(4,
891 (hsh_compare_func *) compare_values,
892 (hsh_hash_func *) hash_value,
894 (void *) indep_var->width );
900 for(r = casefile_get_reader (cf);
901 casereader_read (r, &c) ;
906 const double weight =
907 dict_get_case_weight(default_dict,&c,&bad_weight_warn);
909 const union value *indep_val = case_data (&c, indep_var->fv);
911 hsh_insert ( global_group_hash, (void *) indep_val );
914 for ( i = 0 ; i < n_vars ; ++i )
916 const struct variable *v = vars[i];
918 const union value *val = case_data (&c, v->fv);
920 struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash;
922 struct group_statistics *gs;
924 gs = hsh_find(group_hash, (void *) indep_val );
928 gs = (struct group_statistics *)
929 xmalloc (sizeof(struct group_statistics));
936 gs->minimum = DBL_MAX;
937 gs->maximum = -DBL_MAX;
939 hsh_insert ( group_hash, (void *) gs );
942 if (! value_is_missing(val,v) )
944 struct group_statistics *totals = &vars[i]->p.grp_data.ugs;
947 totals->sum+=weight * val->f;
948 totals->ssq+=weight * val->f * val->f;
950 if ( val->f * weight < totals->minimum )
951 totals->minimum = val->f * weight;
953 if ( val->f * weight > totals->maximum )
954 totals->maximum = val->f * weight;
957 gs->sum+=weight * val->f;
958 gs->ssq+=weight * val->f * val->f;
960 if ( val->f * weight < gs->minimum )
961 gs->minimum = val->f * weight;
963 if ( val->f * weight > gs->maximum )
964 gs->maximum = val->f * weight;
967 vars[i]->p.grp_data.n_groups = hsh_count ( group_hash );
971 casereader_destroy (r);
976 levene(cf, indep_var, n_vars, vars, LEV_LISTWISE, value_is_missing);
979 ostensible_number_of_groups = hsh_count (global_group_hash);
984 /* Post calculations for the ONEWAY command */
986 postcalc ( struct cmd_oneway *cmd UNUSED )
991 for(i = 0; i < n_vars ; ++i)
993 struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash;
994 struct group_statistics *totals = &vars[i]->p.grp_data.ugs;
996 struct hsh_iterator g;
997 struct group_statistics *gs;
999 for (gs = hsh_first (group_hash,&g);
1001 gs = hsh_next(group_hash,&g))
1003 gs->mean=gs->sum / gs->n;
1004 gs->s_std_dev= sqrt(
1005 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1010 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1013 gs->se_mean = gs->std_dev / sqrt(gs->n);
1014 gs->mean_diff= gs->sum_diff / gs->n;
1020 totals->mean = totals->sum / totals->n;
1021 totals->std_dev= sqrt(
1022 totals->n/(totals->n-1) *
1023 ( (totals->ssq / totals->n ) - totals->mean * totals->mean )
1026 totals->se_mean = totals->std_dev / sqrt(totals->n);