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>
37 #include "value-labels.h"
42 #include "group_proc.h"
49 +missing=miss:!analysis/listwise,
50 incl:include/!exclude;
51 contrast= double list;
52 statistics[st_]=descriptives,homogeneity.
59 static int bad_weight_warn = 1;
62 static struct cmd_oneway cmd;
64 /* The independent variable */
65 static struct variable *indep_var;
67 /* Number of dependent variables */
70 /* The dependent variables */
71 static struct variable **vars;
74 /* A hash table containing all the distinct values of the independent
76 static struct hsh_table *global_group_hash ;
78 /* The number of distinct values of the independent variable, when all
79 missing values are disregarded */
80 static int ostensible_number_of_groups=-1;
83 /* Function to use for testing for missing values */
84 static is_missing_func value_is_missing;
87 static void run_oneway(const struct casefile *cf, void *_mode);
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);
111 if ( !parse_oneway(&cmd) )
114 /* If /MISSING=INCLUDE is set, then user missing values are ignored */
115 if (cmd.incl == ONEWAY_INCLUDE )
116 value_is_missing = is_system_missing;
118 value_is_missing = is_missing;
120 /* What statistics were requested */
121 if ( cmd.sbc_statistics )
124 for (i = 0 ; i < ONEWAY_ST_count ; ++i )
126 if ( ! cmd.a_statistics[i] ) continue;
129 case ONEWAY_ST_DESCRIPTIVES:
130 stat_tables |= STAT_DESC;
132 case ONEWAY_ST_HOMOGENEITY:
133 stat_tables |= STAT_HOMO;
139 multipass_procedure_with_splits (run_oneway, &cmd);
151 short *bad_contrast ;
153 bad_contrast = xmalloc ( sizeof (short) * cmd.sbc_contrast );
155 /* Check the sanity of the given contrast values */
156 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
162 if ( subc_list_double_count(&cmd.dl_contrast[i]) !=
163 ostensible_number_of_groups )
166 _("Number of contrast coefficients must equal the number of groups"));
171 for (j=0; j < ostensible_number_of_groups ; ++j )
172 sum += subc_list_double_at(&cmd.dl_contrast[i],j);
175 msg(SW,_("Coefficients for contrast %d do not total zero"),i + 1);
178 if ( stat_tables & STAT_DESC )
181 if ( stat_tables & STAT_HOMO )
186 if (cmd.sbc_contrast )
188 show_contrast_coeffs(bad_contrast);
189 show_contrast_tests(bad_contrast);
196 for (i = 0 ; i < n_vars ; ++i )
198 struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash;
200 hsh_destroy(group_hash);
203 hsh_destroy(global_group_hash);
210 /* Parser for the variables sub command */
212 oneway_custom_variables(struct cmd_oneway *cmd UNUSED)
217 if ((token != T_ID || dict_lookup_var (default_dict, tokid) == NULL)
222 if (!parse_variables (default_dict, &vars, &n_vars,
224 | PV_NUMERIC | PV_NO_SCRATCH) )
232 if ( ! lex_match(T_BY))
236 indep_var = parse_variable();
240 msg(SE,_("`%s' is not a variable name"),tokid);
249 /* Show the ANOVA table */
251 show_anova_table(void)
255 int n_rows = n_vars * 3 + 1;
260 t = tab_create (n_cols,n_rows,0);
261 tab_headers (t, 2, 0, 1, 0);
262 tab_dim (t, tab_natural_dimensions);
269 n_cols - 1, n_rows - 1);
271 tab_hline (t, TAL_2, 0, n_cols - 1, 1 );
272 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
273 tab_vline (t, TAL_0, 1, 0, 0);
275 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Sum of Squares"));
276 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df"));
277 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Mean Square"));
278 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("F"));
279 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
282 for ( i=0 ; i < n_vars ; ++i )
284 struct group_statistics *totals = &vars[i]->p.grp_data.ugs;
285 struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash;
286 struct hsh_iterator g;
287 struct group_statistics *gs;
291 for (gs = hsh_first (group_hash,&g);
293 gs = hsh_next(group_hash,&g))
295 ssa += (gs->sum * gs->sum)/gs->n;
298 ssa -= ( totals->sum * totals->sum ) / totals->n ;
300 const char *s = var_to_string(vars[i]);
302 tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s);
303 tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups"));
304 tab_text (t, 1, i * 3 + 2, TAB_LEFT | TAT_TITLE, _("Within Groups"));
305 tab_text (t, 1, i * 3 + 3, TAB_LEFT | TAT_TITLE, _("Total"));
308 tab_hline(t, TAL_1, 0, n_cols - 1 , i * 3 + 1);
311 const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ;
312 const double df1 = vars[i]->p.grp_data.n_groups - 1;
313 const double df2 = totals->n - vars[i]->p.grp_data.n_groups ;
314 const double msa = ssa / df1;
316 vars[i]->p.grp_data.mse = (sst - ssa) / df2;
319 /* Sums of Squares */
320 tab_float (t, 2, i * 3 + 1, 0, ssa, 10, 2);
321 tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2);
322 tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2);
325 /* Degrees of freedom */
326 tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0);
327 tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0);
328 tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
331 tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3);
332 tab_float (t, 4, i * 3 + 2, TAB_RIGHT, vars[i]->p.grp_data.mse, 8, 3);
336 const double F = msa/vars[i]->p.grp_data.mse ;
339 tab_float (t, 5, i * 3 + 1, 0, F, 8, 3);
341 /* The significance */
342 tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
350 tab_title (t, 0, _("ANOVA"));
356 /* Show the descriptives table */
358 show_descriptives(void)
365 const double confidence=0.95;
366 const double q = (1.0 - confidence) / 2.0;
373 for ( v = 0 ; v < n_vars ; ++v )
374 n_rows += vars[v]->p.grp_data.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, 0, _("Descriptives"));
413 for ( v=0 ; v < n_vars ; ++v )
419 struct hsh_iterator g;
420 struct group_statistics *gs;
421 struct group_statistics *totals = &vars[v]->p.grp_data.ugs;
424 const char *s = var_to_string(vars[v]);
426 struct hsh_table *group_hash = vars[v]->p.grp_data.group_hash;
429 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
431 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
434 for (gs = hsh_first (group_hash,&g);
436 gs = hsh_next(group_hash,&g))
438 const char *s = val_labs_find(indep_var->val_labs, gs->id );
441 tab_text (t, 1, row + count,
442 TAB_LEFT | TAT_TITLE ,s);
443 else if ( indep_var->width != 0 )
444 tab_text (t, 1, row + count,
445 TAB_LEFT | TAT_TITLE, gs->id.s);
447 tab_text (t, 1, row + count,
448 TAB_LEFT | TAT_TITLE | TAT_PRINTF, "%g", gs->id.f);
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);
481 tab_text (t, 1, row + count,
482 TAB_LEFT | TAT_TITLE ,_("Total"));
484 tab_float (t, 2, row + count, 0, totals->n, 8,0);
486 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
488 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
490 std_error = totals->std_dev/sqrt(totals->n) ;
492 tab_float (t, 5, row + count, 0, std_error, 8,2);
494 /* Now the confidence interval */
496 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
498 tab_float(t, 6, row + count, 0,
499 totals->mean - T * std_error, 8, 2);
501 tab_float(t, 7, row + count, 0,
502 totals->mean + T * std_error, 8, 2);
506 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
507 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
509 row += vars[v]->p.grp_data.n_groups + 1;
518 /* Show the homogeneity table */
520 show_homogeneity(void)
524 int n_rows = n_vars + 1;
529 t = tab_create (n_cols,n_rows,0);
530 tab_headers (t, 1, 0, 1, 0);
531 tab_dim (t, tab_natural_dimensions);
533 /* Put a frame around the entire box, and vertical lines inside */
538 n_cols - 1, n_rows - 1);
541 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
542 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
545 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
546 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
547 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
548 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
551 tab_title (t, 0, _("Test of Homogeneity of Variances"));
553 for ( v=0 ; v < n_vars ; ++v )
556 const struct variable *var = vars[v];
557 const char *s = var_to_string(var);
558 const struct group_statistics *totals = &var->p.grp_data.ugs;
560 const double df1 = var->p.grp_data.n_groups - 1;
561 const double df2 = totals->n - var->p.grp_data.n_groups ;
563 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
565 F = var->p.grp_data.levene;
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 struct hsh_iterator g;
587 union value *group_value;
594 t = tab_create (n_cols,n_rows,0);
595 tab_headers (t, 2, 0, 2, 0);
596 tab_dim (t, tab_natural_dimensions);
598 /* Put a frame around the entire box, and vertical lines inside */
603 n_cols - 1, n_rows - 1);
619 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
622 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
623 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
626 tab_title (t, 0, _("Contrast Coefficients"));
628 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
632 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
633 var_to_string(indep_var));
635 for (group_value = hsh_first (global_group_hash,&g);
637 group_value = hsh_next(global_group_hash,&g))
641 tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
642 value_to_string(group_value,indep_var));
644 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
647 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
649 if ( bad_contrast[i] )
650 tab_text(t, count + 2, i + 2, TAB_RIGHT, "?" );
652 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
653 subc_list_double_at(&cmd.dl_contrast[i],count)
665 /* Show the results of the contrast tests */
667 show_contrast_tests(short *bad_contrast)
671 int n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
675 t = tab_create (n_cols,n_rows,0);
676 tab_headers (t, 3, 0, 1, 0);
677 tab_dim (t, tab_natural_dimensions);
679 /* Put a frame around the entire box, and vertical lines inside */
684 n_cols - 1, n_rows - 1);
692 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
693 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
696 tab_title (t, 0, _("Contrast Tests"));
698 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
699 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
700 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
701 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
702 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
703 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
705 for ( v = 0 ; v < n_vars ; ++v )
708 int lines_per_variable = 2 * cmd.sbc_contrast;
711 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
712 var_to_string(vars[v]));
714 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
717 double contrast_value = 0.0;
718 double coef_msq = 0.0;
719 struct group_proc *grp_data = &vars[v]->p.grp_data ;
720 struct hsh_table *group_hash = grp_data->group_hash;
721 struct hsh_iterator g;
722 struct group_statistics *gs;
725 double std_error_contrast ;
730 /* Note: The calculation of the degrees of freedom in the variances
731 not equal case is painfull!!
732 The following formula may help to understand it:
733 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
736 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
741 double df_denominator = 0.0;
742 double df_numerator = 0.0;
747 tab_text (t, 1, (v * lines_per_variable) + i + 1,
748 TAB_LEFT | TAT_TITLE,
749 _("Assume equal variances"));
751 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
752 TAB_LEFT | TAT_TITLE,
753 _("Does not assume equal"));
756 tab_text (t, 2, (v * lines_per_variable) + i + 1,
757 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
760 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
761 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
764 if ( bad_contrast[i])
767 /* FIXME: Potential danger here.
768 We're ASSUMING THE array is in the order corresponding to the
770 for (ci = 0, gs = hsh_first (group_hash,&g);
772 ++ci, gs = hsh_next(group_hash,&g))
775 const double coef = subc_list_double_at(&cmd.dl_contrast[i],ci);
776 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
778 contrast_value += coef * gs->mean;
780 coef_msq += (coef * coef) / gs->n ;
782 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
784 df_numerator += (coef * coef) * winv;
785 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
788 sec_vneq = sqrt(sec_vneq);
790 df_numerator = pow2(df_numerator);
792 tab_float (t, 3, (v * lines_per_variable) + i + 1,
793 TAB_RIGHT, contrast_value, 8,2);
795 tab_float (t, 3, (v * lines_per_variable) + i + 1 +
797 TAB_RIGHT, contrast_value, 8,2);
799 std_error_contrast = sqrt(vars[v]->p.grp_data.mse * coef_msq);
802 tab_float (t, 4, (v * lines_per_variable) + i + 1,
803 TAB_RIGHT, std_error_contrast,
806 T = fabs(contrast_value / std_error_contrast) ;
810 tab_float (t, 5, (v * lines_per_variable) + i + 1,
814 df = grp_data->ugs.n - grp_data->n_groups;
816 /* Degrees of Freedom */
817 tab_float (t, 6, (v * lines_per_variable) + i + 1,
822 /* Significance TWO TAILED !!*/
823 tab_float (t, 7, (v * lines_per_variable) + i + 1,
824 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
828 /* Now for the Variances NOT Equal case */
832 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
837 T = contrast_value / sec_vneq;
839 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
844 df = df_numerator / df_denominator;
847 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
851 /* The Significance */
853 tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
854 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
861 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
869 /* ONEWAY ANOVA Calculations */
871 static void postcalc ( struct cmd_oneway *cmd UNUSED );
873 static void precalc ( struct cmd_oneway *cmd UNUSED );
877 /* Pre calculations */
879 precalc ( struct cmd_oneway *cmd UNUSED )
883 for(i=0; i< n_vars ; ++i)
885 struct group_statistics *totals = &vars[i]->p.grp_data.ugs;
887 /* Create a hash for each of the dependent variables.
888 The hash contains a group_statistics structure,
889 and is keyed by value of the independent variable */
891 vars[i]->p.grp_data.group_hash =
893 (hsh_compare_func *) compare_group,
894 (hsh_hash_func *) hash_group,
895 (hsh_free_func *) free_group,
896 (void *) indep_var->width );
903 totals->maximum = - DBL_MAX;
904 totals->minimum = DBL_MAX;
910 run_oneway(const struct casefile *cf, void *cmd_)
912 struct casereader *r;
915 struct cmd_oneway *cmd = (struct cmd_oneway *) cmd_;
917 global_group_hash = hsh_create(4,
918 (hsh_compare_func *) compare_values,
919 (hsh_hash_func *) hash_value,
921 (void *) indep_var->width );
924 for(r = casefile_get_reader (cf);
925 casereader_read (r, &c) ;
930 const double weight =
931 dict_get_case_weight(default_dict,&c,&bad_weight_warn);
933 const union value *indep_val = case_data (&c, indep_var->fv);
935 /* Deal with missing values */
936 if ( value_is_missing(indep_val,indep_var) )
939 /* Skip the entire case if /MISSING=LISTWISE is set */
940 if ( cmd->miss == ONEWAY_LISTWISE )
942 for(i = 0; i < n_vars ; ++i)
944 const struct variable *v = vars[i];
945 const union value *val = case_data (&c, v->fv);
947 if (value_is_missing(val,v) )
956 hsh_insert ( global_group_hash, (void *) indep_val );
958 for ( i = 0 ; i < n_vars ; ++i )
960 const struct variable *v = vars[i];
962 const union value *val = case_data (&c, v->fv);
964 struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash;
966 struct group_statistics *gs;
968 gs = hsh_find(group_hash, (void *) indep_val );
972 gs = (struct group_statistics *)
973 xmalloc (sizeof(struct group_statistics));
980 gs->minimum = DBL_MAX;
981 gs->maximum = -DBL_MAX;
983 hsh_insert ( group_hash, (void *) gs );
986 if (! value_is_missing(val,v) )
988 struct group_statistics *totals = &vars[i]->p.grp_data.ugs;
991 totals->sum+=weight * val->f;
992 totals->ssq+=weight * val->f * val->f;
994 if ( val->f * weight < totals->minimum )
995 totals->minimum = val->f * weight;
997 if ( val->f * weight > totals->maximum )
998 totals->maximum = val->f * weight;
1001 gs->sum+=weight * val->f;
1002 gs->ssq+=weight * val->f * val->f;
1004 if ( val->f * weight < gs->minimum )
1005 gs->minimum = val->f * weight;
1007 if ( val->f * weight > gs->maximum )
1008 gs->maximum = val->f * weight;
1011 vars[i]->p.grp_data.n_groups = hsh_count ( group_hash );
1015 casereader_destroy (r);
1020 if ( stat_tables & STAT_HOMO )
1021 levene(cf, indep_var, n_vars, vars,
1022 (cmd->miss == ONEWAY_LISTWISE) ? LEV_LISTWISE : LEV_ANALYSIS ,
1025 ostensible_number_of_groups = hsh_count (global_group_hash);
1034 /* Post calculations for the ONEWAY command */
1036 postcalc ( struct cmd_oneway *cmd UNUSED )
1041 for(i = 0; i < n_vars ; ++i)
1043 struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash;
1044 struct group_statistics *totals = &vars[i]->p.grp_data.ugs;
1046 struct hsh_iterator g;
1047 struct group_statistics *gs;
1049 for (gs = hsh_first (group_hash,&g);
1051 gs = hsh_next(group_hash,&g))
1053 gs->mean=gs->sum / gs->n;
1054 gs->s_std_dev= sqrt(
1055 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1060 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1063 gs->se_mean = gs->std_dev / sqrt(gs->n);
1064 gs->mean_diff= gs->sum_diff / gs->n;
1070 totals->mean = totals->sum / totals->n;
1071 totals->std_dev= sqrt(
1072 totals->n/(totals->n-1) *
1073 ( (totals->ssq / totals->n ) - totals->mean * totals->mean )
1076 totals->se_mean = totals->std_dev / sqrt(totals->n);