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., 51 Franklin Street, Fifth Floor, Boston, MA
23 #include <gsl/gsl_cdf.h>
28 #include <data/case.h>
29 #include <data/casefile.h>
30 #include <data/dictionary.h>
31 #include <data/procedure.h>
32 #include <data/value-labels.h>
33 #include <data/variable.h>
34 #include <data/casefilter.h>
35 #include <language/command.h>
36 #include <language/dictionary/split-file.h>
37 #include <language/lexer/lexer.h>
38 #include <libpspp/alloc.h>
39 #include <libpspp/compiler.h>
40 #include <libpspp/hash.h>
41 #include <libpspp/magic.h>
42 #include <libpspp/message.h>
43 #include <libpspp/message.h>
44 #include <libpspp/misc.h>
45 #include <libpspp/str.h>
46 #include <math/group-proc.h>
47 #include <math/group.h>
48 #include <math/levene.h>
49 #include <output/manager.h>
50 #include <output/table.h>
51 #include "sort-criteria.h"
54 #define _(msgid) gettext (msgid)
61 missing=miss:!analysis/listwise,
62 incl:include/!exclude;
63 +contrast= double list;
64 +statistics[st_]=descriptives,homogeneity.
69 static bool bad_weight_warn = true;
72 static struct cmd_oneway cmd;
74 /* The independent variable */
75 static struct variable *indep_var;
77 /* Number of dependent variables */
80 /* The dependent variables */
81 static struct variable **vars;
84 /* A hash table containing all the distinct values of the independent
86 static struct hsh_table *global_group_hash ;
88 /* The number of distinct values of the independent variable, when all
89 missing values are disregarded */
90 static int ostensible_number_of_groups = -1;
93 static bool run_oneway(const struct ccase *first,
94 const struct casefile *cf,
95 void *_mode, const struct dataset *);
98 /* Routines to show the output tables */
99 static void show_anova_table(void);
100 static void show_descriptives(void);
101 static void show_homogeneity(void);
103 static void show_contrast_coeffs(short *);
104 static void show_contrast_tests(short *);
107 enum stat_table_t {STAT_DESC = 1, STAT_HOMO = 2};
109 static enum stat_table_t stat_tables ;
111 void output_oneway(void);
115 cmd_oneway (struct lexer *lexer, struct dataset *ds)
120 if ( !parse_oneway (lexer, ds, &cmd, NULL) )
123 /* What statistics were requested */
124 if ( cmd.sbc_statistics )
127 for (i = 0 ; i < ONEWAY_ST_count ; ++i )
129 if ( ! cmd.a_statistics[i] ) continue;
132 case ONEWAY_ST_DESCRIPTIVES:
133 stat_tables |= STAT_DESC;
135 case ONEWAY_ST_HOMOGENEITY:
136 stat_tables |= STAT_HOMO;
142 ok = multipass_procedure_with_splits (ds, run_oneway, &cmd);
147 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
155 short *bad_contrast ;
157 bad_contrast = xnmalloc (cmd.sbc_contrast, sizeof *bad_contrast);
159 /* Check the sanity of the given contrast values */
160 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
166 if ( subc_list_double_count(&cmd.dl_contrast[i]) !=
167 ostensible_number_of_groups )
170 _("Number of contrast coefficients must equal the number of groups"));
175 for (j=0; j < ostensible_number_of_groups ; ++j )
176 sum += subc_list_double_at(&cmd.dl_contrast[i],j);
179 msg(SW,_("Coefficients for contrast %d do not total zero"),i + 1);
182 if ( stat_tables & STAT_DESC )
185 if ( stat_tables & STAT_HOMO )
190 if (cmd.sbc_contrast )
192 show_contrast_coeffs(bad_contrast);
193 show_contrast_tests(bad_contrast);
200 for (i = 0 ; i < n_vars ; ++i )
202 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
204 hsh_destroy(group_hash);
207 hsh_destroy(global_group_hash);
214 /* Parser for the variables sub command */
216 oneway_custom_variables (struct lexer *lexer,
217 struct dataset *ds, struct cmd_oneway *cmd UNUSED,
220 struct dictionary *dict = dataset_dict (ds);
222 lex_match (lexer, '=');
224 if ((lex_token (lexer) != T_ID || dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
225 && lex_token (lexer) != T_ALL)
228 if (!parse_variables (lexer, dict, &vars, &n_vars,
230 | PV_NUMERIC | PV_NO_SCRATCH) )
238 if ( ! lex_match (lexer, T_BY))
241 indep_var = parse_variable (lexer, dict);
245 msg(SE,_("`%s' is not a variable name"),lex_tokid (lexer));
253 /* Show the ANOVA table */
255 show_anova_table(void)
259 size_t n_rows = n_vars * 3 + 1;
264 t = tab_create (n_cols,n_rows,0);
265 tab_headers (t, 2, 0, 1, 0);
266 tab_dim (t, tab_natural_dimensions);
273 n_cols - 1, n_rows - 1);
275 tab_hline (t, TAL_2, 0, n_cols - 1, 1 );
276 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
277 tab_vline (t, TAL_0, 1, 0, 0);
279 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
280 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
281 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
282 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
283 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
286 for ( i=0 ; i < n_vars ; ++i )
288 struct group_statistics *totals = &group_proc_get (vars[i])->ugs;
289 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
290 struct hsh_iterator g;
291 struct group_statistics *gs;
293 const char *s = var_to_string(vars[i]);
295 for (gs = hsh_first (group_hash,&g);
297 gs = hsh_next(group_hash,&g))
299 ssa += (gs->sum * gs->sum)/gs->n;
302 ssa -= ( totals->sum * totals->sum ) / totals->n ;
304 tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s);
305 tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups"));
306 tab_text (t, 1, i * 3 + 2, TAB_LEFT | TAT_TITLE, _("Within Groups"));
307 tab_text (t, 1, i * 3 + 3, TAB_LEFT | TAT_TITLE, _("Total"));
310 tab_hline(t, TAL_1, 0, n_cols - 1 , i * 3 + 1);
313 struct group_proc *gp = group_proc_get (vars[i]);
314 const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ;
315 const double df1 = gp->n_groups - 1;
316 const double df2 = totals->n - gp->n_groups ;
317 const double msa = ssa / df1;
319 gp->mse = (sst - ssa) / df2;
322 /* Sums of Squares */
323 tab_float (t, 2, i * 3 + 1, 0, ssa, 10, 2);
324 tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2);
325 tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2);
328 /* Degrees of freedom */
329 tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0);
330 tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0);
331 tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
334 tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3);
335 tab_float (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, 8, 3);
339 const double F = msa/gp->mse ;
342 tab_float (t, 5, i * 3 + 1, 0, F, 8, 3);
344 /* The significance */
345 tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
353 tab_title (t, _("ANOVA"));
358 /* Show the descriptives table */
360 show_descriptives(void)
367 const double confidence=0.95;
368 const double q = (1.0 - confidence) / 2.0;
373 for ( v = 0 ; v < n_vars ; ++v )
374 n_rows += group_proc_get (vars[v])->n_groups + 1;
376 t = tab_create (n_cols,n_rows,0);
377 tab_headers (t, 2, 0, 2, 0);
378 tab_dim (t, tab_natural_dimensions);
381 /* Put a frame around the entire box, and vertical lines inside */
386 n_cols - 1, n_rows - 1);
388 /* Underline headers */
389 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
390 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
392 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
393 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
394 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
395 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
398 tab_vline(t, TAL_0, 7, 0, 0);
399 tab_hline(t, TAL_1, 6, 7, 1);
400 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
402 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
403 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
405 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
406 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
409 tab_title (t, _("Descriptives"));
413 for ( v=0 ; v < n_vars ; ++v )
418 struct group_proc *gp = group_proc_get (vars[v]);
420 struct group_statistics *gs;
421 struct group_statistics *totals = &gp->ugs;
423 const char *s = var_to_string(vars[v]);
425 struct group_statistics *const *gs_array =
426 (struct group_statistics *const *) hsh_sort(gp->group_hash);
429 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
431 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
433 for (count = 0 ; count < hsh_count(gp->group_hash) ; ++count)
435 gs = gs_array[count];
437 tab_text (t, 1, row + count,
438 TAB_LEFT | TAT_TITLE ,value_to_string(&gs->id,indep_var));
440 /* Now fill in the numbers ... */
442 tab_float (t, 2, row + count, 0, gs->n, 8,0);
444 tab_float (t, 3, row + count, 0, gs->mean,8,2);
446 tab_float (t, 4, row + count, 0, gs->std_dev,8,2);
448 std_error = gs->std_dev/sqrt(gs->n) ;
449 tab_float (t, 5, row + count, 0,
452 /* Now the confidence interval */
454 T = gsl_cdf_tdist_Qinv(q,gs->n - 1);
456 tab_float(t, 6, row + count, 0,
457 gs->mean - T * std_error, 8, 2);
459 tab_float(t, 7, row + count, 0,
460 gs->mean + T * std_error, 8, 2);
464 tab_float(t, 8, row + count, 0, gs->minimum, 8, 2);
465 tab_float(t, 9, row + count, 0, gs->maximum, 8, 2);
469 tab_text (t, 1, row + count,
470 TAB_LEFT | TAT_TITLE ,_("Total"));
472 tab_float (t, 2, row + count, 0, totals->n, 8,0);
474 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
476 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
478 std_error = totals->std_dev/sqrt(totals->n) ;
480 tab_float (t, 5, row + count, 0, std_error, 8,2);
482 /* Now the confidence interval */
484 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
486 tab_float(t, 6, row + count, 0,
487 totals->mean - T * std_error, 8, 2);
489 tab_float(t, 7, row + count, 0,
490 totals->mean + T * std_error, 8, 2);
494 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
495 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
497 row += gp->n_groups + 1;
506 /* Show the homogeneity table */
508 show_homogeneity(void)
512 size_t n_rows = n_vars + 1;
517 t = tab_create (n_cols,n_rows,0);
518 tab_headers (t, 1, 0, 1, 0);
519 tab_dim (t, tab_natural_dimensions);
521 /* Put a frame around the entire box, and vertical lines inside */
526 n_cols - 1, n_rows - 1);
529 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
530 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
533 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
534 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
535 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
536 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
539 tab_title (t, _("Test of Homogeneity of Variances"));
541 for ( v=0 ; v < n_vars ; ++v )
544 const struct variable *var = vars[v];
545 const struct group_proc *gp = group_proc_get (vars[v]);
546 const char *s = var_to_string(var);
547 const struct group_statistics *totals = &gp->ugs;
549 const double df1 = gp->n_groups - 1;
550 const double df2 = totals->n - gp->n_groups ;
552 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
555 tab_float (t, 1, v + 1, TAB_RIGHT, F, 8,3);
556 tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0);
557 tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0);
559 /* Now the significance */
560 tab_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
567 /* Show the contrast coefficients table */
569 show_contrast_coeffs (short *bad_contrast)
571 int n_cols = 2 + ostensible_number_of_groups;
572 int n_rows = 2 + cmd.sbc_contrast;
573 union value *group_value;
575 void *const *group_values ;
579 t = tab_create (n_cols,n_rows,0);
580 tab_headers (t, 2, 0, 2, 0);
581 tab_dim (t, tab_natural_dimensions);
583 /* Put a frame around the entire box, and vertical lines inside */
588 n_cols - 1, n_rows - 1);
602 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
603 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
605 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
607 tab_title (t, _("Contrast Coefficients"));
609 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
612 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
613 var_to_string(indep_var));
615 group_values = hsh_sort(global_group_hash);
617 count < hsh_count(global_group_hash) ;
621 group_value = group_values[count];
623 tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
624 value_to_string(group_value, indep_var));
626 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
628 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
630 if ( bad_contrast[i] )
631 tab_text(t, count + 2, i + 2, TAB_RIGHT, "?" );
633 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
634 subc_list_double_at(&cmd.dl_contrast[i], count)
643 /* Show the results of the contrast tests */
645 show_contrast_tests(short *bad_contrast)
649 size_t n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
653 t = tab_create (n_cols,n_rows,0);
654 tab_headers (t, 3, 0, 1, 0);
655 tab_dim (t, tab_natural_dimensions);
657 /* Put a frame around the entire box, and vertical lines inside */
662 n_cols - 1, n_rows - 1);
670 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
671 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
674 tab_title (t, _("Contrast Tests"));
676 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
677 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
678 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
679 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
680 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
681 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
683 for ( v = 0 ; v < n_vars ; ++v )
686 int lines_per_variable = 2 * cmd.sbc_contrast;
689 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
690 var_to_string(vars[v]));
692 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
695 double contrast_value = 0.0;
696 double coef_msq = 0.0;
697 struct group_proc *grp_data = group_proc_get (vars[v]);
698 struct hsh_table *group_hash = grp_data->group_hash;
700 void *const *group_stat_array;
703 double std_error_contrast ;
708 /* Note: The calculation of the degrees of freedom in the
709 "variances not equal" case is painfull!!
710 The following formula may help to understand it:
711 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
714 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
719 double df_denominator = 0.0;
720 double df_numerator = 0.0;
723 tab_text (t, 1, (v * lines_per_variable) + i + 1,
724 TAB_LEFT | TAT_TITLE,
725 _("Assume equal variances"));
727 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
728 TAB_LEFT | TAT_TITLE,
729 _("Does not assume equal"));
732 tab_text (t, 2, (v * lines_per_variable) + i + 1,
733 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
736 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
737 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
740 if ( bad_contrast[i])
743 group_stat_array = hsh_sort(group_hash);
745 for (ci = 0 ; ci < hsh_count(group_hash) ; ++ci)
747 const double coef = subc_list_double_at(&cmd.dl_contrast[i], ci);
748 struct group_statistics *gs = group_stat_array[ci];
750 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
752 contrast_value += coef * gs->mean;
754 coef_msq += (coef * coef) / gs->n ;
756 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
758 df_numerator += (coef * coef) * winv;
759 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
761 sec_vneq = sqrt(sec_vneq);
763 df_numerator = pow2(df_numerator);
765 tab_float (t, 3, (v * lines_per_variable) + i + 1,
766 TAB_RIGHT, contrast_value, 8,2);
768 tab_float (t, 3, (v * lines_per_variable) + i + 1 +
770 TAB_RIGHT, contrast_value, 8,2);
772 std_error_contrast = sqrt(grp_data->mse * coef_msq);
775 tab_float (t, 4, (v * lines_per_variable) + i + 1,
776 TAB_RIGHT, std_error_contrast,
779 T = fabs(contrast_value / std_error_contrast) ;
783 tab_float (t, 5, (v * lines_per_variable) + i + 1,
787 df = grp_data->ugs.n - grp_data->n_groups;
789 /* Degrees of Freedom */
790 tab_float (t, 6, (v * lines_per_variable) + i + 1,
795 /* Significance TWO TAILED !!*/
796 tab_float (t, 7, (v * lines_per_variable) + i + 1,
797 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
801 /* Now for the Variances NOT Equal case */
805 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
810 T = contrast_value / sec_vneq;
812 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
817 df = df_numerator / df_denominator;
820 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
824 /* The Significance */
826 tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
827 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
834 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
842 /* ONEWAY ANOVA Calculations */
844 static void postcalc ( struct cmd_oneway *cmd UNUSED );
846 static void precalc ( struct cmd_oneway *cmd UNUSED );
850 /* Pre calculations */
852 precalc ( struct cmd_oneway *cmd UNUSED )
856 for(i=0; i< n_vars ; ++i)
858 struct group_proc *gp = group_proc_get (vars[i]);
859 struct group_statistics *totals = &gp->ugs;
861 /* Create a hash for each of the dependent variables.
862 The hash contains a group_statistics structure,
863 and is keyed by value of the independent variable */
867 (hsh_compare_func *) compare_group,
868 (hsh_hash_func *) hash_group,
869 (hsh_free_func *) free_group,
870 (void *) indep_var->width );
877 totals->maximum = - DBL_MAX;
878 totals->minimum = DBL_MAX;
884 run_oneway(const struct ccase *first, const struct casefile *cf,
885 void *cmd_, const struct dataset *ds)
887 struct casereader *r;
889 struct casefilter *filter = NULL;
891 struct cmd_oneway *cmd = (struct cmd_oneway *) cmd_;
893 output_split_file_values (ds, first);
895 global_group_hash = hsh_create(4,
896 (hsh_compare_func *) compare_values,
897 (hsh_hash_func *) hash_value,
899 (void *) indep_var->width );
903 filter = casefilter_create ( (cmd->incl != ONEWAY_INCLUDE),
906 for(r = casefile_get_reader (cf, filter);
907 casereader_read (r, &c) ;
912 const double weight =
913 dict_get_case_weight (dataset_dict (ds), &c, &bad_weight_warn);
915 const union value *indep_val;
917 if ( casefilter_variable_missing (filter, &c, indep_var))
920 indep_val = case_data (&c, indep_var->fv);
922 hsh_insert ( global_group_hash, (void *) indep_val );
924 for ( i = 0 ; i < n_vars ; ++i )
926 const struct variable *v = vars[i];
928 const union value *val = case_data (&c, v->fv);
930 struct group_proc *gp = group_proc_get (vars[i]);
931 struct hsh_table *group_hash = gp->group_hash;
933 struct group_statistics *gs;
935 gs = hsh_find(group_hash, (void *) indep_val );
939 gs = xmalloc (sizeof *gs);
945 gs->minimum = DBL_MAX;
946 gs->maximum = -DBL_MAX;
948 hsh_insert ( group_hash, (void *) gs );
951 if (! casefilter_variable_missing (filter, &c, v))
953 struct group_statistics *totals = &gp->ugs;
956 totals->sum+=weight * val->f;
957 totals->ssq+=weight * val->f * val->f;
959 if ( val->f * weight < totals->minimum )
960 totals->minimum = val->f * weight;
962 if ( val->f * weight > totals->maximum )
963 totals->maximum = val->f * weight;
966 gs->sum+=weight * val->f;
967 gs->ssq+=weight * val->f * val->f;
969 if ( val->f * weight < gs->minimum )
970 gs->minimum = val->f * weight;
972 if ( val->f * weight > gs->maximum )
973 gs->maximum = val->f * weight;
976 gp->n_groups = hsh_count ( group_hash );
981 casereader_destroy (r);
986 if ( stat_tables & STAT_HOMO )
987 levene (dataset_dict (ds), cf, indep_var, n_vars, vars,
990 casefilter_destroy (filter);
992 ostensible_number_of_groups = hsh_count (global_group_hash);
1001 /* Post calculations for the ONEWAY command */
1003 postcalc ( struct cmd_oneway *cmd UNUSED )
1008 for(i = 0; i < n_vars ; ++i)
1010 struct group_proc *gp = group_proc_get (vars[i]);
1011 struct hsh_table *group_hash = gp->group_hash;
1012 struct group_statistics *totals = &gp->ugs;
1014 struct hsh_iterator g;
1015 struct group_statistics *gs;
1017 for (gs = hsh_first (group_hash,&g);
1019 gs = hsh_next(group_hash,&g))
1021 gs->mean=gs->sum / gs->n;
1022 gs->s_std_dev= sqrt(
1023 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1028 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1031 gs->se_mean = gs->std_dev / sqrt(gs->n);
1032 gs->mean_diff= gs->sum_diff / gs->n;
1038 totals->mean = totals->sum / totals->n;
1039 totals->std_dev= sqrt(
1040 totals->n/(totals->n-1) *
1041 ( (totals->ssq / totals->n ) - totals->mean * totals->mean )
1044 totals->se_mean = totals->std_dev / sqrt(totals->n);