1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000, 2007 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include <gsl/gsl_cdf.h>
24 #include <data/case.h>
25 #include <data/casegrouper.h>
26 #include <data/casereader.h>
27 #include <data/dictionary.h>
28 #include <data/procedure.h>
29 #include <data/value-labels.h>
30 #include <data/variable.h>
31 #include <language/command.h>
32 #include <language/dictionary/split-file.h>
33 #include <language/lexer/lexer.h>
34 #include <libpspp/compiler.h>
35 #include <libpspp/hash.h>
36 #include <libpspp/message.h>
37 #include <libpspp/misc.h>
38 #include <libpspp/str.h>
39 #include <libpspp/taint.h>
40 #include <math/group-proc.h>
41 #include <math/group.h>
42 #include <math/levene.h>
43 #include <output/manager.h>
44 #include <output/table.h>
45 #include "sort-criteria.h"
50 #define _(msgid) gettext (msgid)
57 missing=miss:!analysis/listwise,
58 incl:include/!exclude;
59 +contrast= double list;
60 +statistics[st_]=descriptives,homogeneity.
65 static struct cmd_oneway cmd;
67 /* The independent variable */
68 static const struct variable *indep_var;
70 /* Number of dependent variables */
73 /* The dependent variables */
74 static const struct variable **vars;
77 /* A hash table containing all the distinct values of the independent
79 static struct hsh_table *global_group_hash ;
81 /* The number of distinct values of the independent variable, when all
82 missing values are disregarded */
83 static int ostensible_number_of_groups = -1;
86 static void run_oneway (struct cmd_oneway *, struct casereader *,
87 const struct dataset *);
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);
95 static void show_contrast_coeffs(short *);
96 static void show_contrast_tests(short *);
99 enum stat_table_t {STAT_DESC = 1, STAT_HOMO = 2};
101 static enum stat_table_t stat_tables ;
103 void output_oneway(void);
107 cmd_oneway (struct lexer *lexer, struct dataset *ds)
109 struct casegrouper *grouper;
110 struct casereader *group;
114 if ( !parse_oneway (lexer, ds, &cmd, NULL) )
117 /* What statistics were requested */
118 if ( cmd.sbc_statistics )
121 for (i = 0 ; i < ONEWAY_ST_count ; ++i )
123 if ( ! cmd.a_statistics[i] ) continue;
126 case ONEWAY_ST_DESCRIPTIVES:
127 stat_tables |= STAT_DESC;
129 case ONEWAY_ST_HOMOGENEITY:
130 stat_tables |= STAT_HOMO;
136 /* Data pass. FIXME: error handling. */
137 grouper = casegrouper_create_splits (proc_open (ds), dataset_dict (ds));
138 while (casegrouper_get_next_group (grouper, &group))
139 run_oneway (&cmd, group, ds);
140 ok = casegrouper_destroy (grouper);
141 ok = proc_commit (ds) && ok;
146 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
154 short *bad_contrast ;
156 bad_contrast = xnmalloc (cmd.sbc_contrast, sizeof *bad_contrast);
158 /* Check the sanity of the given contrast values */
159 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
165 if ( subc_list_double_count(&cmd.dl_contrast[i]) !=
166 ostensible_number_of_groups )
169 _("Number of contrast coefficients must equal the number of groups"));
174 for (j=0; j < ostensible_number_of_groups ; ++j )
175 sum += subc_list_double_at(&cmd.dl_contrast[i],j);
178 msg(SW,_("Coefficients for contrast %zu do not total zero"), i + 1);
181 if ( stat_tables & STAT_DESC )
184 if ( stat_tables & STAT_HOMO )
189 if (cmd.sbc_contrast )
191 show_contrast_coeffs(bad_contrast);
192 show_contrast_tests(bad_contrast);
199 for (i = 0 ; i < n_vars ; ++i )
201 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
203 hsh_destroy(group_hash);
206 hsh_destroy(global_group_hash);
213 /* Parser for the variables sub command */
215 oneway_custom_variables (struct lexer *lexer,
216 struct dataset *ds, struct cmd_oneway *cmd UNUSED,
219 struct dictionary *dict = dataset_dict (ds);
221 lex_match (lexer, '=');
223 if ((lex_token (lexer) != T_ID || dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
224 && lex_token (lexer) != T_ALL)
227 if (!parse_variables_const (lexer, dict, &vars, &n_vars,
229 | PV_NUMERIC | PV_NO_SCRATCH) )
237 if ( ! lex_match (lexer, T_BY))
240 indep_var = parse_variable (lexer, dict);
244 msg(SE,_("`%s' is not a variable name"),lex_tokid (lexer));
252 /* Show the ANOVA table */
254 show_anova_table(void)
258 size_t n_rows = n_vars * 3 + 1;
263 t = tab_create (n_cols,n_rows,0);
264 tab_headers (t, 2, 0, 1, 0);
265 tab_dim (t, tab_natural_dimensions);
272 n_cols - 1, n_rows - 1);
274 tab_hline (t, TAL_2, 0, n_cols - 1, 1 );
275 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
276 tab_vline (t, TAL_0, 1, 0, 0);
278 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
279 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
280 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
281 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
282 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
285 for ( i=0 ; i < n_vars ; ++i )
287 struct group_statistics *totals = &group_proc_get (vars[i])->ugs;
288 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
289 struct hsh_iterator g;
290 struct group_statistics *gs;
292 const char *s = var_to_string(vars[i]);
294 for (gs = hsh_first (group_hash,&g);
296 gs = hsh_next(group_hash,&g))
298 ssa += pow2 (gs->sum) / gs->n;
301 ssa -= pow2 (totals->sum) / totals->n;
303 tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s);
304 tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups"));
305 tab_text (t, 1, i * 3 + 2, TAB_LEFT | TAT_TITLE, _("Within Groups"));
306 tab_text (t, 1, i * 3 + 3, TAB_LEFT | TAT_TITLE, _("Total"));
309 tab_hline(t, TAL_1, 0, n_cols - 1 , i * 3 + 1);
312 struct group_proc *gp = group_proc_get (vars[i]);
313 const double sst = totals->ssq - pow2 (totals->sum) / totals->n ;
314 const double df1 = gp->n_groups - 1;
315 const double df2 = totals->n - gp->n_groups ;
316 const double msa = ssa / df1;
318 gp->mse = (sst - ssa) / df2;
321 /* Sums of Squares */
322 tab_float (t, 2, i * 3 + 1, 0, ssa, 10, 2);
323 tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2);
324 tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2);
327 /* Degrees of freedom */
328 tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0);
329 tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0);
330 tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
333 tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3);
334 tab_float (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, 8, 3);
337 const double F = msa/gp->mse ;
340 tab_float (t, 5, i * 3 + 1, 0, F, 8, 3);
342 /* The significance */
343 tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
349 tab_title (t, _("ANOVA"));
354 /* Show the descriptives table */
356 show_descriptives(void)
363 const double confidence=0.95;
364 const double q = (1.0 - confidence) / 2.0;
369 for ( v = 0 ; v < n_vars ; ++v )
370 n_rows += group_proc_get (vars[v])->n_groups + 1;
372 t = tab_create (n_cols,n_rows,0);
373 tab_headers (t, 2, 0, 2, 0);
374 tab_dim (t, tab_natural_dimensions);
377 /* Put a frame around the entire box, and vertical lines inside */
382 n_cols - 1, n_rows - 1);
384 /* Underline headers */
385 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
386 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
388 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
389 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
390 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
391 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
394 tab_vline(t, TAL_0, 7, 0, 0);
395 tab_hline(t, TAL_1, 6, 7, 1);
396 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
398 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
399 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
401 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
402 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
405 tab_title (t, _("Descriptives"));
409 for ( v=0 ; v < n_vars ; ++v )
414 struct group_proc *gp = group_proc_get (vars[v]);
416 struct group_statistics *gs;
417 struct group_statistics *totals = &gp->ugs;
419 const char *s = var_to_string(vars[v]);
421 struct group_statistics *const *gs_array =
422 (struct group_statistics *const *) hsh_sort(gp->group_hash);
425 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
427 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
429 for (count = 0 ; count < hsh_count(gp->group_hash) ; ++count)
432 ds_init_empty (&vstr);
433 gs = gs_array[count];
435 var_append_value_name (indep_var, &gs->id, &vstr);
437 tab_text (t, 1, row + count,
438 TAB_LEFT | TAT_TITLE,
443 /* Now fill in the numbers ... */
445 tab_float (t, 2, row + count, 0, gs->n, 8,0);
447 tab_float (t, 3, row + count, 0, gs->mean, 8, 2);
449 tab_float (t, 4, row + count, 0, gs->std_dev, 8, 2);
451 std_error = gs->std_dev/sqrt(gs->n) ;
452 tab_float (t, 5, row + count, 0,
455 /* Now the confidence interval */
457 T = gsl_cdf_tdist_Qinv(q, gs->n - 1);
459 tab_float(t, 6, row + count, 0,
460 gs->mean - T * std_error, 8, 2);
462 tab_float(t, 7, row + count, 0,
463 gs->mean + T * std_error, 8, 2);
467 tab_float(t, 8, row + count, 0, gs->minimum, 8, 2);
468 tab_float(t, 9, row + count, 0, gs->maximum, 8, 2);
472 tab_text (t, 1, row + count,
473 TAB_LEFT | TAT_TITLE ,_("Total"));
475 tab_float (t, 2, row + count, 0, totals->n, 8,0);
477 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
479 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
481 std_error = totals->std_dev/sqrt(totals->n) ;
483 tab_float (t, 5, row + count, 0, std_error, 8,2);
485 /* Now the confidence interval */
487 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
489 tab_float(t, 6, row + count, 0,
490 totals->mean - T * std_error, 8, 2);
492 tab_float(t, 7, row + count, 0,
493 totals->mean + T * std_error, 8, 2);
497 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
498 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
500 row += gp->n_groups + 1;
509 /* Show the homogeneity table */
511 show_homogeneity(void)
515 size_t n_rows = n_vars + 1;
520 t = tab_create (n_cols,n_rows,0);
521 tab_headers (t, 1, 0, 1, 0);
522 tab_dim (t, tab_natural_dimensions);
524 /* Put a frame around the entire box, and vertical lines inside */
529 n_cols - 1, n_rows - 1);
532 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
533 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
536 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
537 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
538 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
539 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
542 tab_title (t, _("Test of Homogeneity of Variances"));
544 for ( v=0 ; v < n_vars ; ++v )
547 const struct variable *var = vars[v];
548 const struct group_proc *gp = group_proc_get (vars[v]);
549 const char *s = var_to_string(var);
550 const struct group_statistics *totals = &gp->ugs;
552 const double df1 = gp->n_groups - 1;
553 const double df2 = totals->n - gp->n_groups ;
555 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
558 tab_float (t, 1, v + 1, TAB_RIGHT, F, 8,3);
559 tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0);
560 tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0);
562 /* Now the significance */
563 tab_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
570 /* Show the contrast coefficients table */
572 show_contrast_coeffs (short *bad_contrast)
574 int n_cols = 2 + ostensible_number_of_groups;
575 int n_rows = 2 + cmd.sbc_contrast;
576 union value *group_value;
578 void *const *group_values ;
582 t = tab_create (n_cols,n_rows,0);
583 tab_headers (t, 2, 0, 2, 0);
584 tab_dim (t, tab_natural_dimensions);
586 /* Put a frame around the entire box, and vertical lines inside */
591 n_cols - 1, n_rows - 1);
605 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
606 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
608 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
610 tab_title (t, _("Contrast Coefficients"));
612 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
615 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
616 var_to_string(indep_var));
618 group_values = hsh_sort(global_group_hash);
620 count < hsh_count(global_group_hash) ;
625 group_value = group_values[count];
627 ds_init_empty (&vstr);
629 var_append_value_name (indep_var, group_value, &vstr);
631 tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
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 = pow2 (gs->std_dev) / gs->n;
763 contrast_value += coef * gs->mean;
765 coef_msq += (coef * coef) / gs->n ;
767 sec_vneq += (coef * coef) * pow2 (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 *) var_get_width (indep_var) );
888 totals->maximum = - DBL_MAX;
889 totals->minimum = DBL_MAX;
894 free_value (void *value_, const void *aux UNUSED)
896 union value *value = value_;
901 run_oneway (struct cmd_oneway *cmd,
902 struct casereader *input,
903 const struct dataset *ds)
906 struct dictionary *dict = dataset_dict (ds);
907 enum mv_class exclude;
908 struct casereader *reader;
911 if (!casereader_peek (input, 0, &c))
913 casereader_destroy (input);
916 output_split_file_values (ds, &c);
919 taint = taint_clone (casereader_get_taint (input));
921 global_group_hash = hsh_create(4,
922 (hsh_compare_func *) compare_values,
923 (hsh_hash_func *) hash_value,
925 (void *) var_get_width (indep_var) );
929 exclude = cmd->incl != ONEWAY_INCLUDE ? MV_ANY : MV_SYSTEM;
930 input = casereader_create_filter_missing (input, &indep_var, 1,
931 exclude, NULL, NULL);
932 if (cmd->miss == ONEWAY_LISTWISE)
933 input = casereader_create_filter_missing (input, vars, n_vars,
934 exclude, NULL, NULL);
935 input = casereader_create_filter_weight (input, dict, NULL, NULL);
937 reader = casereader_clone (input);
938 for (; casereader_read (reader, &c); case_destroy (&c))
942 const double weight = dict_get_case_weight (dict, &c, NULL);
944 const union value *indep_val = case_data (&c, indep_var);
945 void **p = hsh_probe (global_group_hash, indep_val);
947 *p = value_dup (indep_val, var_get_width (indep_var));
949 for ( i = 0 ; i < n_vars ; ++i )
951 const struct variable *v = vars[i];
953 const union value *val = case_data (&c, v);
955 struct group_proc *gp = group_proc_get (vars[i]);
956 struct hsh_table *group_hash = gp->group_hash;
958 struct group_statistics *gs;
960 gs = hsh_find(group_hash, (void *) indep_val );
964 gs = xmalloc (sizeof *gs);
970 gs->minimum = DBL_MAX;
971 gs->maximum = -DBL_MAX;
973 hsh_insert ( group_hash, (void *) gs );
976 if (!var_is_value_missing (v, val, exclude))
978 struct group_statistics *totals = &gp->ugs;
981 totals->sum += weight * val->f;
982 totals->ssq += weight * pow2 (val->f);
984 if ( val->f * weight < totals->minimum )
985 totals->minimum = val->f * weight;
987 if ( val->f * weight > totals->maximum )
988 totals->maximum = val->f * weight;
991 gs->sum += weight * val->f;
992 gs->ssq += weight * pow2 (val->f);
994 if ( val->f * weight < gs->minimum )
995 gs->minimum = val->f * weight;
997 if ( val->f * weight > gs->maximum )
998 gs->maximum = val->f * weight;
1001 gp->n_groups = hsh_count ( group_hash );
1005 casereader_destroy (reader);
1010 if ( stat_tables & STAT_HOMO )
1011 levene (dict, casereader_clone (input), indep_var, n_vars, vars, exclude);
1013 casereader_destroy (input);
1015 ostensible_number_of_groups = hsh_count (global_group_hash);
1017 if (!taint_has_tainted_successor (taint))
1019 taint_destroy (taint);
1023 /* Post calculations for the ONEWAY command */
1025 postcalc ( struct cmd_oneway *cmd UNUSED )
1030 for(i = 0; i < n_vars ; ++i)
1032 struct group_proc *gp = group_proc_get (vars[i]);
1033 struct hsh_table *group_hash = gp->group_hash;
1034 struct group_statistics *totals = &gp->ugs;
1036 struct hsh_iterator g;
1037 struct group_statistics *gs;
1039 for (gs = hsh_first (group_hash,&g);
1041 gs = hsh_next(group_hash,&g))
1043 gs->mean = gs->sum / gs->n;
1044 gs->s_std_dev= sqrt(
1045 gs->ssq / gs->n - pow2 (gs->mean)
1049 gs->n / (gs->n - 1) *
1050 ( gs->ssq / gs->n - pow2 (gs->mean))
1053 gs->se_mean = gs->std_dev / sqrt (gs->n);
1054 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 - pow2 (totals->mean))
1063 totals->se_mean = totals->std_dev / sqrt (totals->n);