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
22 #include <gsl/gsl_cdf.h>
23 #include <libpspp/message.h>
27 #include <libpspp/alloc.h>
28 #include <libpspp/str.h>
29 #include <data/case.h>
30 #include <data/dictionary.h>
31 #include <language/command.h>
32 #include <libpspp/compiler.h>
33 #include <language/lexer/lexer.h>
34 #include <libpspp/message.h>
35 #include <libpspp/magic.h>
36 #include <libpspp/misc.h>
37 #include <output/table.h>
38 #include <output/manager.h>
39 #include <data/value-labels.h>
40 #include <data/variable.h>
41 #include <procedure.h>
42 #include <libpspp/hash.h>
43 #include <data/casefile.h>
44 #include <math/group-proc.h>
45 #include <math/group.h>
46 #include <math/levene.h>
49 #define _(msgid) gettext (msgid)
56 +missing=miss:!analysis/listwise,
57 incl:include/!exclude;
58 contrast= double list;
59 statistics[st_]=descriptives,homogeneity.
66 static int bad_weight_warn = 1;
69 static struct cmd_oneway cmd;
71 /* The independent variable */
72 static struct variable *indep_var;
74 /* Number of dependent variables */
77 /* The dependent variables */
78 static struct variable **vars;
81 /* A hash table containing all the distinct values of the independent
83 static struct hsh_table *global_group_hash ;
85 /* The number of distinct values of the independent variable, when all
86 missing values are disregarded */
87 static int ostensible_number_of_groups=-1;
90 /* Function to use for testing for missing values */
91 static is_missing_func *value_is_missing;
94 static bool run_oneway(const struct casefile *cf, void *_mode);
97 /* Routines to show the output tables */
98 static void show_anova_table(void);
99 static void show_descriptives(void);
100 static void show_homogeneity(void);
102 static void show_contrast_coeffs(short *);
103 static void show_contrast_tests(short *);
106 enum stat_table_t {STAT_DESC = 1, STAT_HOMO = 2};
108 static enum stat_table_t stat_tables ;
110 void output_oneway(void);
119 if ( !parse_oneway(&cmd) )
122 /* If /MISSING=INCLUDE is set, then user missing values are ignored */
123 if (cmd.incl == ONEWAY_INCLUDE )
124 value_is_missing = mv_is_value_system_missing;
126 value_is_missing = mv_is_value_missing;
128 /* What statistics were requested */
129 if ( cmd.sbc_statistics )
132 for (i = 0 ; i < ONEWAY_ST_count ; ++i )
134 if ( ! cmd.a_statistics[i] ) continue;
137 case ONEWAY_ST_DESCRIPTIVES:
138 stat_tables |= STAT_DESC;
140 case ONEWAY_ST_HOMOGENEITY:
141 stat_tables |= STAT_HOMO;
147 ok = multipass_procedure_with_splits (run_oneway, &cmd);
152 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
160 short *bad_contrast ;
162 bad_contrast = xnmalloc (cmd.sbc_contrast, sizeof *bad_contrast);
164 /* Check the sanity of the given contrast values */
165 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
171 if ( subc_list_double_count(&cmd.dl_contrast[i]) !=
172 ostensible_number_of_groups )
175 _("Number of contrast coefficients must equal the number of groups"));
180 for (j=0; j < ostensible_number_of_groups ; ++j )
181 sum += subc_list_double_at(&cmd.dl_contrast[i],j);
184 msg(SW,_("Coefficients for contrast %d do not total zero"),i + 1);
187 if ( stat_tables & STAT_DESC )
190 if ( stat_tables & STAT_HOMO )
195 if (cmd.sbc_contrast )
197 show_contrast_coeffs(bad_contrast);
198 show_contrast_tests(bad_contrast);
205 for (i = 0 ; i < n_vars ; ++i )
207 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
209 hsh_destroy(group_hash);
212 hsh_destroy(global_group_hash);
219 /* Parser for the variables sub command */
221 oneway_custom_variables(struct cmd_oneway *cmd UNUSED)
226 if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
231 if (!parse_variables (default_dict, &vars, &n_vars,
233 | PV_NUMERIC | PV_NO_SCRATCH) )
241 if ( ! lex_match(T_BY))
245 indep_var = parse_variable();
249 msg(SE,_("`%s' is not a variable name"),tokid);
258 /* Show the ANOVA table */
260 show_anova_table(void)
264 size_t n_rows = n_vars * 3 + 1;
269 t = tab_create (n_cols,n_rows,0);
270 tab_headers (t, 2, 0, 1, 0);
271 tab_dim (t, tab_natural_dimensions);
278 n_cols - 1, n_rows - 1);
280 tab_hline (t, TAL_2, 0, n_cols - 1, 1 );
281 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
282 tab_vline (t, TAL_0, 1, 0, 0);
284 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
285 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
286 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
287 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
288 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
291 for ( i=0 ; i < n_vars ; ++i )
293 struct group_statistics *totals = &group_proc_get (vars[i])->ugs;
294 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
295 struct hsh_iterator g;
296 struct group_statistics *gs;
298 const char *s = var_to_string(vars[i]);
300 for (gs = hsh_first (group_hash,&g);
302 gs = hsh_next(group_hash,&g))
304 ssa += (gs->sum * gs->sum)/gs->n;
307 ssa -= ( totals->sum * totals->sum ) / totals->n ;
309 tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s);
310 tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups"));
311 tab_text (t, 1, i * 3 + 2, TAB_LEFT | TAT_TITLE, _("Within Groups"));
312 tab_text (t, 1, i * 3 + 3, TAB_LEFT | TAT_TITLE, _("Total"));
315 tab_hline(t, TAL_1, 0, n_cols - 1 , i * 3 + 1);
318 struct group_proc *gp = group_proc_get (vars[i]);
319 const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ;
320 const double df1 = gp->n_groups - 1;
321 const double df2 = totals->n - gp->n_groups ;
322 const double msa = ssa / df1;
324 gp->mse = (sst - ssa) / df2;
327 /* Sums of Squares */
328 tab_float (t, 2, i * 3 + 1, 0, ssa, 10, 2);
329 tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2);
330 tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2);
333 /* Degrees of freedom */
334 tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0);
335 tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0);
336 tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
339 tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3);
340 tab_float (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, 8, 3);
344 const double F = msa/gp->mse ;
347 tab_float (t, 5, i * 3 + 1, 0, F, 8, 3);
349 /* The significance */
350 tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
358 tab_title (t, 0, _("ANOVA"));
364 /* Show the descriptives table */
366 show_descriptives(void)
373 const double confidence=0.95;
374 const double q = (1.0 - confidence) / 2.0;
379 for ( v = 0 ; v < n_vars ; ++v )
380 n_rows += group_proc_get (vars[v])->n_groups + 1;
382 t = tab_create (n_cols,n_rows,0);
383 tab_headers (t, 2, 0, 2, 0);
384 tab_dim (t, tab_natural_dimensions);
387 /* Put a frame around the entire box, and vertical lines inside */
392 n_cols - 1, n_rows - 1);
394 /* Underline headers */
395 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
396 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
398 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
399 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
400 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
401 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
404 tab_vline(t, TAL_0, 7, 0, 0);
405 tab_hline(t, TAL_1, 6, 7, 1);
406 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
408 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
409 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
411 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
412 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
415 tab_title (t, 0, _("Descriptives"));
419 for ( v=0 ; v < n_vars ; ++v )
424 struct group_proc *gp = group_proc_get (vars[v]);
426 struct group_statistics *gs;
427 struct group_statistics *totals = &gp->ugs;
429 const char *s = var_to_string(vars[v]);
431 struct group_statistics *const *gs_array = hsh_sort(gp->group_hash);
434 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
436 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
438 for (count = 0 ; count < hsh_count(gp->group_hash) ; ++count)
440 gs = gs_array[count];
442 tab_text (t, 1, row + count,
443 TAB_LEFT | TAT_TITLE ,value_to_string(&gs->id,indep_var));
445 /* Now fill in the numbers ... */
447 tab_float (t, 2, row + count, 0, gs->n, 8,0);
449 tab_float (t, 3, row + count, 0, gs->mean,8,2);
451 tab_float (t, 4, row + count, 0, gs->std_dev,8,2);
453 std_error = gs->std_dev/sqrt(gs->n) ;
454 tab_float (t, 5, row + count, 0,
457 /* Now the confidence interval */
459 T = gsl_cdf_tdist_Qinv(q,gs->n - 1);
461 tab_float(t, 6, row + count, 0,
462 gs->mean - T * std_error, 8, 2);
464 tab_float(t, 7, row + count, 0,
465 gs->mean + T * std_error, 8, 2);
469 tab_float(t, 8, row + count, 0, gs->minimum, 8, 2);
470 tab_float(t, 9, row + count, 0, gs->maximum, 8, 2);
474 tab_text (t, 1, row + count,
475 TAB_LEFT | TAT_TITLE ,_("Total"));
477 tab_float (t, 2, row + count, 0, totals->n, 8,0);
479 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
481 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
483 std_error = totals->std_dev/sqrt(totals->n) ;
485 tab_float (t, 5, row + count, 0, std_error, 8,2);
487 /* Now the confidence interval */
489 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
491 tab_float(t, 6, row + count, 0,
492 totals->mean - T * std_error, 8, 2);
494 tab_float(t, 7, row + count, 0,
495 totals->mean + T * std_error, 8, 2);
499 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
500 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
502 row += gp->n_groups + 1;
511 /* Show the homogeneity table */
513 show_homogeneity(void)
517 size_t n_rows = n_vars + 1;
522 t = tab_create (n_cols,n_rows,0);
523 tab_headers (t, 1, 0, 1, 0);
524 tab_dim (t, tab_natural_dimensions);
526 /* Put a frame around the entire box, and vertical lines inside */
531 n_cols - 1, n_rows - 1);
534 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
535 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
538 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
539 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
540 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
541 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
544 tab_title (t, 0, _("Test of Homogeneity of Variances"));
546 for ( v=0 ; v < n_vars ; ++v )
549 const struct variable *var = vars[v];
550 const struct group_proc *gp = group_proc_get (vars[v]);
551 const char *s = var_to_string(var);
552 const struct group_statistics *totals = &gp->ugs;
554 const double df1 = gp->n_groups - 1;
555 const double df2 = totals->n - gp->n_groups ;
557 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
560 tab_float (t, 1, v + 1, TAB_RIGHT, F, 8,3);
561 tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0);
562 tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0);
564 /* Now the significance */
565 tab_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
574 /* Show the contrast coefficients table */
576 show_contrast_coeffs(short *bad_contrast)
578 int n_cols = 2 + ostensible_number_of_groups;
579 int n_rows = 2 + cmd.sbc_contrast;
580 union value *group_value;
582 void *const *group_values ;
586 t = tab_create (n_cols,n_rows,0);
587 tab_headers (t, 2, 0, 2, 0);
588 tab_dim (t, tab_natural_dimensions);
590 /* Put a frame around the entire box, and vertical lines inside */
595 n_cols - 1, n_rows - 1);
609 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
610 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
612 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
614 tab_title (t, 0, _("Contrast Coefficients"));
616 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
619 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
620 var_to_string(indep_var));
622 group_values = hsh_sort(global_group_hash);
624 count < hsh_count(global_group_hash) ;
628 group_value = group_values[count];
630 tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
631 value_to_string(group_value, indep_var));
633 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
635 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
637 if ( bad_contrast[i] )
638 tab_text(t, count + 2, i + 2, TAB_RIGHT, "?" );
640 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
641 subc_list_double_at(&cmd.dl_contrast[i], count)
650 /* Show the results of the contrast tests */
652 show_contrast_tests(short *bad_contrast)
656 size_t n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
660 t = tab_create (n_cols,n_rows,0);
661 tab_headers (t, 3, 0, 1, 0);
662 tab_dim (t, tab_natural_dimensions);
664 /* Put a frame around the entire box, and vertical lines inside */
669 n_cols - 1, n_rows - 1);
677 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
678 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
681 tab_title (t, 0, _("Contrast Tests"));
683 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
684 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
685 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
686 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
687 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
688 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
690 for ( v = 0 ; v < n_vars ; ++v )
693 int lines_per_variable = 2 * cmd.sbc_contrast;
696 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
697 var_to_string(vars[v]));
699 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
702 double contrast_value = 0.0;
703 double coef_msq = 0.0;
704 struct group_proc *grp_data = group_proc_get (vars[v]);
705 struct hsh_table *group_hash = grp_data->group_hash;
707 void *const *group_stat_array;
710 double std_error_contrast ;
715 /* Note: The calculation of the degrees of freedom in the
716 "variances not equal" case is painfull!!
717 The following formula may help to understand it:
718 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
721 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
726 double df_denominator = 0.0;
727 double df_numerator = 0.0;
730 tab_text (t, 1, (v * lines_per_variable) + i + 1,
731 TAB_LEFT | TAT_TITLE,
732 _("Assume equal variances"));
734 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
735 TAB_LEFT | TAT_TITLE,
736 _("Does not assume equal"));
739 tab_text (t, 2, (v * lines_per_variable) + i + 1,
740 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
743 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
744 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
747 if ( bad_contrast[i])
750 group_stat_array = hsh_sort(group_hash);
752 for (ci = 0 ; ci < hsh_count(group_hash) ; ++ci)
754 const double coef = subc_list_double_at(&cmd.dl_contrast[i], ci);
755 struct group_statistics *gs = group_stat_array[ci];
757 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
759 contrast_value += coef * gs->mean;
761 coef_msq += (coef * coef) / gs->n ;
763 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
765 df_numerator += (coef * coef) * winv;
766 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
768 sec_vneq = sqrt(sec_vneq);
770 df_numerator = pow2(df_numerator);
772 tab_float (t, 3, (v * lines_per_variable) + i + 1,
773 TAB_RIGHT, contrast_value, 8,2);
775 tab_float (t, 3, (v * lines_per_variable) + i + 1 +
777 TAB_RIGHT, contrast_value, 8,2);
779 std_error_contrast = sqrt(grp_data->mse * coef_msq);
782 tab_float (t, 4, (v * lines_per_variable) + i + 1,
783 TAB_RIGHT, std_error_contrast,
786 T = fabs(contrast_value / std_error_contrast) ;
790 tab_float (t, 5, (v * lines_per_variable) + i + 1,
794 df = grp_data->ugs.n - grp_data->n_groups;
796 /* Degrees of Freedom */
797 tab_float (t, 6, (v * lines_per_variable) + i + 1,
802 /* Significance TWO TAILED !!*/
803 tab_float (t, 7, (v * lines_per_variable) + i + 1,
804 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
808 /* Now for the Variances NOT Equal case */
812 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
817 T = contrast_value / sec_vneq;
819 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
824 df = df_numerator / df_denominator;
827 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
831 /* The Significance */
833 tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
834 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
841 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
849 /* ONEWAY ANOVA Calculations */
851 static void postcalc ( struct cmd_oneway *cmd UNUSED );
853 static void precalc ( struct cmd_oneway *cmd UNUSED );
857 /* Pre calculations */
859 precalc ( struct cmd_oneway *cmd UNUSED )
863 for(i=0; i< n_vars ; ++i)
865 struct group_proc *gp = group_proc_get (vars[i]);
866 struct group_statistics *totals = &gp->ugs;
868 /* Create a hash for each of the dependent variables.
869 The hash contains a group_statistics structure,
870 and is keyed by value of the independent variable */
874 (hsh_compare_func *) compare_group,
875 (hsh_hash_func *) hash_group,
876 (hsh_free_func *) free_group,
877 (void *) indep_var->width );
884 totals->maximum = - DBL_MAX;
885 totals->minimum = DBL_MAX;
891 run_oneway(const struct casefile *cf, void *cmd_)
893 struct casereader *r;
896 struct cmd_oneway *cmd = (struct cmd_oneway *) cmd_;
898 global_group_hash = hsh_create(4,
899 (hsh_compare_func *) compare_values,
900 (hsh_hash_func *) hash_value,
902 (void *) indep_var->width );
905 for(r = casefile_get_reader (cf);
906 casereader_read (r, &c) ;
911 const double weight =
912 dict_get_case_weight(default_dict,&c,&bad_weight_warn);
914 const union value *indep_val = case_data (&c, indep_var->fv);
916 /* Deal with missing values */
917 if ( value_is_missing(&indep_var->miss, indep_val) )
920 /* Skip the entire case if /MISSING=LISTWISE is set */
921 if ( cmd->miss == ONEWAY_LISTWISE )
923 for(i = 0; i < n_vars ; ++i)
925 const struct variable *v = vars[i];
926 const union value *val = case_data (&c, v->fv);
928 if (value_is_missing(&v->miss, val) )
937 hsh_insert ( global_group_hash, (void *) indep_val );
939 for ( i = 0 ; i < n_vars ; ++i )
941 const struct variable *v = vars[i];
943 const union value *val = case_data (&c, v->fv);
945 struct group_proc *gp = group_proc_get (vars[i]);
946 struct hsh_table *group_hash = gp->group_hash;
948 struct group_statistics *gs;
950 gs = hsh_find(group_hash, (void *) indep_val );
954 gs = xmalloc (sizeof *gs);
960 gs->minimum = DBL_MAX;
961 gs->maximum = -DBL_MAX;
963 hsh_insert ( group_hash, (void *) gs );
966 if (! value_is_missing(&v->miss, val) )
968 struct group_statistics *totals = &gp->ugs;
971 totals->sum+=weight * val->f;
972 totals->ssq+=weight * val->f * val->f;
974 if ( val->f * weight < totals->minimum )
975 totals->minimum = val->f * weight;
977 if ( val->f * weight > totals->maximum )
978 totals->maximum = val->f * weight;
981 gs->sum+=weight * val->f;
982 gs->ssq+=weight * val->f * val->f;
984 if ( val->f * weight < gs->minimum )
985 gs->minimum = val->f * weight;
987 if ( val->f * weight > gs->maximum )
988 gs->maximum = val->f * weight;
991 gp->n_groups = hsh_count ( group_hash );
995 casereader_destroy (r);
1000 if ( stat_tables & STAT_HOMO )
1001 levene(cf, indep_var, n_vars, vars,
1002 (cmd->miss == ONEWAY_LISTWISE) ? LEV_LISTWISE : LEV_ANALYSIS ,
1005 ostensible_number_of_groups = hsh_count (global_group_hash);
1014 /* Post calculations for the ONEWAY command */
1016 postcalc ( struct cmd_oneway *cmd UNUSED )
1021 for(i = 0; i < n_vars ; ++i)
1023 struct group_proc *gp = group_proc_get (vars[i]);
1024 struct hsh_table *group_hash = gp->group_hash;
1025 struct group_statistics *totals = &gp->ugs;
1027 struct hsh_iterator g;
1028 struct group_statistics *gs;
1030 for (gs = hsh_first (group_hash,&g);
1032 gs = hsh_next(group_hash,&g))
1034 gs->mean=gs->sum / gs->n;
1035 gs->s_std_dev= sqrt(
1036 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1041 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1044 gs->se_mean = gs->std_dev / sqrt(gs->n);
1045 gs->mean_diff= gs->sum_diff / gs->n;
1051 totals->mean = totals->sum / totals->n;
1052 totals->std_dev= sqrt(
1053 totals->n/(totals->n-1) *
1054 ( (totals->ssq / totals->n ) - totals->mean * totals->mean )
1057 totals->se_mean = totals->std_dev / sqrt(totals->n);