1 /* PSPP - One way ANOVA. -*-c-*-
3 Copyright (C) 1997-9, 2000, 2007 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <gsl/gsl_cdf.h>
27 #include <data/case.h>
28 #include <data/casegrouper.h>
29 #include <data/casereader.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/misc.h>
43 #include <libpspp/str.h>
44 #include <libpspp/taint.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.
68 static struct cmd_oneway cmd;
70 /* The independent variable */
71 static const struct variable *indep_var;
73 /* Number of dependent variables */
76 /* The dependent variables */
77 static const struct variable **vars;
80 /* A hash table containing all the distinct values of the independent
82 static struct hsh_table *global_group_hash ;
84 /* The number of distinct values of the independent variable, when all
85 missing values are disregarded */
86 static int ostensible_number_of_groups = -1;
89 static void run_oneway (struct cmd_oneway *, struct casereader *,
90 const struct dataset *);
93 /* Routines to show the output tables */
94 static void show_anova_table(void);
95 static void show_descriptives(void);
96 static void show_homogeneity(void);
98 static void show_contrast_coeffs(short *);
99 static void show_contrast_tests(short *);
102 enum stat_table_t {STAT_DESC = 1, STAT_HOMO = 2};
104 static enum stat_table_t stat_tables ;
106 void output_oneway(void);
110 cmd_oneway (struct lexer *lexer, struct dataset *ds)
112 struct casegrouper *grouper;
113 struct casereader *group;
117 if ( !parse_oneway (lexer, ds, &cmd, NULL) )
120 /* What statistics were requested */
121 if ( cmd.sbc_statistics )
124 for (i = 0 ; i < ONEWAY_ST_count ; ++i )
126 if ( ! cmd.a_statistics[i] ) continue;
129 case ONEWAY_ST_DESCRIPTIVES:
130 stat_tables |= STAT_DESC;
132 case ONEWAY_ST_HOMOGENEITY:
133 stat_tables |= STAT_HOMO;
139 /* Data pass. FIXME: error handling. */
140 grouper = casegrouper_create_splits (proc_open (ds), dataset_dict (ds));
141 while (casegrouper_get_next_group (grouper, &group))
142 run_oneway (&cmd, group, ds);
143 ok = casegrouper_destroy (grouper);
144 ok = proc_commit (ds) && ok;
149 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
157 short *bad_contrast ;
159 bad_contrast = xnmalloc (cmd.sbc_contrast, sizeof *bad_contrast);
161 /* Check the sanity of the given contrast values */
162 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
168 if ( subc_list_double_count(&cmd.dl_contrast[i]) !=
169 ostensible_number_of_groups )
172 _("Number of contrast coefficients must equal the number of groups"));
177 for (j=0; j < ostensible_number_of_groups ; ++j )
178 sum += subc_list_double_at(&cmd.dl_contrast[i],j);
181 msg(SW,_("Coefficients for contrast %d do not total zero"),
185 if ( stat_tables & STAT_DESC )
188 if ( stat_tables & STAT_HOMO )
193 if (cmd.sbc_contrast )
195 show_contrast_coeffs(bad_contrast);
196 show_contrast_tests(bad_contrast);
203 for (i = 0 ; i < n_vars ; ++i )
205 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
207 hsh_destroy(group_hash);
210 hsh_destroy(global_group_hash);
217 /* Parser for the variables sub command */
219 oneway_custom_variables (struct lexer *lexer,
220 struct dataset *ds, struct cmd_oneway *cmd UNUSED,
223 struct dictionary *dict = dataset_dict (ds);
225 lex_match (lexer, '=');
227 if ((lex_token (lexer) != T_ID || dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
228 && lex_token (lexer) != T_ALL)
231 if (!parse_variables_const (lexer, dict, &vars, &n_vars,
233 | PV_NUMERIC | PV_NO_SCRATCH) )
241 if ( ! lex_match (lexer, T_BY))
244 indep_var = parse_variable (lexer, dict);
248 msg(SE,_("`%s' is not a variable name"),lex_tokid (lexer));
256 /* Show the ANOVA table */
258 show_anova_table(void)
262 size_t n_rows = n_vars * 3 + 1;
267 t = tab_create (n_cols,n_rows,0);
268 tab_headers (t, 2, 0, 1, 0);
269 tab_dim (t, tab_natural_dimensions);
276 n_cols - 1, n_rows - 1);
278 tab_hline (t, TAL_2, 0, n_cols - 1, 1 );
279 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
280 tab_vline (t, TAL_0, 1, 0, 0);
282 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
283 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
284 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
285 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
286 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
289 for ( i=0 ; i < n_vars ; ++i )
291 struct group_statistics *totals = &group_proc_get (vars[i])->ugs;
292 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
293 struct hsh_iterator g;
294 struct group_statistics *gs;
296 const char *s = var_to_string(vars[i]);
298 for (gs = hsh_first (group_hash,&g);
300 gs = hsh_next(group_hash,&g))
302 ssa += (gs->sum * gs->sum)/gs->n;
305 ssa -= ( totals->sum * totals->sum ) / totals->n ;
307 tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s);
308 tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups"));
309 tab_text (t, 1, i * 3 + 2, TAB_LEFT | TAT_TITLE, _("Within Groups"));
310 tab_text (t, 1, i * 3 + 3, TAB_LEFT | TAT_TITLE, _("Total"));
313 tab_hline(t, TAL_1, 0, n_cols - 1 , i * 3 + 1);
316 struct group_proc *gp = group_proc_get (vars[i]);
317 const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ;
318 const double df1 = gp->n_groups - 1;
319 const double df2 = totals->n - gp->n_groups ;
320 const double msa = ssa / df1;
322 gp->mse = (sst - ssa) / df2;
325 /* Sums of Squares */
326 tab_float (t, 2, i * 3 + 1, 0, ssa, 10, 2);
327 tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2);
328 tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2);
331 /* Degrees of freedom */
332 tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0);
333 tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0);
334 tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
337 tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3);
338 tab_float (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, 8, 3);
342 const double F = msa/gp->mse ;
345 tab_float (t, 5, i * 3 + 1, 0, F, 8, 3);
347 /* The significance */
348 tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
356 tab_title (t, _("ANOVA"));
361 /* Show the descriptives table */
363 show_descriptives(void)
370 const double confidence=0.95;
371 const double q = (1.0 - confidence) / 2.0;
376 for ( v = 0 ; v < n_vars ; ++v )
377 n_rows += group_proc_get (vars[v])->n_groups + 1;
379 t = tab_create (n_cols,n_rows,0);
380 tab_headers (t, 2, 0, 2, 0);
381 tab_dim (t, tab_natural_dimensions);
384 /* Put a frame around the entire box, and vertical lines inside */
389 n_cols - 1, n_rows - 1);
391 /* Underline headers */
392 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
393 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
395 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
396 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
397 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
398 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
401 tab_vline(t, TAL_0, 7, 0, 0);
402 tab_hline(t, TAL_1, 6, 7, 1);
403 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
405 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
406 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
408 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
409 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
412 tab_title (t, _("Descriptives"));
416 for ( v=0 ; v < n_vars ; ++v )
421 struct group_proc *gp = group_proc_get (vars[v]);
423 struct group_statistics *gs;
424 struct group_statistics *totals = &gp->ugs;
426 const char *s = var_to_string(vars[v]);
428 struct group_statistics *const *gs_array =
429 (struct group_statistics *const *) hsh_sort(gp->group_hash);
432 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
434 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
436 for (count = 0 ; count < hsh_count(gp->group_hash) ; ++count)
438 gs = gs_array[count];
440 tab_text (t, 1, row + count,
441 TAB_LEFT | TAT_TITLE, var_get_value_name(indep_var,
444 /* Now fill in the numbers ... */
446 tab_float (t, 2, row + count, 0, gs->n, 8,0);
448 tab_float (t, 3, row + count, 0, gs->mean,8,2);
450 tab_float (t, 4, row + count, 0, gs->std_dev,8,2);
452 std_error = gs->std_dev/sqrt(gs->n) ;
453 tab_float (t, 5, row + count, 0,
456 /* Now the confidence interval */
458 T = gsl_cdf_tdist_Qinv(q,gs->n - 1);
460 tab_float(t, 6, row + count, 0,
461 gs->mean - T * std_error, 8, 2);
463 tab_float(t, 7, row + count, 0,
464 gs->mean + T * std_error, 8, 2);
468 tab_float(t, 8, row + count, 0, gs->minimum, 8, 2);
469 tab_float(t, 9, row + count, 0, gs->maximum, 8, 2);
473 tab_text (t, 1, row + count,
474 TAB_LEFT | TAT_TITLE ,_("Total"));
476 tab_float (t, 2, row + count, 0, totals->n, 8,0);
478 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
480 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
482 std_error = totals->std_dev/sqrt(totals->n) ;
484 tab_float (t, 5, row + count, 0, std_error, 8,2);
486 /* Now the confidence interval */
488 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
490 tab_float(t, 6, row + count, 0,
491 totals->mean - T * std_error, 8, 2);
493 tab_float(t, 7, row + count, 0,
494 totals->mean + T * std_error, 8, 2);
498 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
499 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
501 row += gp->n_groups + 1;
510 /* Show the homogeneity table */
512 show_homogeneity(void)
516 size_t n_rows = n_vars + 1;
521 t = tab_create (n_cols,n_rows,0);
522 tab_headers (t, 1, 0, 1, 0);
523 tab_dim (t, tab_natural_dimensions);
525 /* Put a frame around the entire box, and vertical lines inside */
530 n_cols - 1, n_rows - 1);
533 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
534 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
537 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
538 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
539 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
540 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
543 tab_title (t, _("Test of Homogeneity of Variances"));
545 for ( v=0 ; v < n_vars ; ++v )
548 const struct variable *var = vars[v];
549 const struct group_proc *gp = group_proc_get (vars[v]);
550 const char *s = var_to_string(var);
551 const struct group_statistics *totals = &gp->ugs;
553 const double df1 = gp->n_groups - 1;
554 const double df2 = totals->n - gp->n_groups ;
556 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
559 tab_float (t, 1, v + 1, TAB_RIGHT, F, 8,3);
560 tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0);
561 tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0);
563 /* Now the significance */
564 tab_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
571 /* Show the contrast coefficients table */
573 show_contrast_coeffs (short *bad_contrast)
575 int n_cols = 2 + ostensible_number_of_groups;
576 int n_rows = 2 + cmd.sbc_contrast;
577 union value *group_value;
579 void *const *group_values ;
583 t = tab_create (n_cols,n_rows,0);
584 tab_headers (t, 2, 0, 2, 0);
585 tab_dim (t, tab_natural_dimensions);
587 /* Put a frame around the entire box, and vertical lines inside */
592 n_cols - 1, n_rows - 1);
606 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
607 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
609 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
611 tab_title (t, _("Contrast Coefficients"));
613 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
616 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
617 var_to_string(indep_var));
619 group_values = hsh_sort(global_group_hash);
621 count < hsh_count(global_group_hash) ;
625 group_value = group_values[count];
627 tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
628 var_get_value_name (indep_var, group_value));
630 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
632 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
634 if ( bad_contrast[i] )
635 tab_text(t, count + 2, i + 2, TAB_RIGHT, "?" );
637 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
638 subc_list_double_at(&cmd.dl_contrast[i], count)
647 /* Show the results of the contrast tests */
649 show_contrast_tests(short *bad_contrast)
653 size_t n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
657 t = tab_create (n_cols,n_rows,0);
658 tab_headers (t, 3, 0, 1, 0);
659 tab_dim (t, tab_natural_dimensions);
661 /* Put a frame around the entire box, and vertical lines inside */
666 n_cols - 1, n_rows - 1);
674 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
675 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
678 tab_title (t, _("Contrast Tests"));
680 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
681 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
682 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
683 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
684 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
685 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
687 for ( v = 0 ; v < n_vars ; ++v )
690 int lines_per_variable = 2 * cmd.sbc_contrast;
693 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
694 var_to_string(vars[v]));
696 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
699 double contrast_value = 0.0;
700 double coef_msq = 0.0;
701 struct group_proc *grp_data = group_proc_get (vars[v]);
702 struct hsh_table *group_hash = grp_data->group_hash;
704 void *const *group_stat_array;
707 double std_error_contrast ;
712 /* Note: The calculation of the degrees of freedom in the
713 "variances not equal" case is painfull!!
714 The following formula may help to understand it:
715 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
718 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
723 double df_denominator = 0.0;
724 double df_numerator = 0.0;
727 tab_text (t, 1, (v * lines_per_variable) + i + 1,
728 TAB_LEFT | TAT_TITLE,
729 _("Assume equal variances"));
731 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
732 TAB_LEFT | TAT_TITLE,
733 _("Does not assume equal"));
736 tab_text (t, 2, (v * lines_per_variable) + i + 1,
737 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
740 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
741 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
744 if ( bad_contrast[i])
747 group_stat_array = hsh_sort(group_hash);
749 for (ci = 0 ; ci < hsh_count(group_hash) ; ++ci)
751 const double coef = subc_list_double_at(&cmd.dl_contrast[i], ci);
752 struct group_statistics *gs = group_stat_array[ci];
754 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
756 contrast_value += coef * gs->mean;
758 coef_msq += (coef * coef) / gs->n ;
760 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
762 df_numerator += (coef * coef) * winv;
763 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
765 sec_vneq = sqrt(sec_vneq);
767 df_numerator = pow2(df_numerator);
769 tab_float (t, 3, (v * lines_per_variable) + i + 1,
770 TAB_RIGHT, contrast_value, 8,2);
772 tab_float (t, 3, (v * lines_per_variable) + i + 1 +
774 TAB_RIGHT, contrast_value, 8,2);
776 std_error_contrast = sqrt(grp_data->mse * coef_msq);
779 tab_float (t, 4, (v * lines_per_variable) + i + 1,
780 TAB_RIGHT, std_error_contrast,
783 T = fabs(contrast_value / std_error_contrast) ;
787 tab_float (t, 5, (v * lines_per_variable) + i + 1,
791 df = grp_data->ugs.n - grp_data->n_groups;
793 /* Degrees of Freedom */
794 tab_float (t, 6, (v * lines_per_variable) + i + 1,
799 /* Significance TWO TAILED !!*/
800 tab_float (t, 7, (v * lines_per_variable) + i + 1,
801 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
805 /* Now for the Variances NOT Equal case */
809 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
814 T = contrast_value / sec_vneq;
816 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
821 df = df_numerator / df_denominator;
824 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
828 /* The Significance */
830 tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
831 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
838 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
846 /* ONEWAY ANOVA Calculations */
848 static void postcalc ( struct cmd_oneway *cmd UNUSED );
850 static void precalc ( struct cmd_oneway *cmd UNUSED );
854 /* Pre calculations */
856 precalc ( struct cmd_oneway *cmd UNUSED )
860 for(i=0; i< n_vars ; ++i)
862 struct group_proc *gp = group_proc_get (vars[i]);
863 struct group_statistics *totals = &gp->ugs;
865 /* Create a hash for each of the dependent variables.
866 The hash contains a group_statistics structure,
867 and is keyed by value of the independent variable */
871 (hsh_compare_func *) compare_group,
872 (hsh_hash_func *) hash_group,
873 (hsh_free_func *) free_group,
874 (void *) var_get_width (indep_var) );
881 totals->maximum = - DBL_MAX;
882 totals->minimum = DBL_MAX;
887 free_value (void *value_, const void *aux UNUSED)
889 union value *value = value_;
894 run_oneway (struct cmd_oneway *cmd,
895 struct casereader *input,
896 const struct dataset *ds)
899 struct dictionary *dict = dataset_dict (ds);
900 enum mv_class exclude;
901 struct casereader *reader;
904 if (!casereader_peek (input, 0, &c))
906 output_split_file_values (ds, &c);
909 taint = taint_clone (casereader_get_taint (input));
911 global_group_hash = hsh_create(4,
912 (hsh_compare_func *) compare_values,
913 (hsh_hash_func *) hash_value,
915 (void *) var_get_width (indep_var) );
919 exclude = cmd->incl != ONEWAY_INCLUDE ? MV_ANY : MV_SYSTEM;
920 input = casereader_create_filter_missing (input, &indep_var, 1,
922 if (cmd->miss == ONEWAY_LISTWISE)
923 input = casereader_create_filter_missing (input, vars, n_vars,
925 input = casereader_create_filter_weight (input, dict, NULL, NULL);
927 reader = casereader_clone (input);
928 for (; casereader_read (reader, &c); case_destroy (&c))
932 const double weight = dict_get_case_weight (dict, &c, NULL);
934 const union value *indep_val = case_data (&c, indep_var);
935 void **p = hsh_probe (global_group_hash, indep_val);
937 *p = value_dup (indep_val, var_get_width (indep_var));
939 for ( i = 0 ; i < n_vars ; ++i )
941 const struct variable *v = vars[i];
943 const union value *val = case_data (&c, v);
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 (!var_is_value_missing (v, val, exclude))
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 (reader);
1000 if ( stat_tables & STAT_HOMO )
1001 levene (dict, casereader_clone (input), indep_var, n_vars, vars, exclude);
1003 casereader_destroy (input);
1005 ostensible_number_of_groups = hsh_count (global_group_hash);
1007 if (!taint_has_tainted_successor (taint))
1009 taint_destroy (taint);
1013 /* Post calculations for the ONEWAY command */
1015 postcalc ( struct cmd_oneway *cmd UNUSED )
1020 for(i = 0; i < n_vars ; ++i)
1022 struct group_proc *gp = group_proc_get (vars[i]);
1023 struct hsh_table *group_hash = gp->group_hash;
1024 struct group_statistics *totals = &gp->ugs;
1026 struct hsh_iterator g;
1027 struct group_statistics *gs;
1029 for (gs = hsh_first (group_hash,&g);
1031 gs = hsh_next(group_hash,&g))
1033 gs->mean=gs->sum / gs->n;
1034 gs->s_std_dev= sqrt(
1035 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1040 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1043 gs->se_mean = gs->std_dev / sqrt(gs->n);
1044 gs->mean_diff= gs->sum_diff / gs->n;
1050 totals->mean = totals->sum / totals->n;
1051 totals->std_dev= sqrt(
1052 totals->n/(totals->n-1) *
1053 ( (totals->ssq / totals->n ) - totals->mean * totals->mean )
1056 totals->se_mean = totals->std_dev / sqrt(totals->n);