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/alloc.h>
35 #include <libpspp/compiler.h>
36 #include <libpspp/hash.h>
37 #include <libpspp/magic.h>
38 #include <libpspp/message.h>
39 #include <libpspp/misc.h>
40 #include <libpspp/str.h>
41 #include <libpspp/taint.h>
42 #include <math/group-proc.h>
43 #include <math/group.h>
44 #include <math/levene.h>
45 #include <output/manager.h>
46 #include <output/table.h>
47 #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 %d do not total zero"),
182 if ( stat_tables & STAT_DESC )
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_float (t, 2, i * 3 + 1, 0, ssa, 10, 2);
324 tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2);
325 tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2);
328 /* Degrees of freedom */
329 tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0);
330 tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0);
331 tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
334 tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3);
335 tab_float (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, 8, 3);
339 const double F = msa/gp->mse ;
342 tab_float (t, 5, i * 3 + 1, 0, F, 8, 3);
344 /* The significance */
345 tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
353 tab_title (t, _("ANOVA"));
358 /* Show the descriptives table */
360 show_descriptives(void)
367 const double confidence=0.95;
368 const double q = (1.0 - confidence) / 2.0;
373 for ( v = 0 ; v < n_vars ; ++v )
374 n_rows += group_proc_get (vars[v])->n_groups + 1;
376 t = tab_create (n_cols,n_rows,0);
377 tab_headers (t, 2, 0, 2, 0);
378 tab_dim (t, tab_natural_dimensions);
381 /* Put a frame around the entire box, and vertical lines inside */
386 n_cols - 1, n_rows - 1);
388 /* Underline headers */
389 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
390 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
392 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
393 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
394 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
395 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
398 tab_vline(t, TAL_0, 7, 0, 0);
399 tab_hline(t, TAL_1, 6, 7, 1);
400 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
402 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
403 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
405 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
406 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
409 tab_title (t, _("Descriptives"));
413 for ( v=0 ; v < n_vars ; ++v )
418 struct group_proc *gp = group_proc_get (vars[v]);
420 struct group_statistics *gs;
421 struct group_statistics *totals = &gp->ugs;
423 const char *s = var_to_string(vars[v]);
425 struct group_statistics *const *gs_array =
426 (struct group_statistics *const *) hsh_sort(gp->group_hash);
429 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
431 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
433 for (count = 0 ; count < hsh_count(gp->group_hash) ; ++count)
435 gs = gs_array[count];
437 tab_text (t, 1, row + count,
438 TAB_LEFT | TAT_TITLE, var_get_value_name(indep_var,
441 /* Now fill in the numbers ... */
443 tab_float (t, 2, row + count, 0, gs->n, 8,0);
445 tab_float (t, 3, row + count, 0, gs->mean,8,2);
447 tab_float (t, 4, row + count, 0, gs->std_dev,8,2);
449 std_error = gs->std_dev/sqrt(gs->n) ;
450 tab_float (t, 5, row + count, 0,
453 /* Now the confidence interval */
455 T = gsl_cdf_tdist_Qinv(q,gs->n - 1);
457 tab_float(t, 6, row + count, 0,
458 gs->mean - T * std_error, 8, 2);
460 tab_float(t, 7, row + count, 0,
461 gs->mean + T * std_error, 8, 2);
465 tab_float(t, 8, row + count, 0, gs->minimum, 8, 2);
466 tab_float(t, 9, row + count, 0, gs->maximum, 8, 2);
470 tab_text (t, 1, row + count,
471 TAB_LEFT | TAT_TITLE ,_("Total"));
473 tab_float (t, 2, row + count, 0, totals->n, 8,0);
475 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
477 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
479 std_error = totals->std_dev/sqrt(totals->n) ;
481 tab_float (t, 5, row + count, 0, std_error, 8,2);
483 /* Now the confidence interval */
485 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
487 tab_float(t, 6, row + count, 0,
488 totals->mean - T * std_error, 8, 2);
490 tab_float(t, 7, row + count, 0,
491 totals->mean + T * std_error, 8, 2);
495 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
496 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
498 row += gp->n_groups + 1;
507 /* Show the homogeneity table */
509 show_homogeneity(void)
513 size_t n_rows = n_vars + 1;
518 t = tab_create (n_cols,n_rows,0);
519 tab_headers (t, 1, 0, 1, 0);
520 tab_dim (t, tab_natural_dimensions);
522 /* Put a frame around the entire box, and vertical lines inside */
527 n_cols - 1, n_rows - 1);
530 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
531 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
534 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
535 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
536 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
537 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
540 tab_title (t, _("Test of Homogeneity of Variances"));
542 for ( v=0 ; v < n_vars ; ++v )
545 const struct variable *var = vars[v];
546 const struct group_proc *gp = group_proc_get (vars[v]);
547 const char *s = var_to_string(var);
548 const struct group_statistics *totals = &gp->ugs;
550 const double df1 = gp->n_groups - 1;
551 const double df2 = totals->n - gp->n_groups ;
553 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
556 tab_float (t, 1, v + 1, TAB_RIGHT, F, 8,3);
557 tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0);
558 tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0);
560 /* Now the significance */
561 tab_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
568 /* Show the contrast coefficients table */
570 show_contrast_coeffs (short *bad_contrast)
572 int n_cols = 2 + ostensible_number_of_groups;
573 int n_rows = 2 + cmd.sbc_contrast;
574 union value *group_value;
576 void *const *group_values ;
580 t = tab_create (n_cols,n_rows,0);
581 tab_headers (t, 2, 0, 2, 0);
582 tab_dim (t, tab_natural_dimensions);
584 /* Put a frame around the entire box, and vertical lines inside */
589 n_cols - 1, n_rows - 1);
603 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
604 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
606 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
608 tab_title (t, _("Contrast Coefficients"));
610 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
613 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
614 var_to_string(indep_var));
616 group_values = hsh_sort(global_group_hash);
618 count < hsh_count(global_group_hash) ;
622 group_value = group_values[count];
624 tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
625 var_get_value_name (indep_var, group_value));
627 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
629 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
631 if ( bad_contrast[i] )
632 tab_text(t, count + 2, i + 2, TAB_RIGHT, "?" );
634 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
635 subc_list_double_at(&cmd.dl_contrast[i], count)
644 /* Show the results of the contrast tests */
646 show_contrast_tests(short *bad_contrast)
650 size_t n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
654 t = tab_create (n_cols,n_rows,0);
655 tab_headers (t, 3, 0, 1, 0);
656 tab_dim (t, tab_natural_dimensions);
658 /* Put a frame around the entire box, and vertical lines inside */
663 n_cols - 1, n_rows - 1);
671 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
672 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
675 tab_title (t, _("Contrast Tests"));
677 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
678 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
679 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
680 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
681 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
682 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
684 for ( v = 0 ; v < n_vars ; ++v )
687 int lines_per_variable = 2 * cmd.sbc_contrast;
690 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
691 var_to_string(vars[v]));
693 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
696 double contrast_value = 0.0;
697 double coef_msq = 0.0;
698 struct group_proc *grp_data = group_proc_get (vars[v]);
699 struct hsh_table *group_hash = grp_data->group_hash;
701 void *const *group_stat_array;
704 double std_error_contrast ;
709 /* Note: The calculation of the degrees of freedom in the
710 "variances not equal" case is painfull!!
711 The following formula may help to understand it:
712 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
715 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
720 double df_denominator = 0.0;
721 double df_numerator = 0.0;
724 tab_text (t, 1, (v * lines_per_variable) + i + 1,
725 TAB_LEFT | TAT_TITLE,
726 _("Assume equal variances"));
728 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
729 TAB_LEFT | TAT_TITLE,
730 _("Does not assume equal"));
733 tab_text (t, 2, (v * lines_per_variable) + i + 1,
734 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
737 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
738 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
741 if ( bad_contrast[i])
744 group_stat_array = hsh_sort(group_hash);
746 for (ci = 0 ; ci < hsh_count(group_hash) ; ++ci)
748 const double coef = subc_list_double_at(&cmd.dl_contrast[i], ci);
749 struct group_statistics *gs = group_stat_array[ci];
751 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
753 contrast_value += coef * gs->mean;
755 coef_msq += (coef * coef) / gs->n ;
757 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
759 df_numerator += (coef * coef) * winv;
760 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
762 sec_vneq = sqrt(sec_vneq);
764 df_numerator = pow2(df_numerator);
766 tab_float (t, 3, (v * lines_per_variable) + i + 1,
767 TAB_RIGHT, contrast_value, 8,2);
769 tab_float (t, 3, (v * lines_per_variable) + i + 1 +
771 TAB_RIGHT, contrast_value, 8,2);
773 std_error_contrast = sqrt(grp_data->mse * coef_msq);
776 tab_float (t, 4, (v * lines_per_variable) + i + 1,
777 TAB_RIGHT, std_error_contrast,
780 T = fabs(contrast_value / std_error_contrast) ;
784 tab_float (t, 5, (v * lines_per_variable) + i + 1,
788 df = grp_data->ugs.n - grp_data->n_groups;
790 /* Degrees of Freedom */
791 tab_float (t, 6, (v * lines_per_variable) + i + 1,
796 /* Significance TWO TAILED !!*/
797 tab_float (t, 7, (v * lines_per_variable) + i + 1,
798 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
802 /* Now for the Variances NOT Equal case */
806 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
811 T = contrast_value / sec_vneq;
813 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
818 df = df_numerator / df_denominator;
821 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
825 /* The Significance */
827 tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
828 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
835 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
843 /* ONEWAY ANOVA Calculations */
845 static void postcalc ( struct cmd_oneway *cmd UNUSED );
847 static void precalc ( struct cmd_oneway *cmd UNUSED );
851 /* Pre calculations */
853 precalc ( struct cmd_oneway *cmd UNUSED )
857 for(i=0; i< n_vars ; ++i)
859 struct group_proc *gp = group_proc_get (vars[i]);
860 struct group_statistics *totals = &gp->ugs;
862 /* Create a hash for each of the dependent variables.
863 The hash contains a group_statistics structure,
864 and is keyed by value of the independent variable */
868 (hsh_compare_func *) compare_group,
869 (hsh_hash_func *) hash_group,
870 (hsh_free_func *) free_group,
871 (void *) var_get_width (indep_var) );
878 totals->maximum = - DBL_MAX;
879 totals->minimum = DBL_MAX;
884 free_value (void *value_, const void *aux UNUSED)
886 union value *value = value_;
891 run_oneway (struct cmd_oneway *cmd,
892 struct casereader *input,
893 const struct dataset *ds)
896 struct dictionary *dict = dataset_dict (ds);
897 enum mv_class exclude;
898 struct casereader *reader;
901 if (!casereader_peek (input, 0, &c))
903 casereader_destroy (input);
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);