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., 59 Temple Place - Suite 330, Boston, MA
22 #include <gsl/gsl_cdf.h>
30 #include "dictionary.h"
38 #include "value-labels.h"
43 #include "group_proc.h"
51 +missing=miss:!analysis/listwise,
52 incl:include/!exclude;
53 contrast= double list;
54 statistics[st_]=descriptives,homogeneity.
61 static int bad_weight_warn = 1;
64 static struct cmd_oneway cmd;
66 /* The independent variable */
67 static struct variable *indep_var;
69 /* Number of dependent variables */
72 /* The dependent variables */
73 static struct variable **vars;
76 /* A hash table containing all the distinct values of the independent
78 static struct hsh_table *global_group_hash ;
80 /* The number of distinct values of the independent variable, when all
81 missing values are disregarded */
82 static int ostensible_number_of_groups=-1;
85 /* Function to use for testing for missing values */
86 static is_missing_func value_is_missing;
89 static void run_oneway(const struct casefile *cf, void *_mode);
92 /* Routines to show the output tables */
93 static void show_anova_table(void);
94 static void show_descriptives(void);
95 static void show_homogeneity(void);
97 static void show_contrast_coeffs(short *);
98 static void show_contrast_tests(short *);
101 enum stat_table_t {STAT_DESC = 1, STAT_HOMO = 2};
103 static enum stat_table_t stat_tables ;
105 void output_oneway(void);
113 if ( !parse_oneway(&cmd) )
116 /* If /MISSING=INCLUDE is set, then user missing values are ignored */
117 if (cmd.incl == ONEWAY_INCLUDE )
118 value_is_missing = is_system_missing;
120 value_is_missing = is_missing;
122 /* What statistics were requested */
123 if ( cmd.sbc_statistics )
126 for (i = 0 ; i < ONEWAY_ST_count ; ++i )
128 if ( ! cmd.a_statistics[i] ) continue;
131 case ONEWAY_ST_DESCRIPTIVES:
132 stat_tables |= STAT_DESC;
134 case ONEWAY_ST_HOMOGENEITY:
135 stat_tables |= STAT_HOMO;
141 multipass_procedure_with_splits (run_oneway, &cmd);
153 short *bad_contrast ;
155 bad_contrast = xmalloc ( sizeof (short) * cmd.sbc_contrast );
157 /* Check the sanity of the given contrast values */
158 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
164 if ( subc_list_double_count(&cmd.dl_contrast[i]) !=
165 ostensible_number_of_groups )
168 _("Number of contrast coefficients must equal the number of groups"));
173 for (j=0; j < ostensible_number_of_groups ; ++j )
174 sum += subc_list_double_at(&cmd.dl_contrast[i],j);
177 msg(SW,_("Coefficients for contrast %d do not total zero"),i + 1);
180 if ( stat_tables & STAT_DESC )
183 if ( stat_tables & STAT_HOMO )
188 if (cmd.sbc_contrast )
190 show_contrast_coeffs(bad_contrast);
191 show_contrast_tests(bad_contrast);
198 for (i = 0 ; i < n_vars ; ++i )
200 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
202 hsh_destroy(group_hash);
205 hsh_destroy(global_group_hash);
212 /* Parser for the variables sub command */
214 oneway_custom_variables(struct cmd_oneway *cmd UNUSED)
219 if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
224 if (!parse_variables (default_dict, &vars, &n_vars,
226 | PV_NUMERIC | PV_NO_SCRATCH) )
234 if ( ! lex_match(T_BY))
238 indep_var = parse_variable();
242 msg(SE,_("`%s' is not a variable name"),tokid);
251 /* Show the ANOVA table */
253 show_anova_table(void)
257 int n_rows = n_vars * 3 + 1;
262 t = tab_create (n_cols,n_rows,0);
263 tab_headers (t, 2, 0, 1, 0);
264 tab_dim (t, tab_natural_dimensions);
271 n_cols - 1, n_rows - 1);
273 tab_hline (t, TAL_2, 0, n_cols - 1, 1 );
274 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
275 tab_vline (t, TAL_0, 1, 0, 0);
277 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
278 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
279 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
280 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
281 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
284 for ( i=0 ; i < n_vars ; ++i )
286 struct group_statistics *totals = &group_proc_get (vars[i])->ugs;
287 struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash;
288 struct hsh_iterator g;
289 struct group_statistics *gs;
293 for (gs = hsh_first (group_hash,&g);
295 gs = hsh_next(group_hash,&g))
297 ssa += (gs->sum * gs->sum)/gs->n;
300 ssa -= ( totals->sum * totals->sum ) / totals->n ;
302 const char *s = var_to_string(vars[i]);
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, 0, _("ANOVA"));
359 /* Show the descriptives table */
361 show_descriptives(void)
368 const double confidence=0.95;
369 const double q = (1.0 - confidence) / 2.0;
376 for ( v = 0 ; v < n_vars ; ++v )
377 n_rows += group_proc_get (vars[v])->n_groups + 1;
379 t = tab_create (n_cols,n_rows,0);
380 tab_headers (t, 2, 0, 2, 0);
381 tab_dim (t, tab_natural_dimensions);
384 /* Put a frame around the entire box, and vertical lines inside */
389 n_cols - 1, n_rows - 1);
391 /* Underline headers */
392 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
393 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
395 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
396 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
397 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
398 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
401 tab_vline(t, TAL_0, 7, 0, 0);
402 tab_hline(t, TAL_1, 6, 7, 1);
403 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
405 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
406 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
408 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
409 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
412 tab_title (t, 0, _("Descriptives"));
416 for ( v=0 ; v < n_vars ; ++v )
421 struct group_proc *gp = group_proc_get (vars[v]);
423 struct hsh_iterator g;
424 struct group_statistics *gs;
425 struct group_statistics *totals = &gp->ugs;
428 const char *s = var_to_string(vars[v]);
430 struct hsh_table *group_hash = gp->group_hash;
433 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
435 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
438 for (gs = hsh_first (group_hash,&g);
440 gs = hsh_next(group_hash,&g))
442 const char *s = val_labs_find(indep_var->val_labs, gs->id );
445 tab_text (t, 1, row + count,
446 TAB_LEFT | TAT_TITLE ,s);
447 else if ( indep_var->width != 0 )
448 tab_text (t, 1, row + count,
449 TAB_LEFT | TAT_TITLE, gs->id.s);
451 tab_text (t, 1, row + count,
452 TAB_LEFT | TAT_TITLE | TAT_PRINTF, "%g", gs->id.f);
455 /* Now fill in the numbers ... */
457 tab_float (t, 2, row + count, 0, gs->n, 8,0);
459 tab_float (t, 3, row + count, 0, gs->mean,8,2);
461 tab_float (t, 4, row + count, 0, gs->std_dev,8,2);
463 std_error = gs->std_dev/sqrt(gs->n) ;
464 tab_float (t, 5, row + count, 0,
467 /* Now the confidence interval */
469 T = gsl_cdf_tdist_Qinv(q,gs->n - 1);
471 tab_float(t, 6, row + count, 0,
472 gs->mean - T * std_error, 8, 2);
474 tab_float(t, 7, row + count, 0,
475 gs->mean + T * std_error, 8, 2);
479 tab_float(t, 8, row + count, 0, gs->minimum, 8, 2);
480 tab_float(t, 9, row + count, 0, gs->maximum, 8, 2);
485 tab_text (t, 1, row + count,
486 TAB_LEFT | TAT_TITLE ,_("Total"));
488 tab_float (t, 2, row + count, 0, totals->n, 8,0);
490 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
492 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
494 std_error = totals->std_dev/sqrt(totals->n) ;
496 tab_float (t, 5, row + count, 0, std_error, 8,2);
498 /* Now the confidence interval */
500 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
502 tab_float(t, 6, row + count, 0,
503 totals->mean - T * std_error, 8, 2);
505 tab_float(t, 7, row + count, 0,
506 totals->mean + T * std_error, 8, 2);
510 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
511 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
513 row += gp->n_groups + 1;
522 /* Show the homogeneity table */
524 show_homogeneity(void)
528 int n_rows = n_vars + 1;
533 t = tab_create (n_cols,n_rows,0);
534 tab_headers (t, 1, 0, 1, 0);
535 tab_dim (t, tab_natural_dimensions);
537 /* Put a frame around the entire box, and vertical lines inside */
542 n_cols - 1, n_rows - 1);
545 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
546 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
549 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
550 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
551 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
552 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
555 tab_title (t, 0, _("Test of Homogeneity of Variances"));
557 for ( v=0 ; v < n_vars ; ++v )
560 const struct variable *var = vars[v];
561 const struct group_proc *gp = group_proc_get (vars[v]);
562 const char *s = var_to_string(var);
563 const struct group_statistics *totals = &gp->ugs;
565 const double df1 = gp->n_groups - 1;
566 const double df2 = totals->n - gp->n_groups ;
568 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
571 tab_float (t, 1, v + 1, TAB_RIGHT, F, 8,3);
572 tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0);
573 tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0);
575 /* Now the significance */
576 tab_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
585 /* Show the contrast coefficients table */
587 show_contrast_coeffs(short *bad_contrast)
589 int n_cols = 2 + ostensible_number_of_groups;
590 int n_rows = 2 + cmd.sbc_contrast;
591 struct hsh_iterator g;
592 union value *group_value;
599 t = tab_create (n_cols,n_rows,0);
600 tab_headers (t, 2, 0, 2, 0);
601 tab_dim (t, tab_natural_dimensions);
603 /* Put a frame around the entire box, and vertical lines inside */
608 n_cols - 1, n_rows - 1);
624 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
627 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
628 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
631 tab_title (t, 0, _("Contrast Coefficients"));
633 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
637 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
638 var_to_string(indep_var));
640 for (group_value = hsh_first (global_group_hash,&g);
642 group_value = hsh_next(global_group_hash,&g))
646 tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
647 value_to_string(group_value,indep_var));
649 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
652 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
654 if ( bad_contrast[i] )
655 tab_text(t, count + 2, i + 2, TAB_RIGHT, "?" );
657 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
658 subc_list_double_at(&cmd.dl_contrast[i],count)
670 /* Show the results of the contrast tests */
672 show_contrast_tests(short *bad_contrast)
676 int n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
680 t = tab_create (n_cols,n_rows,0);
681 tab_headers (t, 3, 0, 1, 0);
682 tab_dim (t, tab_natural_dimensions);
684 /* Put a frame around the entire box, and vertical lines inside */
689 n_cols - 1, n_rows - 1);
697 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
698 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
701 tab_title (t, 0, _("Contrast Tests"));
703 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
704 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
705 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
706 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
707 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
708 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
710 for ( v = 0 ; v < n_vars ; ++v )
713 int lines_per_variable = 2 * cmd.sbc_contrast;
716 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
717 var_to_string(vars[v]));
719 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
722 double contrast_value = 0.0;
723 double coef_msq = 0.0;
724 struct group_proc *grp_data = group_proc_get (vars[v]);
725 struct hsh_table *group_hash = grp_data->group_hash;
726 struct hsh_iterator g;
727 struct group_statistics *gs;
730 double std_error_contrast ;
735 /* Note: The calculation of the degrees of freedom in the variances
736 not equal case is painfull!!
737 The following formula may help to understand it:
738 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
741 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
746 double df_denominator = 0.0;
747 double df_numerator = 0.0;
752 tab_text (t, 1, (v * lines_per_variable) + i + 1,
753 TAB_LEFT | TAT_TITLE,
754 _("Assume equal variances"));
756 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
757 TAB_LEFT | TAT_TITLE,
758 _("Does not assume equal"));
761 tab_text (t, 2, (v * lines_per_variable) + i + 1,
762 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
765 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
766 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
769 if ( bad_contrast[i])
772 /* FIXME: Potential danger here.
773 We're ASSUMING THE array is in the order corresponding to the
775 for (ci = 0, gs = hsh_first (group_hash,&g);
777 ++ci, gs = hsh_next(group_hash,&g))
780 const double coef = subc_list_double_at(&cmd.dl_contrast[i],ci);
781 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
783 contrast_value += coef * gs->mean;
785 coef_msq += (coef * coef) / gs->n ;
787 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
789 df_numerator += (coef * coef) * winv;
790 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
793 sec_vneq = sqrt(sec_vneq);
795 df_numerator = pow2(df_numerator);
797 tab_float (t, 3, (v * lines_per_variable) + i + 1,
798 TAB_RIGHT, contrast_value, 8,2);
800 tab_float (t, 3, (v * lines_per_variable) + i + 1 +
802 TAB_RIGHT, contrast_value, 8,2);
804 std_error_contrast = sqrt(grp_data->mse * coef_msq);
807 tab_float (t, 4, (v * lines_per_variable) + i + 1,
808 TAB_RIGHT, std_error_contrast,
811 T = fabs(contrast_value / std_error_contrast) ;
815 tab_float (t, 5, (v * lines_per_variable) + i + 1,
819 df = grp_data->ugs.n - grp_data->n_groups;
821 /* Degrees of Freedom */
822 tab_float (t, 6, (v * lines_per_variable) + i + 1,
827 /* Significance TWO TAILED !!*/
828 tab_float (t, 7, (v * lines_per_variable) + i + 1,
829 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
833 /* Now for the Variances NOT Equal case */
837 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
842 T = contrast_value / sec_vneq;
844 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
849 df = df_numerator / df_denominator;
852 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
856 /* The Significance */
858 tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
859 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
866 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
874 /* ONEWAY ANOVA Calculations */
876 static void postcalc ( struct cmd_oneway *cmd UNUSED );
878 static void precalc ( struct cmd_oneway *cmd UNUSED );
882 /* Pre calculations */
884 precalc ( struct cmd_oneway *cmd UNUSED )
888 for(i=0; i< n_vars ; ++i)
890 struct group_proc *gp = group_proc_get (vars[i]);
891 struct group_statistics *totals = &gp->ugs;
893 /* Create a hash for each of the dependent variables.
894 The hash contains a group_statistics structure,
895 and is keyed by value of the independent variable */
899 (hsh_compare_func *) compare_group,
900 (hsh_hash_func *) hash_group,
901 (hsh_free_func *) free_group,
902 (void *) indep_var->width );
909 totals->maximum = - DBL_MAX;
910 totals->minimum = DBL_MAX;
916 run_oneway(const struct casefile *cf, void *cmd_)
918 struct casereader *r;
921 struct cmd_oneway *cmd = (struct cmd_oneway *) cmd_;
923 global_group_hash = hsh_create(4,
924 (hsh_compare_func *) compare_values,
925 (hsh_hash_func *) hash_value,
927 (void *) indep_var->width );
930 for(r = casefile_get_reader (cf);
931 casereader_read (r, &c) ;
936 const double weight =
937 dict_get_case_weight(default_dict,&c,&bad_weight_warn);
939 const union value *indep_val = case_data (&c, indep_var->fv);
941 /* Deal with missing values */
942 if ( value_is_missing(indep_val,indep_var) )
945 /* Skip the entire case if /MISSING=LISTWISE is set */
946 if ( cmd->miss == ONEWAY_LISTWISE )
948 for(i = 0; i < n_vars ; ++i)
950 const struct variable *v = vars[i];
951 const union value *val = case_data (&c, v->fv);
953 if (value_is_missing(val,v) )
962 hsh_insert ( global_group_hash, (void *) indep_val );
964 for ( i = 0 ; i < n_vars ; ++i )
966 const struct variable *v = vars[i];
968 const union value *val = case_data (&c, v->fv);
970 struct group_proc *gp = group_proc_get (vars[i]);
971 struct hsh_table *group_hash = gp->group_hash;
973 struct group_statistics *gs;
975 gs = hsh_find(group_hash, (void *) indep_val );
979 gs = (struct group_statistics *)
980 xmalloc (sizeof(struct group_statistics));
987 gs->minimum = DBL_MAX;
988 gs->maximum = -DBL_MAX;
990 hsh_insert ( group_hash, (void *) gs );
993 if (! value_is_missing(val,v) )
995 struct group_statistics *totals = &gp->ugs;
998 totals->sum+=weight * val->f;
999 totals->ssq+=weight * val->f * val->f;
1001 if ( val->f * weight < totals->minimum )
1002 totals->minimum = val->f * weight;
1004 if ( val->f * weight > totals->maximum )
1005 totals->maximum = val->f * weight;
1008 gs->sum+=weight * val->f;
1009 gs->ssq+=weight * val->f * val->f;
1011 if ( val->f * weight < gs->minimum )
1012 gs->minimum = val->f * weight;
1014 if ( val->f * weight > gs->maximum )
1015 gs->maximum = val->f * weight;
1018 gp->n_groups = hsh_count ( group_hash );
1022 casereader_destroy (r);
1027 if ( stat_tables & STAT_HOMO )
1028 levene(cf, indep_var, n_vars, vars,
1029 (cmd->miss == ONEWAY_LISTWISE) ? LEV_LISTWISE : LEV_ANALYSIS ,
1032 ostensible_number_of_groups = hsh_count (global_group_hash);
1041 /* Post calculations for the ONEWAY command */
1043 postcalc ( struct cmd_oneway *cmd UNUSED )
1048 for(i = 0; i < n_vars ; ++i)
1050 struct group_proc *gp = group_proc_get (vars[i]);
1051 struct hsh_table *group_hash = gp->group_hash;
1052 struct group_statistics *totals = &gp->ugs;
1054 struct hsh_iterator g;
1055 struct group_statistics *gs;
1057 for (gs = hsh_first (group_hash,&g);
1059 gs = hsh_next(group_hash,&g))
1061 gs->mean=gs->sum / gs->n;
1062 gs->s_std_dev= sqrt(
1063 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1068 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1071 gs->se_mean = gs->std_dev / sqrt(gs->n);
1072 gs->mean_diff= gs->sum_diff / gs->n;
1078 totals->mean = totals->sum / totals->n;
1079 totals->std_dev= sqrt(
1080 totals->n/(totals->n-1) *
1081 ( (totals->ssq / totals->n ) - totals->mean * totals->mean )
1084 totals->se_mean = totals->std_dev / sqrt(totals->n);