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 <language/command.h>
35 #include <language/dictionary/split-file.h>
36 #include <language/lexer/lexer.h>
37 #include <libpspp/alloc.h>
38 #include <libpspp/compiler.h>
39 #include <libpspp/hash.h>
40 #include <libpspp/magic.h>
41 #include <libpspp/message.h>
42 #include <libpspp/message.h>
43 #include <libpspp/misc.h>
44 #include <libpspp/str.h>
45 #include <math/group-proc.h>
46 #include <math/group.h>
47 #include <math/levene.h>
48 #include <output/manager.h>
49 #include <output/table.h>
50 #include "sort-criteria.h"
53 #define _(msgid) gettext (msgid)
60 missing=miss:!analysis/listwise,
61 incl:include/!exclude;
62 +contrast= double list;
63 +statistics[st_]=descriptives,homogeneity.
70 static bool bad_weight_warn = true;
73 static struct cmd_oneway cmd;
75 /* The independent variable */
76 static struct variable *indep_var;
78 /* Number of dependent variables */
81 /* The dependent variables */
82 static struct variable **vars;
85 /* A hash table containing all the distinct values of the independent
87 static struct hsh_table *global_group_hash ;
89 /* The number of distinct values of the independent variable, when all
90 missing values are disregarded */
91 static int ostensible_number_of_groups = -1;
94 /* Function to use for testing for missing values */
95 static is_missing_func *value_is_missing;
98 static bool run_oneway(const struct ccase *first,
99 const struct casefile *cf, void *_mode, const struct dataset *);
102 /* Routines to show the output tables */
103 static void show_anova_table(void);
104 static void show_descriptives(void);
105 static void show_homogeneity(void);
107 static void show_contrast_coeffs(short *);
108 static void show_contrast_tests(short *);
111 enum stat_table_t {STAT_DESC = 1, STAT_HOMO = 2};
113 static enum stat_table_t stat_tables ;
115 void output_oneway(void);
119 cmd_oneway (struct dataset *ds)
124 if ( !parse_oneway (ds, &cmd, NULL) )
127 /* If /MISSING=INCLUDE is set, then user missing values are ignored */
128 if (cmd.incl == ONEWAY_INCLUDE )
129 value_is_missing = mv_is_value_system_missing;
131 value_is_missing = mv_is_value_missing;
133 /* What statistics were requested */
134 if ( cmd.sbc_statistics )
137 for (i = 0 ; i < ONEWAY_ST_count ; ++i )
139 if ( ! cmd.a_statistics[i] ) continue;
142 case ONEWAY_ST_DESCRIPTIVES:
143 stat_tables |= STAT_DESC;
145 case ONEWAY_ST_HOMOGENEITY:
146 stat_tables |= STAT_HOMO;
152 ok = multipass_procedure_with_splits (ds, run_oneway, &cmd);
157 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
165 short *bad_contrast ;
167 bad_contrast = xnmalloc (cmd.sbc_contrast, sizeof *bad_contrast);
169 /* Check the sanity of the given contrast values */
170 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
176 if ( subc_list_double_count(&cmd.dl_contrast[i]) !=
177 ostensible_number_of_groups )
180 _("Number of contrast coefficients must equal the number of groups"));
185 for (j=0; j < ostensible_number_of_groups ; ++j )
186 sum += subc_list_double_at(&cmd.dl_contrast[i],j);
189 msg(SW,_("Coefficients for contrast %d do not total zero"),i + 1);
192 if ( stat_tables & STAT_DESC )
195 if ( stat_tables & STAT_HOMO )
200 if (cmd.sbc_contrast )
202 show_contrast_coeffs(bad_contrast);
203 show_contrast_tests(bad_contrast);
210 for (i = 0 ; i < n_vars ; ++i )
212 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
214 hsh_destroy(group_hash);
217 hsh_destroy(global_group_hash);
224 /* Parser for the variables sub command */
226 oneway_custom_variables(struct dataset *ds, struct cmd_oneway *cmd UNUSED, void *aux UNUSED)
228 struct dictionary *dict = dataset_dict (ds);
232 if ((token != T_ID || dict_lookup_var (dict, tokid) == NULL)
236 if (!parse_variables (dict, &vars, &n_vars,
238 | PV_NUMERIC | PV_NO_SCRATCH) )
246 if ( ! lex_match(T_BY))
249 indep_var = parse_variable (dict);
253 msg(SE,_("`%s' is not a variable name"),tokid);
261 /* Show the ANOVA table */
263 show_anova_table(void)
267 size_t n_rows = n_vars * 3 + 1;
272 t = tab_create (n_cols,n_rows,0);
273 tab_headers (t, 2, 0, 1, 0);
274 tab_dim (t, tab_natural_dimensions);
281 n_cols - 1, n_rows - 1);
283 tab_hline (t, TAL_2, 0, n_cols - 1, 1 );
284 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
285 tab_vline (t, TAL_0, 1, 0, 0);
287 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
288 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
289 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
290 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
291 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
294 for ( i=0 ; i < n_vars ; ++i )
296 struct group_statistics *totals = &group_proc_get (vars[i])->ugs;
297 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
298 struct hsh_iterator g;
299 struct group_statistics *gs;
301 const char *s = var_to_string(vars[i]);
303 for (gs = hsh_first (group_hash,&g);
305 gs = hsh_next(group_hash,&g))
307 ssa += (gs->sum * gs->sum)/gs->n;
310 ssa -= ( totals->sum * totals->sum ) / totals->n ;
312 tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s);
313 tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups"));
314 tab_text (t, 1, i * 3 + 2, TAB_LEFT | TAT_TITLE, _("Within Groups"));
315 tab_text (t, 1, i * 3 + 3, TAB_LEFT | TAT_TITLE, _("Total"));
318 tab_hline(t, TAL_1, 0, n_cols - 1 , i * 3 + 1);
321 struct group_proc *gp = group_proc_get (vars[i]);
322 const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ;
323 const double df1 = gp->n_groups - 1;
324 const double df2 = totals->n - gp->n_groups ;
325 const double msa = ssa / df1;
327 gp->mse = (sst - ssa) / df2;
330 /* Sums of Squares */
331 tab_float (t, 2, i * 3 + 1, 0, ssa, 10, 2);
332 tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2);
333 tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2);
336 /* Degrees of freedom */
337 tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0);
338 tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0);
339 tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
342 tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3);
343 tab_float (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, 8, 3);
347 const double F = msa/gp->mse ;
350 tab_float (t, 5, i * 3 + 1, 0, F, 8, 3);
352 /* The significance */
353 tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
361 tab_title (t, _("ANOVA"));
367 /* Show the descriptives table */
369 show_descriptives(void)
376 const double confidence=0.95;
377 const double q = (1.0 - confidence) / 2.0;
382 for ( v = 0 ; v < n_vars ; ++v )
383 n_rows += group_proc_get (vars[v])->n_groups + 1;
385 t = tab_create (n_cols,n_rows,0);
386 tab_headers (t, 2, 0, 2, 0);
387 tab_dim (t, tab_natural_dimensions);
390 /* Put a frame around the entire box, and vertical lines inside */
395 n_cols - 1, n_rows - 1);
397 /* Underline headers */
398 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
399 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
401 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
402 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
403 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
404 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
407 tab_vline(t, TAL_0, 7, 0, 0);
408 tab_hline(t, TAL_1, 6, 7, 1);
409 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
411 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
412 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
414 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
415 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
418 tab_title (t, _("Descriptives"));
422 for ( v=0 ; v < n_vars ; ++v )
427 struct group_proc *gp = group_proc_get (vars[v]);
429 struct group_statistics *gs;
430 struct group_statistics *totals = &gp->ugs;
432 const char *s = var_to_string(vars[v]);
434 struct group_statistics *const *gs_array =
435 (struct group_statistics *const *) hsh_sort(gp->group_hash);
438 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
440 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
442 for (count = 0 ; count < hsh_count(gp->group_hash) ; ++count)
444 gs = gs_array[count];
446 tab_text (t, 1, row + count,
447 TAB_LEFT | TAT_TITLE ,value_to_string(&gs->id,indep_var));
449 /* Now fill in the numbers ... */
451 tab_float (t, 2, row + count, 0, gs->n, 8,0);
453 tab_float (t, 3, row + count, 0, gs->mean,8,2);
455 tab_float (t, 4, row + count, 0, gs->std_dev,8,2);
457 std_error = gs->std_dev/sqrt(gs->n) ;
458 tab_float (t, 5, row + count, 0,
461 /* Now the confidence interval */
463 T = gsl_cdf_tdist_Qinv(q,gs->n - 1);
465 tab_float(t, 6, row + count, 0,
466 gs->mean - T * std_error, 8, 2);
468 tab_float(t, 7, row + count, 0,
469 gs->mean + T * std_error, 8, 2);
473 tab_float(t, 8, row + count, 0, gs->minimum, 8, 2);
474 tab_float(t, 9, row + count, 0, gs->maximum, 8, 2);
478 tab_text (t, 1, row + count,
479 TAB_LEFT | TAT_TITLE ,_("Total"));
481 tab_float (t, 2, row + count, 0, totals->n, 8,0);
483 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
485 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
487 std_error = totals->std_dev/sqrt(totals->n) ;
489 tab_float (t, 5, row + count, 0, std_error, 8,2);
491 /* Now the confidence interval */
493 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
495 tab_float(t, 6, row + count, 0,
496 totals->mean - T * std_error, 8, 2);
498 tab_float(t, 7, row + count, 0,
499 totals->mean + T * std_error, 8, 2);
503 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
504 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
506 row += gp->n_groups + 1;
515 /* Show the homogeneity table */
517 show_homogeneity(void)
521 size_t n_rows = n_vars + 1;
526 t = tab_create (n_cols,n_rows,0);
527 tab_headers (t, 1, 0, 1, 0);
528 tab_dim (t, tab_natural_dimensions);
530 /* Put a frame around the entire box, and vertical lines inside */
535 n_cols - 1, n_rows - 1);
538 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
539 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
542 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
543 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
544 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
545 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
548 tab_title (t, _("Test of Homogeneity of Variances"));
550 for ( v=0 ; v < n_vars ; ++v )
553 const struct variable *var = vars[v];
554 const struct group_proc *gp = group_proc_get (vars[v]);
555 const char *s = var_to_string(var);
556 const struct group_statistics *totals = &gp->ugs;
558 const double df1 = gp->n_groups - 1;
559 const double df2 = totals->n - gp->n_groups ;
561 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
564 tab_float (t, 1, v + 1, TAB_RIGHT, F, 8,3);
565 tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0);
566 tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0);
568 /* Now the significance */
569 tab_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
578 /* Show the contrast coefficients table */
580 show_contrast_coeffs(short *bad_contrast)
582 int n_cols = 2 + ostensible_number_of_groups;
583 int n_rows = 2 + cmd.sbc_contrast;
584 union value *group_value;
586 void *const *group_values ;
590 t = tab_create (n_cols,n_rows,0);
591 tab_headers (t, 2, 0, 2, 0);
592 tab_dim (t, tab_natural_dimensions);
594 /* Put a frame around the entire box, and vertical lines inside */
599 n_cols - 1, n_rows - 1);
613 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
614 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
616 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
618 tab_title (t, _("Contrast Coefficients"));
620 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
623 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
624 var_to_string(indep_var));
626 group_values = hsh_sort(global_group_hash);
628 count < hsh_count(global_group_hash) ;
632 group_value = group_values[count];
634 tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
635 value_to_string(group_value, indep_var));
637 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
639 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
641 if ( bad_contrast[i] )
642 tab_text(t, count + 2, i + 2, TAB_RIGHT, "?" );
644 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
645 subc_list_double_at(&cmd.dl_contrast[i], count)
654 /* Show the results of the contrast tests */
656 show_contrast_tests(short *bad_contrast)
660 size_t n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
664 t = tab_create (n_cols,n_rows,0);
665 tab_headers (t, 3, 0, 1, 0);
666 tab_dim (t, tab_natural_dimensions);
668 /* Put a frame around the entire box, and vertical lines inside */
673 n_cols - 1, n_rows - 1);
681 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
682 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
685 tab_title (t, _("Contrast Tests"));
687 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
688 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
689 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
690 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
691 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
692 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
694 for ( v = 0 ; v < n_vars ; ++v )
697 int lines_per_variable = 2 * cmd.sbc_contrast;
700 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
701 var_to_string(vars[v]));
703 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
706 double contrast_value = 0.0;
707 double coef_msq = 0.0;
708 struct group_proc *grp_data = group_proc_get (vars[v]);
709 struct hsh_table *group_hash = grp_data->group_hash;
711 void *const *group_stat_array;
714 double std_error_contrast ;
719 /* Note: The calculation of the degrees of freedom in the
720 "variances not equal" case is painfull!!
721 The following formula may help to understand it:
722 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
725 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
730 double df_denominator = 0.0;
731 double df_numerator = 0.0;
734 tab_text (t, 1, (v * lines_per_variable) + i + 1,
735 TAB_LEFT | TAT_TITLE,
736 _("Assume equal variances"));
738 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
739 TAB_LEFT | TAT_TITLE,
740 _("Does not assume equal"));
743 tab_text (t, 2, (v * lines_per_variable) + i + 1,
744 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
747 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
748 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
751 if ( bad_contrast[i])
754 group_stat_array = hsh_sort(group_hash);
756 for (ci = 0 ; ci < hsh_count(group_hash) ; ++ci)
758 const double coef = subc_list_double_at(&cmd.dl_contrast[i], ci);
759 struct group_statistics *gs = group_stat_array[ci];
761 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
763 contrast_value += coef * gs->mean;
765 coef_msq += (coef * coef) / gs->n ;
767 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
769 df_numerator += (coef * coef) * winv;
770 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
772 sec_vneq = sqrt(sec_vneq);
774 df_numerator = pow2(df_numerator);
776 tab_float (t, 3, (v * lines_per_variable) + i + 1,
777 TAB_RIGHT, contrast_value, 8,2);
779 tab_float (t, 3, (v * lines_per_variable) + i + 1 +
781 TAB_RIGHT, contrast_value, 8,2);
783 std_error_contrast = sqrt(grp_data->mse * coef_msq);
786 tab_float (t, 4, (v * lines_per_variable) + i + 1,
787 TAB_RIGHT, std_error_contrast,
790 T = fabs(contrast_value / std_error_contrast) ;
794 tab_float (t, 5, (v * lines_per_variable) + i + 1,
798 df = grp_data->ugs.n - grp_data->n_groups;
800 /* Degrees of Freedom */
801 tab_float (t, 6, (v * lines_per_variable) + i + 1,
806 /* Significance TWO TAILED !!*/
807 tab_float (t, 7, (v * lines_per_variable) + i + 1,
808 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
812 /* Now for the Variances NOT Equal case */
816 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
821 T = contrast_value / sec_vneq;
823 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
828 df = df_numerator / df_denominator;
831 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
835 /* The Significance */
837 tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
838 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
845 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
853 /* ONEWAY ANOVA Calculations */
855 static void postcalc ( struct cmd_oneway *cmd UNUSED );
857 static void precalc ( struct cmd_oneway *cmd UNUSED );
861 /* Pre calculations */
863 precalc ( struct cmd_oneway *cmd UNUSED )
867 for(i=0; i< n_vars ; ++i)
869 struct group_proc *gp = group_proc_get (vars[i]);
870 struct group_statistics *totals = &gp->ugs;
872 /* Create a hash for each of the dependent variables.
873 The hash contains a group_statistics structure,
874 and is keyed by value of the independent variable */
878 (hsh_compare_func *) compare_group,
879 (hsh_hash_func *) hash_group,
880 (hsh_free_func *) free_group,
881 (void *) indep_var->width );
888 totals->maximum = - DBL_MAX;
889 totals->minimum = DBL_MAX;
895 run_oneway(const struct ccase *first, const struct casefile *cf, void *cmd_, const struct dataset *ds)
897 struct casereader *r;
900 struct cmd_oneway *cmd = (struct cmd_oneway *) cmd_;
902 output_split_file_values (ds, first);
904 global_group_hash = hsh_create(4,
905 (hsh_compare_func *) compare_values,
906 (hsh_hash_func *) hash_value,
908 (void *) indep_var->width );
911 for(r = casefile_get_reader (cf);
912 casereader_read (r, &c) ;
917 const double weight =
918 dict_get_case_weight (dataset_dict (ds), &c, &bad_weight_warn);
920 const union value *indep_val = case_data (&c, indep_var->fv);
922 /* Deal with missing values */
923 if ( value_is_missing(&indep_var->miss, indep_val) )
926 /* Skip the entire case if /MISSING=LISTWISE is set */
927 if ( cmd->miss == ONEWAY_LISTWISE )
929 for(i = 0; i < n_vars ; ++i)
931 const struct variable *v = vars[i];
932 const union value *val = case_data (&c, v->fv);
934 if (value_is_missing(&v->miss, val) )
943 hsh_insert ( global_group_hash, (void *) indep_val );
945 for ( i = 0 ; i < n_vars ; ++i )
947 const struct variable *v = vars[i];
949 const union value *val = case_data (&c, v->fv);
951 struct group_proc *gp = group_proc_get (vars[i]);
952 struct hsh_table *group_hash = gp->group_hash;
954 struct group_statistics *gs;
956 gs = hsh_find(group_hash, (void *) indep_val );
960 gs = xmalloc (sizeof *gs);
966 gs->minimum = DBL_MAX;
967 gs->maximum = -DBL_MAX;
969 hsh_insert ( group_hash, (void *) gs );
972 if (! value_is_missing(&v->miss, val) )
974 struct group_statistics *totals = &gp->ugs;
977 totals->sum+=weight * val->f;
978 totals->ssq+=weight * val->f * val->f;
980 if ( val->f * weight < totals->minimum )
981 totals->minimum = val->f * weight;
983 if ( val->f * weight > totals->maximum )
984 totals->maximum = val->f * weight;
987 gs->sum+=weight * val->f;
988 gs->ssq+=weight * val->f * val->f;
990 if ( val->f * weight < gs->minimum )
991 gs->minimum = val->f * weight;
993 if ( val->f * weight > gs->maximum )
994 gs->maximum = val->f * weight;
997 gp->n_groups = hsh_count ( group_hash );
1001 casereader_destroy (r);
1006 if ( stat_tables & STAT_HOMO )
1007 levene (dataset_dict (ds), cf, indep_var, n_vars, vars,
1008 (cmd->miss == ONEWAY_LISTWISE) ? LEV_LISTWISE : LEV_ANALYSIS ,
1011 ostensible_number_of_groups = hsh_count (global_group_hash);
1020 /* Post calculations for the ONEWAY command */
1022 postcalc ( struct cmd_oneway *cmd UNUSED )
1027 for(i = 0; i < n_vars ; ++i)
1029 struct group_proc *gp = group_proc_get (vars[i]);
1030 struct hsh_table *group_hash = gp->group_hash;
1031 struct group_statistics *totals = &gp->ugs;
1033 struct hsh_iterator g;
1034 struct group_statistics *gs;
1036 for (gs = hsh_first (group_hash,&g);
1038 gs = hsh_next(group_hash,&g))
1040 gs->mean=gs->sum / gs->n;
1041 gs->s_std_dev= sqrt(
1042 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1047 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1050 gs->se_mean = gs->std_dev / sqrt(gs->n);
1051 gs->mean_diff= gs->sum_diff / gs->n;
1057 totals->mean = totals->sum / totals->n;
1058 totals->std_dev= sqrt(
1059 totals->n/(totals->n-1) *
1060 ( (totals->ssq / totals->n ) - totals->mean * totals->mean )
1063 totals->se_mean = totals->std_dev / sqrt(totals->n);