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);
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);
124 if ( !parse_oneway(&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 (current_dataset, 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 cmd_oneway *cmd UNUSED, void *aux UNUSED)
231 if ((token != T_ID || dict_lookup_var (dataset_dict (current_dataset), tokid) == NULL)
236 if (!parse_variables (dataset_dict (current_dataset), &vars, &n_vars,
238 | PV_NUMERIC | PV_NO_SCRATCH) )
246 if ( ! lex_match(T_BY))
250 indep_var = parse_variable();
254 msg(SE,_("`%s' is not a variable name"),tokid);
263 /* Show the ANOVA table */
265 show_anova_table(void)
269 size_t n_rows = n_vars * 3 + 1;
274 t = tab_create (n_cols,n_rows,0);
275 tab_headers (t, 2, 0, 1, 0);
276 tab_dim (t, tab_natural_dimensions);
283 n_cols - 1, n_rows - 1);
285 tab_hline (t, TAL_2, 0, n_cols - 1, 1 );
286 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
287 tab_vline (t, TAL_0, 1, 0, 0);
289 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
290 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
291 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
292 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
293 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
296 for ( i=0 ; i < n_vars ; ++i )
298 struct group_statistics *totals = &group_proc_get (vars[i])->ugs;
299 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
300 struct hsh_iterator g;
301 struct group_statistics *gs;
303 const char *s = var_to_string(vars[i]);
305 for (gs = hsh_first (group_hash,&g);
307 gs = hsh_next(group_hash,&g))
309 ssa += (gs->sum * gs->sum)/gs->n;
312 ssa -= ( totals->sum * totals->sum ) / totals->n ;
314 tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s);
315 tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups"));
316 tab_text (t, 1, i * 3 + 2, TAB_LEFT | TAT_TITLE, _("Within Groups"));
317 tab_text (t, 1, i * 3 + 3, TAB_LEFT | TAT_TITLE, _("Total"));
320 tab_hline(t, TAL_1, 0, n_cols - 1 , i * 3 + 1);
323 struct group_proc *gp = group_proc_get (vars[i]);
324 const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ;
325 const double df1 = gp->n_groups - 1;
326 const double df2 = totals->n - gp->n_groups ;
327 const double msa = ssa / df1;
329 gp->mse = (sst - ssa) / df2;
332 /* Sums of Squares */
333 tab_float (t, 2, i * 3 + 1, 0, ssa, 10, 2);
334 tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2);
335 tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2);
338 /* Degrees of freedom */
339 tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0);
340 tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0);
341 tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
344 tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3);
345 tab_float (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, 8, 3);
349 const double F = msa/gp->mse ;
352 tab_float (t, 5, i * 3 + 1, 0, F, 8, 3);
354 /* The significance */
355 tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
363 tab_title (t, _("ANOVA"));
369 /* Show the descriptives table */
371 show_descriptives(void)
378 const double confidence=0.95;
379 const double q = (1.0 - confidence) / 2.0;
384 for ( v = 0 ; v < n_vars ; ++v )
385 n_rows += group_proc_get (vars[v])->n_groups + 1;
387 t = tab_create (n_cols,n_rows,0);
388 tab_headers (t, 2, 0, 2, 0);
389 tab_dim (t, tab_natural_dimensions);
392 /* Put a frame around the entire box, and vertical lines inside */
397 n_cols - 1, n_rows - 1);
399 /* Underline headers */
400 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
401 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
403 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
404 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
405 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
406 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
409 tab_vline(t, TAL_0, 7, 0, 0);
410 tab_hline(t, TAL_1, 6, 7, 1);
411 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
413 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
414 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
416 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
417 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
420 tab_title (t, _("Descriptives"));
424 for ( v=0 ; v < n_vars ; ++v )
429 struct group_proc *gp = group_proc_get (vars[v]);
431 struct group_statistics *gs;
432 struct group_statistics *totals = &gp->ugs;
434 const char *s = var_to_string(vars[v]);
436 struct group_statistics *const *gs_array =
437 (struct group_statistics *const *) hsh_sort(gp->group_hash);
440 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
442 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
444 for (count = 0 ; count < hsh_count(gp->group_hash) ; ++count)
446 gs = gs_array[count];
448 tab_text (t, 1, row + count,
449 TAB_LEFT | TAT_TITLE ,value_to_string(&gs->id,indep_var));
451 /* Now fill in the numbers ... */
453 tab_float (t, 2, row + count, 0, gs->n, 8,0);
455 tab_float (t, 3, row + count, 0, gs->mean,8,2);
457 tab_float (t, 4, row + count, 0, gs->std_dev,8,2);
459 std_error = gs->std_dev/sqrt(gs->n) ;
460 tab_float (t, 5, row + count, 0,
463 /* Now the confidence interval */
465 T = gsl_cdf_tdist_Qinv(q,gs->n - 1);
467 tab_float(t, 6, row + count, 0,
468 gs->mean - T * std_error, 8, 2);
470 tab_float(t, 7, row + count, 0,
471 gs->mean + T * std_error, 8, 2);
475 tab_float(t, 8, row + count, 0, gs->minimum, 8, 2);
476 tab_float(t, 9, row + count, 0, gs->maximum, 8, 2);
480 tab_text (t, 1, row + count,
481 TAB_LEFT | TAT_TITLE ,_("Total"));
483 tab_float (t, 2, row + count, 0, totals->n, 8,0);
485 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
487 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
489 std_error = totals->std_dev/sqrt(totals->n) ;
491 tab_float (t, 5, row + count, 0, std_error, 8,2);
493 /* Now the confidence interval */
495 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
497 tab_float(t, 6, row + count, 0,
498 totals->mean - T * std_error, 8, 2);
500 tab_float(t, 7, row + count, 0,
501 totals->mean + T * std_error, 8, 2);
505 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
506 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
508 row += gp->n_groups + 1;
517 /* Show the homogeneity table */
519 show_homogeneity(void)
523 size_t n_rows = n_vars + 1;
528 t = tab_create (n_cols,n_rows,0);
529 tab_headers (t, 1, 0, 1, 0);
530 tab_dim (t, tab_natural_dimensions);
532 /* Put a frame around the entire box, and vertical lines inside */
537 n_cols - 1, n_rows - 1);
540 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
541 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
544 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
545 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
546 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
547 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
550 tab_title (t, _("Test of Homogeneity of Variances"));
552 for ( v=0 ; v < n_vars ; ++v )
555 const struct variable *var = vars[v];
556 const struct group_proc *gp = group_proc_get (vars[v]);
557 const char *s = var_to_string(var);
558 const struct group_statistics *totals = &gp->ugs;
560 const double df1 = gp->n_groups - 1;
561 const double df2 = totals->n - gp->n_groups ;
563 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
566 tab_float (t, 1, v + 1, TAB_RIGHT, F, 8,3);
567 tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0);
568 tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0);
570 /* Now the significance */
571 tab_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
580 /* Show the contrast coefficients table */
582 show_contrast_coeffs(short *bad_contrast)
584 int n_cols = 2 + ostensible_number_of_groups;
585 int n_rows = 2 + cmd.sbc_contrast;
586 union value *group_value;
588 void *const *group_values ;
592 t = tab_create (n_cols,n_rows,0);
593 tab_headers (t, 2, 0, 2, 0);
594 tab_dim (t, tab_natural_dimensions);
596 /* Put a frame around the entire box, and vertical lines inside */
601 n_cols - 1, n_rows - 1);
615 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
616 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
618 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
620 tab_title (t, _("Contrast Coefficients"));
622 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
625 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
626 var_to_string(indep_var));
628 group_values = hsh_sort(global_group_hash);
630 count < hsh_count(global_group_hash) ;
634 group_value = group_values[count];
636 tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
637 value_to_string(group_value, indep_var));
639 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
641 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
643 if ( bad_contrast[i] )
644 tab_text(t, count + 2, i + 2, TAB_RIGHT, "?" );
646 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
647 subc_list_double_at(&cmd.dl_contrast[i], count)
656 /* Show the results of the contrast tests */
658 show_contrast_tests(short *bad_contrast)
662 size_t n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
666 t = tab_create (n_cols,n_rows,0);
667 tab_headers (t, 3, 0, 1, 0);
668 tab_dim (t, tab_natural_dimensions);
670 /* Put a frame around the entire box, and vertical lines inside */
675 n_cols - 1, n_rows - 1);
683 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
684 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
687 tab_title (t, _("Contrast Tests"));
689 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
690 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
691 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
692 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
693 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
694 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
696 for ( v = 0 ; v < n_vars ; ++v )
699 int lines_per_variable = 2 * cmd.sbc_contrast;
702 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
703 var_to_string(vars[v]));
705 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
708 double contrast_value = 0.0;
709 double coef_msq = 0.0;
710 struct group_proc *grp_data = group_proc_get (vars[v]);
711 struct hsh_table *group_hash = grp_data->group_hash;
713 void *const *group_stat_array;
716 double std_error_contrast ;
721 /* Note: The calculation of the degrees of freedom in the
722 "variances not equal" case is painfull!!
723 The following formula may help to understand it:
724 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
727 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
732 double df_denominator = 0.0;
733 double df_numerator = 0.0;
736 tab_text (t, 1, (v * lines_per_variable) + i + 1,
737 TAB_LEFT | TAT_TITLE,
738 _("Assume equal variances"));
740 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
741 TAB_LEFT | TAT_TITLE,
742 _("Does not assume equal"));
745 tab_text (t, 2, (v * lines_per_variable) + i + 1,
746 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
749 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
750 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
753 if ( bad_contrast[i])
756 group_stat_array = hsh_sort(group_hash);
758 for (ci = 0 ; ci < hsh_count(group_hash) ; ++ci)
760 const double coef = subc_list_double_at(&cmd.dl_contrast[i], ci);
761 struct group_statistics *gs = group_stat_array[ci];
763 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
765 contrast_value += coef * gs->mean;
767 coef_msq += (coef * coef) / gs->n ;
769 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
771 df_numerator += (coef * coef) * winv;
772 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
774 sec_vneq = sqrt(sec_vneq);
776 df_numerator = pow2(df_numerator);
778 tab_float (t, 3, (v * lines_per_variable) + i + 1,
779 TAB_RIGHT, contrast_value, 8,2);
781 tab_float (t, 3, (v * lines_per_variable) + i + 1 +
783 TAB_RIGHT, contrast_value, 8,2);
785 std_error_contrast = sqrt(grp_data->mse * coef_msq);
788 tab_float (t, 4, (v * lines_per_variable) + i + 1,
789 TAB_RIGHT, std_error_contrast,
792 T = fabs(contrast_value / std_error_contrast) ;
796 tab_float (t, 5, (v * lines_per_variable) + i + 1,
800 df = grp_data->ugs.n - grp_data->n_groups;
802 /* Degrees of Freedom */
803 tab_float (t, 6, (v * lines_per_variable) + i + 1,
808 /* Significance TWO TAILED !!*/
809 tab_float (t, 7, (v * lines_per_variable) + i + 1,
810 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
814 /* Now for the Variances NOT Equal case */
818 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
823 T = contrast_value / sec_vneq;
825 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
830 df = df_numerator / df_denominator;
833 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
837 /* The Significance */
839 tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
840 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
847 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
855 /* ONEWAY ANOVA Calculations */
857 static void postcalc ( struct cmd_oneway *cmd UNUSED );
859 static void precalc ( struct cmd_oneway *cmd UNUSED );
863 /* Pre calculations */
865 precalc ( struct cmd_oneway *cmd UNUSED )
869 for(i=0; i< n_vars ; ++i)
871 struct group_proc *gp = group_proc_get (vars[i]);
872 struct group_statistics *totals = &gp->ugs;
874 /* Create a hash for each of the dependent variables.
875 The hash contains a group_statistics structure,
876 and is keyed by value of the independent variable */
880 (hsh_compare_func *) compare_group,
881 (hsh_hash_func *) hash_group,
882 (hsh_free_func *) free_group,
883 (void *) indep_var->width );
890 totals->maximum = - DBL_MAX;
891 totals->minimum = DBL_MAX;
897 run_oneway(const struct ccase *first, const struct casefile *cf, void *cmd_)
899 struct casereader *r;
902 struct cmd_oneway *cmd = (struct cmd_oneway *) cmd_;
904 output_split_file_values (first);
906 global_group_hash = hsh_create(4,
907 (hsh_compare_func *) compare_values,
908 (hsh_hash_func *) hash_value,
910 (void *) indep_var->width );
913 for(r = casefile_get_reader (cf);
914 casereader_read (r, &c) ;
919 const double weight =
920 dict_get_case_weight (dataset_dict (current_dataset), &c, &bad_weight_warn);
922 const union value *indep_val = case_data (&c, indep_var->fv);
924 /* Deal with missing values */
925 if ( value_is_missing(&indep_var->miss, indep_val) )
928 /* Skip the entire case if /MISSING=LISTWISE is set */
929 if ( cmd->miss == ONEWAY_LISTWISE )
931 for(i = 0; i < n_vars ; ++i)
933 const struct variable *v = vars[i];
934 const union value *val = case_data (&c, v->fv);
936 if (value_is_missing(&v->miss, val) )
945 hsh_insert ( global_group_hash, (void *) indep_val );
947 for ( i = 0 ; i < n_vars ; ++i )
949 const struct variable *v = vars[i];
951 const union value *val = case_data (&c, v->fv);
953 struct group_proc *gp = group_proc_get (vars[i]);
954 struct hsh_table *group_hash = gp->group_hash;
956 struct group_statistics *gs;
958 gs = hsh_find(group_hash, (void *) indep_val );
962 gs = xmalloc (sizeof *gs);
968 gs->minimum = DBL_MAX;
969 gs->maximum = -DBL_MAX;
971 hsh_insert ( group_hash, (void *) gs );
974 if (! value_is_missing(&v->miss, val) )
976 struct group_statistics *totals = &gp->ugs;
979 totals->sum+=weight * val->f;
980 totals->ssq+=weight * val->f * val->f;
982 if ( val->f * weight < totals->minimum )
983 totals->minimum = val->f * weight;
985 if ( val->f * weight > totals->maximum )
986 totals->maximum = val->f * weight;
989 gs->sum+=weight * val->f;
990 gs->ssq+=weight * val->f * val->f;
992 if ( val->f * weight < gs->minimum )
993 gs->minimum = val->f * weight;
995 if ( val->f * weight > gs->maximum )
996 gs->maximum = val->f * weight;
999 gp->n_groups = hsh_count ( group_hash );
1003 casereader_destroy (r);
1008 if ( stat_tables & STAT_HOMO )
1009 levene(cf, indep_var, n_vars, vars,
1010 (cmd->miss == ONEWAY_LISTWISE) ? LEV_LISTWISE : LEV_ANALYSIS ,
1013 ostensible_number_of_groups = hsh_count (global_group_hash);
1022 /* Post calculations for the ONEWAY command */
1024 postcalc ( struct cmd_oneway *cmd UNUSED )
1029 for(i = 0; i < n_vars ; ++i)
1031 struct group_proc *gp = group_proc_get (vars[i]);
1032 struct hsh_table *group_hash = gp->group_hash;
1033 struct group_statistics *totals = &gp->ugs;
1035 struct hsh_iterator g;
1036 struct group_statistics *gs;
1038 for (gs = hsh_first (group_hash,&g);
1040 gs = hsh_next(group_hash,&g))
1042 gs->mean=gs->sum / gs->n;
1043 gs->s_std_dev= sqrt(
1044 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1049 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1052 gs->se_mean = gs->std_dev / sqrt(gs->n);
1053 gs->mean_diff= gs->sum_diff / gs->n;
1059 totals->mean = totals->sum / totals->n;
1060 totals->std_dev= sqrt(
1061 totals->n/(totals->n-1) *
1062 ( (totals->ssq / totals->n ) - totals->mean * totals->mean )
1065 totals->se_mean = totals->std_dev / sqrt(totals->n);