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"
46 #include <data/format.h>
51 #define _(msgid) gettext (msgid)
58 missing=miss:!analysis/listwise,
59 incl:include/!exclude;
60 +contrast= double list;
61 +statistics[st_]=descriptives,homogeneity.
66 static struct cmd_oneway cmd;
68 /* The independent variable */
69 static const struct variable *indep_var;
71 /* Number of dependent variables */
74 /* The dependent variables */
75 static const struct variable **vars;
78 /* A hash table containing all the distinct values of the independent
80 static struct hsh_table *global_group_hash ;
82 /* The number of distinct values of the independent variable, when all
83 missing values are disregarded */
84 static int ostensible_number_of_groups = -1;
87 static void run_oneway (struct cmd_oneway *, struct casereader *,
88 const struct dataset *);
91 /* Routines to show the output tables */
92 static void show_anova_table(void);
93 static void show_descriptives (const struct dictionary *dict);
94 static void show_homogeneity(void);
96 static void show_contrast_coeffs(short *);
97 static void show_contrast_tests(short *);
100 enum stat_table_t {STAT_DESC = 1, STAT_HOMO = 2};
102 static enum stat_table_t stat_tables ;
104 static void output_oneway (const struct dictionary *dict);
108 cmd_oneway (struct lexer *lexer, struct dataset *ds)
110 struct casegrouper *grouper;
111 struct casereader *group;
115 if ( !parse_oneway (lexer, ds, &cmd, NULL) )
118 /* What statistics were requested */
119 if ( cmd.sbc_statistics )
122 for (i = 0 ; i < ONEWAY_ST_count ; ++i )
124 if ( ! cmd.a_statistics[i] ) continue;
127 case ONEWAY_ST_DESCRIPTIVES:
128 stat_tables |= STAT_DESC;
130 case ONEWAY_ST_HOMOGENEITY:
131 stat_tables |= STAT_HOMO;
137 /* Data pass. FIXME: error handling. */
138 grouper = casegrouper_create_splits (proc_open (ds), dataset_dict (ds));
139 while (casegrouper_get_next_group (grouper, &group))
140 run_oneway (&cmd, group, ds);
141 ok = casegrouper_destroy (grouper);
142 ok = proc_commit (ds) && ok;
147 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
152 output_oneway (const struct dictionary *dict)
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 %zu do not total zero"), i + 1);
182 if ( stat_tables & STAT_DESC )
183 show_descriptives (dict);
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_const (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_double (t, 2, i * 3 + 1, 0, ssa, NULL);
324 tab_double (t, 2, i * 3 + 3, 0, sst, NULL);
325 tab_double (t, 2, i * 3 + 2, 0, sst - ssa, NULL);
328 /* Degrees of freedom */
329 tab_fixed (t, 3, i * 3 + 1, 0, df1, 4, 0);
330 tab_fixed (t, 3, i * 3 + 2, 0, df2, 4, 0);
331 tab_fixed (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
334 tab_double (t, 4, i * 3 + 1, TAB_RIGHT, msa, NULL);
335 tab_double (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, NULL);
339 const double F = msa / gp->mse ;
342 tab_double (t, 5, i * 3 + 1, 0, F, NULL);
344 /* The significance */
345 tab_double (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q (F, df1,df2), NULL);
353 tab_title (t, _("ANOVA"));
358 /* Show the descriptives table */
360 show_descriptives (const struct dictionary *dict)
367 const double confidence = 0.95;
368 const double q = (1.0 - confidence) / 2.0;
370 const struct variable *wv = dict_get_weight (dict);
371 const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0;
375 for ( v = 0 ; v < n_vars ; ++v )
376 n_rows += group_proc_get (vars[v])->n_groups + 1;
378 t = tab_create (n_cols,n_rows,0);
379 tab_headers (t, 2, 0, 2, 0);
380 tab_dim (t, tab_natural_dimensions);
383 /* Put a frame around the entire box, and vertical lines inside */
388 n_cols - 1, n_rows - 1);
390 /* Underline headers */
391 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
392 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
394 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
395 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
396 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
397 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
400 tab_vline(t, TAL_0, 7, 0, 0);
401 tab_hline(t, TAL_1, 6, 7, 1);
402 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
404 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
405 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
407 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
408 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
411 tab_title (t, _("Descriptives"));
415 for ( v=0 ; v < n_vars ; ++v )
420 struct group_proc *gp = group_proc_get (vars[v]);
422 struct group_statistics *gs;
423 struct group_statistics *totals = &gp->ugs;
425 const char *s = var_to_string (vars[v]);
426 const struct fmt_spec *fmt = var_get_print_format (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)
439 ds_init_empty (&vstr);
440 gs = gs_array[count];
442 var_append_value_name (indep_var, &gs->id, &vstr);
444 tab_text (t, 1, row + count,
445 TAB_LEFT | TAT_TITLE,
450 /* Now fill in the numbers ... */
452 tab_fixed (t, 2, row + count, 0, gs->n, 8, 0);
454 tab_double (t, 3, row + count, 0, gs->mean, NULL);
456 tab_double (t, 4, row + count, 0, gs->std_dev, NULL);
458 std_error = gs->std_dev / sqrt (gs->n) ;
459 tab_double (t, 5, row + count, 0,
462 /* Now the confidence interval */
464 T = gsl_cdf_tdist_Qinv (q, gs->n - 1);
466 tab_double (t, 6, row + count, 0,
467 gs->mean - T * std_error, NULL);
469 tab_double (t, 7, row + count, 0,
470 gs->mean + T * std_error, NULL);
474 tab_double (t, 8, row + count, 0, gs->minimum, fmt);
475 tab_double (t, 9, row + count, 0, gs->maximum, fmt);
478 tab_text (t, 1, row + count,
479 TAB_LEFT | TAT_TITLE ,_("Total"));
481 tab_double (t, 2, row + count, 0, totals->n, wfmt);
483 tab_double (t, 3, row + count, 0, totals->mean, NULL);
485 tab_double (t, 4, row + count, 0, totals->std_dev, NULL);
487 std_error = totals->std_dev / sqrt (totals->n) ;
489 tab_double (t, 5, row + count, 0, std_error, NULL);
491 /* Now the confidence interval */
493 T = gsl_cdf_tdist_Qinv (q, totals->n - 1);
495 tab_double (t, 6, row + count, 0,
496 totals->mean - T * std_error, NULL);
498 tab_double (t, 7, row + count, 0,
499 totals->mean + T * std_error, NULL);
503 tab_double (t, 8, row + count, 0, totals->minimum, fmt);
504 tab_double (t, 9, row + count, 0, totals->maximum, fmt);
506 row += gp->n_groups + 1;
513 /* Show the homogeneity table */
515 show_homogeneity(void)
519 size_t n_rows = n_vars + 1;
524 t = tab_create (n_cols,n_rows,0);
525 tab_headers (t, 1, 0, 1, 0);
526 tab_dim (t, tab_natural_dimensions);
528 /* Put a frame around the entire box, and vertical lines inside */
533 n_cols - 1, n_rows - 1);
536 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
537 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
540 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
541 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
542 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
543 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
546 tab_title (t, _("Test of Homogeneity of Variances"));
548 for ( v=0 ; v < n_vars ; ++v )
551 const struct variable *var = vars[v];
552 const struct group_proc *gp = group_proc_get (vars[v]);
553 const char *s = var_to_string(var);
554 const struct group_statistics *totals = &gp->ugs;
556 const double df1 = gp->n_groups - 1;
557 const double df2 = totals->n - gp->n_groups ;
559 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
562 tab_double (t, 1, v + 1, TAB_RIGHT, F, NULL);
563 tab_fixed (t, 2, v + 1, TAB_RIGHT, df1, 8, 0);
564 tab_fixed (t, 3, v + 1, TAB_RIGHT, df2, 8, 0);
566 /* Now the significance */
567 tab_double (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q (F, df1, df2), NULL);
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, _("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) ;
629 group_value = group_values[count];
631 ds_init_empty (&vstr);
633 var_append_value_name (indep_var, group_value, &vstr);
635 tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
641 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
643 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
645 if ( bad_contrast[i] )
646 tab_text(t, count + 2, i + 2, TAB_RIGHT, "?" );
648 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
649 subc_list_double_at(&cmd.dl_contrast[i], count)
658 /* Show the results of the contrast tests */
660 show_contrast_tests(short *bad_contrast)
664 size_t n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
668 t = tab_create (n_cols,n_rows,0);
669 tab_headers (t, 3, 0, 1, 0);
670 tab_dim (t, tab_natural_dimensions);
672 /* Put a frame around the entire box, and vertical lines inside */
677 n_cols - 1, n_rows - 1);
685 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
686 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
689 tab_title (t, _("Contrast Tests"));
691 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
692 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
693 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
694 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
695 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
696 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
698 for ( v = 0 ; v < n_vars ; ++v )
701 int lines_per_variable = 2 * cmd.sbc_contrast;
704 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
705 var_to_string(vars[v]));
707 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
710 double contrast_value = 0.0;
711 double coef_msq = 0.0;
712 struct group_proc *grp_data = group_proc_get (vars[v]);
713 struct hsh_table *group_hash = grp_data->group_hash;
715 void *const *group_stat_array;
718 double std_error_contrast ;
723 /* Note: The calculation of the degrees of freedom in the
724 "variances not equal" case is painfull!!
725 The following formula may help to understand it:
726 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
729 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
734 double df_denominator = 0.0;
735 double df_numerator = 0.0;
738 tab_text (t, 1, (v * lines_per_variable) + i + 1,
739 TAB_LEFT | TAT_TITLE,
740 _("Assume equal variances"));
742 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
743 TAB_LEFT | TAT_TITLE,
744 _("Does not assume equal"));
747 tab_text (t, 2, (v * lines_per_variable) + i + 1,
748 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
751 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
752 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
755 if ( bad_contrast[i])
758 group_stat_array = hsh_sort(group_hash);
760 for (ci = 0 ; ci < hsh_count(group_hash) ; ++ci)
762 const double coef = subc_list_double_at(&cmd.dl_contrast[i], ci);
763 struct group_statistics *gs = group_stat_array[ci];
765 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
767 contrast_value += coef * gs->mean;
769 coef_msq += (coef * coef) / gs->n ;
771 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
773 df_numerator += (coef * coef) * winv;
774 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
776 sec_vneq = sqrt(sec_vneq);
778 df_numerator = pow2 (df_numerator);
780 tab_double (t, 3, (v * lines_per_variable) + i + 1,
781 TAB_RIGHT, contrast_value, NULL);
783 tab_double (t, 3, (v * lines_per_variable) + i + 1 +
785 TAB_RIGHT, contrast_value, NULL);
787 std_error_contrast = sqrt (grp_data->mse * coef_msq);
790 tab_double (t, 4, (v * lines_per_variable) + i + 1,
791 TAB_RIGHT, std_error_contrast,
794 T = fabs(contrast_value / std_error_contrast) ;
798 tab_double (t, 5, (v * lines_per_variable) + i + 1,
802 df = grp_data->ugs.n - grp_data->n_groups;
804 /* Degrees of Freedom */
805 tab_fixed (t, 6, (v * lines_per_variable) + i + 1,
810 /* Significance TWO TAILED !!*/
811 tab_double (t, 7, (v * lines_per_variable) + i + 1,
812 TAB_RIGHT, 2 * gsl_cdf_tdist_Q (T, df),
816 /* Now for the Variances NOT Equal case */
820 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
825 T = contrast_value / sec_vneq;
827 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
832 df = df_numerator / df_denominator;
835 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
839 /* The Significance */
841 tab_double (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
842 TAB_RIGHT, 2 * gsl_cdf_tdist_Q (T,df),
849 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
856 /* ONEWAY ANOVA Calculations */
858 static void postcalc ( struct cmd_oneway *cmd UNUSED );
860 static void precalc ( struct cmd_oneway *cmd UNUSED );
864 /* Pre calculations */
866 precalc ( struct cmd_oneway *cmd UNUSED )
870 for(i=0; i< n_vars ; ++i)
872 struct group_proc *gp = group_proc_get (vars[i]);
873 struct group_statistics *totals = &gp->ugs;
875 /* Create a hash for each of the dependent variables.
876 The hash contains a group_statistics structure,
877 and is keyed by value of the independent variable */
881 (hsh_compare_func *) compare_group,
882 (hsh_hash_func *) hash_group,
883 (hsh_free_func *) free_group,
884 (void *) var_get_width (indep_var) );
891 totals->maximum = - DBL_MAX;
892 totals->minimum = DBL_MAX;
897 free_value (void *value_, const void *aux UNUSED)
899 union value *value = value_;
904 run_oneway (struct cmd_oneway *cmd,
905 struct casereader *input,
906 const struct dataset *ds)
909 struct dictionary *dict = dataset_dict (ds);
910 enum mv_class exclude;
911 struct casereader *reader;
914 if (!casereader_peek (input, 0, &c))
916 casereader_destroy (input);
919 output_split_file_values (ds, &c);
922 taint = taint_clone (casereader_get_taint (input));
924 global_group_hash = hsh_create(4,
925 (hsh_compare_func *) compare_values,
926 (hsh_hash_func *) hash_value,
928 (void *) var_get_width (indep_var) );
932 exclude = cmd->incl != ONEWAY_INCLUDE ? MV_ANY : MV_SYSTEM;
933 input = casereader_create_filter_missing (input, &indep_var, 1,
935 if (cmd->miss == ONEWAY_LISTWISE)
936 input = casereader_create_filter_missing (input, vars, n_vars,
938 input = casereader_create_filter_weight (input, dict, NULL, NULL);
940 reader = casereader_clone (input);
941 for (; casereader_read (reader, &c); case_destroy (&c))
945 const double weight = dict_get_case_weight (dict, &c, NULL);
947 const union value *indep_val = case_data (&c, indep_var);
948 void **p = hsh_probe (global_group_hash, indep_val);
950 *p = value_dup (indep_val, var_get_width (indep_var));
952 for ( i = 0 ; i < n_vars ; ++i )
954 const struct variable *v = vars[i];
956 const union value *val = case_data (&c, v);
958 struct group_proc *gp = group_proc_get (vars[i]);
959 struct hsh_table *group_hash = gp->group_hash;
961 struct group_statistics *gs;
963 gs = hsh_find(group_hash, (void *) indep_val );
967 gs = xmalloc (sizeof *gs);
973 gs->minimum = DBL_MAX;
974 gs->maximum = -DBL_MAX;
976 hsh_insert ( group_hash, (void *) gs );
979 if (!var_is_value_missing (v, val, exclude))
981 struct group_statistics *totals = &gp->ugs;
984 totals->sum+=weight * val->f;
985 totals->ssq+=weight * val->f * val->f;
987 if ( val->f * weight < totals->minimum )
988 totals->minimum = val->f * weight;
990 if ( val->f * weight > totals->maximum )
991 totals->maximum = val->f * weight;
994 gs->sum+=weight * val->f;
995 gs->ssq+=weight * val->f * val->f;
997 if ( val->f * weight < gs->minimum )
998 gs->minimum = val->f * weight;
1000 if ( val->f * weight > gs->maximum )
1001 gs->maximum = val->f * weight;
1004 gp->n_groups = hsh_count ( group_hash );
1008 casereader_destroy (reader);
1013 if ( stat_tables & STAT_HOMO )
1014 levene (dict, casereader_clone (input), indep_var, n_vars, vars, exclude);
1016 casereader_destroy (input);
1018 ostensible_number_of_groups = hsh_count (global_group_hash);
1020 if (!taint_has_tainted_successor (taint))
1021 output_oneway (dict);
1023 taint_destroy (taint);
1027 /* Post calculations for the ONEWAY command */
1029 postcalc ( struct cmd_oneway *cmd UNUSED )
1034 for(i = 0; i < n_vars ; ++i)
1036 struct group_proc *gp = group_proc_get (vars[i]);
1037 struct hsh_table *group_hash = gp->group_hash;
1038 struct group_statistics *totals = &gp->ugs;
1040 struct hsh_iterator g;
1041 struct group_statistics *gs;
1043 for (gs = hsh_first (group_hash,&g);
1045 gs = hsh_next(group_hash,&g))
1047 gs->mean=gs->sum / gs->n;
1048 gs->s_std_dev= sqrt(
1049 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1054 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1057 gs->se_mean = gs->std_dev / sqrt(gs->n);
1058 gs->mean_diff= gs->sum_diff / gs->n;
1064 totals->mean = totals->sum / totals->n;
1065 totals->std_dev= sqrt(
1066 totals->n/(totals->n-1) *
1067 ( (totals->ssq / totals->n ) - totals->mean * totals->mean )
1070 totals->se_mean = totals->std_dev / sqrt(totals->n);