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
22 #include <gsl/gsl_cdf.h>
23 #include <libpspp/message.h>
27 #include <libpspp/alloc.h>
28 #include <libpspp/str.h>
29 #include <data/case.h>
30 #include <data/dictionary.h>
31 #include <language/command.h>
32 #include <libpspp/compiler.h>
33 #include <language/lexer/lexer.h>
34 #include <libpspp/message.h>
35 #include <libpspp/magic.h>
36 #include <libpspp/misc.h>
37 #include <output/table.h>
38 #include <output/manager.h>
39 #include <data/value-labels.h>
40 #include <data/variable.h>
41 #include <procedure.h>
42 #include <libpspp/hash.h>
43 #include <data/casefile.h>
44 #include <math/group-proc.h>
45 #include <math/group.h>
46 #include <math/levene.h>
48 #include "sort-criteria.h"
51 #define _(msgid) gettext (msgid)
58 +missing=miss:!analysis/listwise,
59 incl:include/!exclude;
60 contrast= double list;
61 statistics[st_]=descriptives,homogeneity.
68 static int bad_weight_warn = 1;
71 static struct cmd_oneway cmd;
73 /* The independent variable */
74 static struct variable *indep_var;
76 /* Number of dependent variables */
79 /* The dependent variables */
80 static struct variable **vars;
83 /* A hash table containing all the distinct values of the independent
85 static struct hsh_table *global_group_hash ;
87 /* The number of distinct values of the independent variable, when all
88 missing values are disregarded */
89 static int ostensible_number_of_groups=-1;
92 /* Function to use for testing for missing values */
93 static is_missing_func *value_is_missing;
96 static bool run_oneway(const struct casefile *cf, void *_mode);
99 /* Routines to show the output tables */
100 static void show_anova_table(void);
101 static void show_descriptives(void);
102 static void show_homogeneity(void);
104 static void show_contrast_coeffs(short *);
105 static void show_contrast_tests(short *);
108 enum stat_table_t {STAT_DESC = 1, STAT_HOMO = 2};
110 static enum stat_table_t stat_tables ;
112 void output_oneway(void);
121 if ( !parse_oneway(&cmd) )
124 /* If /MISSING=INCLUDE is set, then user missing values are ignored */
125 if (cmd.incl == ONEWAY_INCLUDE )
126 value_is_missing = mv_is_value_system_missing;
128 value_is_missing = mv_is_value_missing;
130 /* What statistics were requested */
131 if ( cmd.sbc_statistics )
134 for (i = 0 ; i < ONEWAY_ST_count ; ++i )
136 if ( ! cmd.a_statistics[i] ) continue;
139 case ONEWAY_ST_DESCRIPTIVES:
140 stat_tables |= STAT_DESC;
142 case ONEWAY_ST_HOMOGENEITY:
143 stat_tables |= STAT_HOMO;
149 ok = multipass_procedure_with_splits (run_oneway, &cmd);
154 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
162 short *bad_contrast ;
164 bad_contrast = xnmalloc (cmd.sbc_contrast, sizeof *bad_contrast);
166 /* Check the sanity of the given contrast values */
167 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
173 if ( subc_list_double_count(&cmd.dl_contrast[i]) !=
174 ostensible_number_of_groups )
177 _("Number of contrast coefficients must equal the number of groups"));
182 for (j=0; j < ostensible_number_of_groups ; ++j )
183 sum += subc_list_double_at(&cmd.dl_contrast[i],j);
186 msg(SW,_("Coefficients for contrast %d do not total zero"),i + 1);
189 if ( stat_tables & STAT_DESC )
192 if ( stat_tables & STAT_HOMO )
197 if (cmd.sbc_contrast )
199 show_contrast_coeffs(bad_contrast);
200 show_contrast_tests(bad_contrast);
207 for (i = 0 ; i < n_vars ; ++i )
209 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
211 hsh_destroy(group_hash);
214 hsh_destroy(global_group_hash);
221 /* Parser for the variables sub command */
223 oneway_custom_variables(struct cmd_oneway *cmd UNUSED)
228 if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
233 if (!parse_variables (default_dict, &vars, &n_vars,
235 | PV_NUMERIC | PV_NO_SCRATCH) )
243 if ( ! lex_match(T_BY))
247 indep_var = parse_variable();
251 msg(SE,_("`%s' is not a variable name"),tokid);
260 /* Show the ANOVA table */
262 show_anova_table(void)
266 size_t n_rows = n_vars * 3 + 1;
271 t = tab_create (n_cols,n_rows,0);
272 tab_headers (t, 2, 0, 1, 0);
273 tab_dim (t, tab_natural_dimensions);
280 n_cols - 1, n_rows - 1);
282 tab_hline (t, TAL_2, 0, n_cols - 1, 1 );
283 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
284 tab_vline (t, TAL_0, 1, 0, 0);
286 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
287 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
288 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
289 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
290 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
293 for ( i=0 ; i < n_vars ; ++i )
295 struct group_statistics *totals = &group_proc_get (vars[i])->ugs;
296 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
297 struct hsh_iterator g;
298 struct group_statistics *gs;
300 const char *s = var_to_string(vars[i]);
302 for (gs = hsh_first (group_hash,&g);
304 gs = hsh_next(group_hash,&g))
306 ssa += (gs->sum * gs->sum)/gs->n;
309 ssa -= ( totals->sum * totals->sum ) / totals->n ;
311 tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s);
312 tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups"));
313 tab_text (t, 1, i * 3 + 2, TAB_LEFT | TAT_TITLE, _("Within Groups"));
314 tab_text (t, 1, i * 3 + 3, TAB_LEFT | TAT_TITLE, _("Total"));
317 tab_hline(t, TAL_1, 0, n_cols - 1 , i * 3 + 1);
320 struct group_proc *gp = group_proc_get (vars[i]);
321 const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ;
322 const double df1 = gp->n_groups - 1;
323 const double df2 = totals->n - gp->n_groups ;
324 const double msa = ssa / df1;
326 gp->mse = (sst - ssa) / df2;
329 /* Sums of Squares */
330 tab_float (t, 2, i * 3 + 1, 0, ssa, 10, 2);
331 tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2);
332 tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2);
335 /* Degrees of freedom */
336 tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0);
337 tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0);
338 tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
341 tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3);
342 tab_float (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, 8, 3);
346 const double F = msa/gp->mse ;
349 tab_float (t, 5, i * 3 + 1, 0, F, 8, 3);
351 /* The significance */
352 tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
360 tab_title (t, _("ANOVA"));
366 /* Show the descriptives table */
368 show_descriptives(void)
375 const double confidence=0.95;
376 const double q = (1.0 - confidence) / 2.0;
381 for ( v = 0 ; v < n_vars ; ++v )
382 n_rows += group_proc_get (vars[v])->n_groups + 1;
384 t = tab_create (n_cols,n_rows,0);
385 tab_headers (t, 2, 0, 2, 0);
386 tab_dim (t, tab_natural_dimensions);
389 /* Put a frame around the entire box, and vertical lines inside */
394 n_cols - 1, n_rows - 1);
396 /* Underline headers */
397 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
398 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
400 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
401 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
402 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
403 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
406 tab_vline(t, TAL_0, 7, 0, 0);
407 tab_hline(t, TAL_1, 6, 7, 1);
408 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
410 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
411 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
413 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
414 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
417 tab_title (t, _("Descriptives"));
421 for ( v=0 ; v < n_vars ; ++v )
426 struct group_proc *gp = group_proc_get (vars[v]);
428 struct group_statistics *gs;
429 struct group_statistics *totals = &gp->ugs;
431 const char *s = var_to_string(vars[v]);
433 struct group_statistics *const *gs_array =
434 (struct group_statistics *const *) hsh_sort(gp->group_hash);
437 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
439 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
441 for (count = 0 ; count < hsh_count(gp->group_hash) ; ++count)
443 gs = gs_array[count];
445 tab_text (t, 1, row + count,
446 TAB_LEFT | TAT_TITLE ,value_to_string(&gs->id,indep_var));
448 /* Now fill in the numbers ... */
450 tab_float (t, 2, row + count, 0, gs->n, 8,0);
452 tab_float (t, 3, row + count, 0, gs->mean,8,2);
454 tab_float (t, 4, row + count, 0, gs->std_dev,8,2);
456 std_error = gs->std_dev/sqrt(gs->n) ;
457 tab_float (t, 5, row + count, 0,
460 /* Now the confidence interval */
462 T = gsl_cdf_tdist_Qinv(q,gs->n - 1);
464 tab_float(t, 6, row + count, 0,
465 gs->mean - T * std_error, 8, 2);
467 tab_float(t, 7, row + count, 0,
468 gs->mean + T * std_error, 8, 2);
472 tab_float(t, 8, row + count, 0, gs->minimum, 8, 2);
473 tab_float(t, 9, row + count, 0, gs->maximum, 8, 2);
477 tab_text (t, 1, row + count,
478 TAB_LEFT | TAT_TITLE ,_("Total"));
480 tab_float (t, 2, row + count, 0, totals->n, 8,0);
482 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
484 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
486 std_error = totals->std_dev/sqrt(totals->n) ;
488 tab_float (t, 5, row + count, 0, std_error, 8,2);
490 /* Now the confidence interval */
492 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
494 tab_float(t, 6, row + count, 0,
495 totals->mean - T * std_error, 8, 2);
497 tab_float(t, 7, row + count, 0,
498 totals->mean + T * std_error, 8, 2);
502 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
503 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
505 row += gp->n_groups + 1;
514 /* Show the homogeneity table */
516 show_homogeneity(void)
520 size_t n_rows = n_vars + 1;
525 t = tab_create (n_cols,n_rows,0);
526 tab_headers (t, 1, 0, 1, 0);
527 tab_dim (t, tab_natural_dimensions);
529 /* Put a frame around the entire box, and vertical lines inside */
534 n_cols - 1, n_rows - 1);
537 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
538 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
541 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
542 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
543 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
544 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
547 tab_title (t, _("Test of Homogeneity of Variances"));
549 for ( v=0 ; v < n_vars ; ++v )
552 const struct variable *var = vars[v];
553 const struct group_proc *gp = group_proc_get (vars[v]);
554 const char *s = var_to_string(var);
555 const struct group_statistics *totals = &gp->ugs;
557 const double df1 = gp->n_groups - 1;
558 const double df2 = totals->n - gp->n_groups ;
560 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
563 tab_float (t, 1, v + 1, TAB_RIGHT, F, 8,3);
564 tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0);
565 tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0);
567 /* Now the significance */
568 tab_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
577 /* Show the contrast coefficients table */
579 show_contrast_coeffs(short *bad_contrast)
581 int n_cols = 2 + ostensible_number_of_groups;
582 int n_rows = 2 + cmd.sbc_contrast;
583 union value *group_value;
585 void *const *group_values ;
589 t = tab_create (n_cols,n_rows,0);
590 tab_headers (t, 2, 0, 2, 0);
591 tab_dim (t, tab_natural_dimensions);
593 /* Put a frame around the entire box, and vertical lines inside */
598 n_cols - 1, n_rows - 1);
612 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
613 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
615 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
617 tab_title (t, _("Contrast Coefficients"));
619 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
622 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
623 var_to_string(indep_var));
625 group_values = hsh_sort(global_group_hash);
627 count < hsh_count(global_group_hash) ;
631 group_value = group_values[count];
633 tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
634 value_to_string(group_value, indep_var));
636 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
638 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
640 if ( bad_contrast[i] )
641 tab_text(t, count + 2, i + 2, TAB_RIGHT, "?" );
643 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
644 subc_list_double_at(&cmd.dl_contrast[i], count)
653 /* Show the results of the contrast tests */
655 show_contrast_tests(short *bad_contrast)
659 size_t n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
663 t = tab_create (n_cols,n_rows,0);
664 tab_headers (t, 3, 0, 1, 0);
665 tab_dim (t, tab_natural_dimensions);
667 /* Put a frame around the entire box, and vertical lines inside */
672 n_cols - 1, n_rows - 1);
680 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
681 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
684 tab_title (t, _("Contrast Tests"));
686 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
687 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
688 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
689 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
690 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
691 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
693 for ( v = 0 ; v < n_vars ; ++v )
696 int lines_per_variable = 2 * cmd.sbc_contrast;
699 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
700 var_to_string(vars[v]));
702 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
705 double contrast_value = 0.0;
706 double coef_msq = 0.0;
707 struct group_proc *grp_data = group_proc_get (vars[v]);
708 struct hsh_table *group_hash = grp_data->group_hash;
710 void *const *group_stat_array;
713 double std_error_contrast ;
718 /* Note: The calculation of the degrees of freedom in the
719 "variances not equal" case is painfull!!
720 The following formula may help to understand it:
721 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
724 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
729 double df_denominator = 0.0;
730 double df_numerator = 0.0;
733 tab_text (t, 1, (v * lines_per_variable) + i + 1,
734 TAB_LEFT | TAT_TITLE,
735 _("Assume equal variances"));
737 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
738 TAB_LEFT | TAT_TITLE,
739 _("Does not assume equal"));
742 tab_text (t, 2, (v * lines_per_variable) + i + 1,
743 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
746 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
747 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
750 if ( bad_contrast[i])
753 group_stat_array = hsh_sort(group_hash);
755 for (ci = 0 ; ci < hsh_count(group_hash) ; ++ci)
757 const double coef = subc_list_double_at(&cmd.dl_contrast[i], ci);
758 struct group_statistics *gs = group_stat_array[ci];
760 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
762 contrast_value += coef * gs->mean;
764 coef_msq += (coef * coef) / gs->n ;
766 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
768 df_numerator += (coef * coef) * winv;
769 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
771 sec_vneq = sqrt(sec_vneq);
773 df_numerator = pow2(df_numerator);
775 tab_float (t, 3, (v * lines_per_variable) + i + 1,
776 TAB_RIGHT, contrast_value, 8,2);
778 tab_float (t, 3, (v * lines_per_variable) + i + 1 +
780 TAB_RIGHT, contrast_value, 8,2);
782 std_error_contrast = sqrt(grp_data->mse * coef_msq);
785 tab_float (t, 4, (v * lines_per_variable) + i + 1,
786 TAB_RIGHT, std_error_contrast,
789 T = fabs(contrast_value / std_error_contrast) ;
793 tab_float (t, 5, (v * lines_per_variable) + i + 1,
797 df = grp_data->ugs.n - grp_data->n_groups;
799 /* Degrees of Freedom */
800 tab_float (t, 6, (v * lines_per_variable) + i + 1,
805 /* Significance TWO TAILED !!*/
806 tab_float (t, 7, (v * lines_per_variable) + i + 1,
807 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
811 /* Now for the Variances NOT Equal case */
815 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
820 T = contrast_value / sec_vneq;
822 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
827 df = df_numerator / df_denominator;
830 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
834 /* The Significance */
836 tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
837 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
844 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
852 /* ONEWAY ANOVA Calculations */
854 static void postcalc ( struct cmd_oneway *cmd UNUSED );
856 static void precalc ( struct cmd_oneway *cmd UNUSED );
860 /* Pre calculations */
862 precalc ( struct cmd_oneway *cmd UNUSED )
866 for(i=0; i< n_vars ; ++i)
868 struct group_proc *gp = group_proc_get (vars[i]);
869 struct group_statistics *totals = &gp->ugs;
871 /* Create a hash for each of the dependent variables.
872 The hash contains a group_statistics structure,
873 and is keyed by value of the independent variable */
877 (hsh_compare_func *) compare_group,
878 (hsh_hash_func *) hash_group,
879 (hsh_free_func *) free_group,
880 (void *) indep_var->width );
887 totals->maximum = - DBL_MAX;
888 totals->minimum = DBL_MAX;
894 run_oneway(const struct casefile *cf, void *cmd_)
896 struct casereader *r;
899 struct cmd_oneway *cmd = (struct cmd_oneway *) cmd_;
901 global_group_hash = hsh_create(4,
902 (hsh_compare_func *) compare_values,
903 (hsh_hash_func *) hash_value,
905 (void *) indep_var->width );
908 for(r = casefile_get_reader (cf);
909 casereader_read (r, &c) ;
914 const double weight =
915 dict_get_case_weight(default_dict,&c,&bad_weight_warn);
917 const union value *indep_val = case_data (&c, indep_var->fv);
919 /* Deal with missing values */
920 if ( value_is_missing(&indep_var->miss, indep_val) )
923 /* Skip the entire case if /MISSING=LISTWISE is set */
924 if ( cmd->miss == ONEWAY_LISTWISE )
926 for(i = 0; i < n_vars ; ++i)
928 const struct variable *v = vars[i];
929 const union value *val = case_data (&c, v->fv);
931 if (value_is_missing(&v->miss, val) )
940 hsh_insert ( global_group_hash, (void *) indep_val );
942 for ( i = 0 ; i < n_vars ; ++i )
944 const struct variable *v = vars[i];
946 const union value *val = case_data (&c, v->fv);
948 struct group_proc *gp = group_proc_get (vars[i]);
949 struct hsh_table *group_hash = gp->group_hash;
951 struct group_statistics *gs;
953 gs = hsh_find(group_hash, (void *) indep_val );
957 gs = xmalloc (sizeof *gs);
963 gs->minimum = DBL_MAX;
964 gs->maximum = -DBL_MAX;
966 hsh_insert ( group_hash, (void *) gs );
969 if (! value_is_missing(&v->miss, val) )
971 struct group_statistics *totals = &gp->ugs;
974 totals->sum+=weight * val->f;
975 totals->ssq+=weight * val->f * val->f;
977 if ( val->f * weight < totals->minimum )
978 totals->minimum = val->f * weight;
980 if ( val->f * weight > totals->maximum )
981 totals->maximum = val->f * weight;
984 gs->sum+=weight * val->f;
985 gs->ssq+=weight * val->f * val->f;
987 if ( val->f * weight < gs->minimum )
988 gs->minimum = val->f * weight;
990 if ( val->f * weight > gs->maximum )
991 gs->maximum = val->f * weight;
994 gp->n_groups = hsh_count ( group_hash );
998 casereader_destroy (r);
1003 if ( stat_tables & STAT_HOMO )
1004 levene(cf, indep_var, n_vars, vars,
1005 (cmd->miss == ONEWAY_LISTWISE) ? LEV_LISTWISE : LEV_ANALYSIS ,
1008 ostensible_number_of_groups = hsh_count (global_group_hash);
1017 /* Post calculations for the ONEWAY command */
1019 postcalc ( struct cmd_oneway *cmd UNUSED )
1024 for(i = 0; i < n_vars ; ++i)
1026 struct group_proc *gp = group_proc_get (vars[i]);
1027 struct hsh_table *group_hash = gp->group_hash;
1028 struct group_statistics *totals = &gp->ugs;
1030 struct hsh_iterator g;
1031 struct group_statistics *gs;
1033 for (gs = hsh_first (group_hash,&g);
1035 gs = hsh_next(group_hash,&g))
1037 gs->mean=gs->sum / gs->n;
1038 gs->s_std_dev= sqrt(
1039 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1044 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1047 gs->se_mean = gs->std_dev / sqrt(gs->n);
1048 gs->mean_diff= gs->sum_diff / gs->n;
1054 totals->mean = totals->sum / totals->n;
1055 totals->std_dev= sqrt(
1056 totals->n/(totals->n-1) *
1057 ( (totals->ssq / totals->n ) - totals->mean * totals->mean )
1060 totals->se_mean = totals->std_dev / sqrt(totals->n);