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 = (vars[i]->label) ? vars[i]->label : vars[i]->name;
303 tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s);
304 tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups"));
305 tab_text (t, 1, i * 3 + 2, TAB_LEFT | TAT_TITLE, _("Within Groups"));
306 tab_text (t, 1, i * 3 + 3, TAB_LEFT | TAT_TITLE, _("Total"));
309 tab_hline(t, TAL_1, 0, n_cols - 1 , i * 3 + 1);
312 const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ;
313 const double df1 = vars[i]->p.grp_data.n_groups - 1;
314 const double df2 = totals->n - vars[i]->p.grp_data.n_groups ;
315 const double msa = ssa / df1;
317 vars[i]->p.grp_data.mse = (sst - ssa) / df2;
320 /* Sums of Squares */
321 tab_float (t, 2, i * 3 + 1, 0, ssa, 10, 2);
322 tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2);
323 tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2);
326 /* Degrees of freedom */
327 tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0);
328 tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0);
329 tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0);
332 tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3);
333 tab_float (t, 4, i * 3 + 2, TAB_RIGHT, vars[i]->p.grp_data.mse, 8, 3);
337 const double F = msa/vars[i]->p.grp_data.mse ;
340 tab_float (t, 5, i * 3 + 1, 0, F, 8, 3);
342 /* The significance */
343 tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
351 tab_title (t, 0, _("ANOVA"));
357 /* Show the descriptives table */
359 show_descriptives(void)
366 const double confidence=0.95;
367 const double q = (1.0 - confidence) / 2.0;
374 for ( v = 0 ; v < n_vars ; ++v )
375 n_rows += vars[v]->p.grp_data.n_groups + 1;
377 t = tab_create (n_cols,n_rows,0);
378 tab_headers (t, 2, 0, 2, 0);
379 tab_dim (t, tab_natural_dimensions);
382 /* Put a frame around the entire box, and vertical lines inside */
387 n_cols - 1, n_rows - 1);
389 /* Underline headers */
390 tab_hline (t, TAL_2, 0, n_cols - 1, 2 );
391 tab_vline (t, TAL_2, 2, 0, n_rows - 1);
393 tab_text (t, 2, 1, TAB_CENTER | TAT_TITLE, _("N"));
394 tab_text (t, 3, 1, TAB_CENTER | TAT_TITLE, _("Mean"));
395 tab_text (t, 4, 1, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
396 tab_text (t, 5, 1, TAB_CENTER | TAT_TITLE, _("Std. Error"));
399 tab_vline(t, TAL_0, 7, 0, 0);
400 tab_hline(t, TAL_1, 6, 7, 1);
401 tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF, _("%g%% Confidence Interval for Mean"),confidence*100.0);
403 tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
404 tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
406 tab_text (t, 8, 1, TAB_CENTER | TAT_TITLE, _("Minimum"));
407 tab_text (t, 9, 1, TAB_CENTER | TAT_TITLE, _("Maximum"));
410 tab_title (t, 0, _("Descriptives"));
414 for ( v=0 ; v < n_vars ; ++v )
420 struct hsh_iterator g;
421 struct group_statistics *gs;
422 struct group_statistics *totals = &vars[v]->p.grp_data.ugs;
425 char *s = (vars[v]->label) ? vars[v]->label : vars[v]->name;
427 struct hsh_table *group_hash = vars[v]->p.grp_data.group_hash;
430 tab_text (t, 0, row, TAB_LEFT | TAT_TITLE, s);
432 tab_hline(t, TAL_1, 0, n_cols - 1 , row);
435 for (gs = hsh_first (group_hash,&g);
437 gs = hsh_next(group_hash,&g))
439 const char *s = val_labs_find(indep_var->val_labs, gs->id );
442 tab_text (t, 1, row + count,
443 TAB_LEFT | TAT_TITLE ,s);
444 else if ( indep_var->width != 0 )
445 tab_text (t, 1, row + count,
446 TAB_LEFT | TAT_TITLE, gs->id.s);
448 tab_text (t, 1, row + count,
449 TAB_LEFT | TAT_TITLE | TAT_PRINTF, "%g", gs->id.f);
452 /* Now fill in the numbers ... */
454 tab_float (t, 2, row + count, 0, gs->n, 8,0);
456 tab_float (t, 3, row + count, 0, gs->mean,8,2);
458 tab_float (t, 4, row + count, 0, gs->std_dev,8,2);
460 std_error = gs->std_dev/sqrt(gs->n) ;
461 tab_float (t, 5, row + count, 0,
464 /* Now the confidence interval */
466 T = gsl_cdf_tdist_Qinv(q,gs->n - 1);
468 tab_float(t, 6, row + count, 0,
469 gs->mean - T * std_error, 8, 2);
471 tab_float(t, 7, row + count, 0,
472 gs->mean + T * std_error, 8, 2);
476 tab_float(t, 8, row + count, 0, gs->minimum, 8, 2);
477 tab_float(t, 9, row + count, 0, gs->maximum, 8, 2);
482 tab_text (t, 1, row + count,
483 TAB_LEFT | TAT_TITLE ,_("Total"));
485 tab_float (t, 2, row + count, 0, totals->n, 8,0);
487 tab_float (t, 3, row + count, 0, totals->mean, 8,2);
489 tab_float (t, 4, row + count, 0, totals->std_dev,8,2);
491 std_error = totals->std_dev/sqrt(totals->n) ;
493 tab_float (t, 5, row + count, 0, std_error, 8,2);
495 /* Now the confidence interval */
497 T = gsl_cdf_tdist_Qinv(q,totals->n - 1);
499 tab_float(t, 6, row + count, 0,
500 totals->mean - T * std_error, 8, 2);
502 tab_float(t, 7, row + count, 0,
503 totals->mean + T * std_error, 8, 2);
507 tab_float(t, 8, row + count, 0, totals->minimum, 8, 2);
508 tab_float(t, 9, row + count, 0, totals->maximum, 8, 2);
510 row += vars[v]->p.grp_data.n_groups + 1;
519 /* Show the homogeneity table */
521 show_homogeneity(void)
525 int n_rows = n_vars + 1;
530 t = tab_create (n_cols,n_rows,0);
531 tab_headers (t, 1, 0, 1, 0);
532 tab_dim (t, tab_natural_dimensions);
534 /* Put a frame around the entire box, and vertical lines inside */
539 n_cols - 1, n_rows - 1);
542 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
543 tab_vline(t, TAL_2, 1, 0, n_rows - 1);
546 tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic"));
547 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1"));
548 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2"));
549 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Significance"));
552 tab_title (t, 0, _("Test of Homogeneity of Variances"));
554 for ( v=0 ; v < n_vars ; ++v )
557 const struct variable *var = vars[v];
558 const char *s = (var->label) ? var->label : var->name;
559 const struct group_statistics *totals = &var->p.grp_data.ugs;
561 const double df1 = var->p.grp_data.n_groups - 1;
562 const double df2 = totals->n - var->p.grp_data.n_groups ;
564 tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s);
566 F = var->p.grp_data.levene;
567 tab_float (t, 1, v + 1, TAB_RIGHT, F, 8,3);
568 tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0);
569 tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0);
571 /* Now the significance */
572 tab_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3);
581 /* Show the contrast coefficients table */
583 show_contrast_coeffs(short *bad_contrast)
586 int n_cols = 2 + ostensible_number_of_groups;
587 int n_rows = 2 + cmd.sbc_contrast;
588 struct hsh_iterator g;
589 union value *group_value;
596 t = tab_create (n_cols,n_rows,0);
597 tab_headers (t, 2, 0, 2, 0);
598 tab_dim (t, tab_natural_dimensions);
600 /* Put a frame around the entire box, and vertical lines inside */
605 n_cols - 1, n_rows - 1);
621 tab_hline(t, TAL_1, 2, n_cols - 1, 1);
624 tab_hline(t, TAL_2, 0, n_cols - 1, 2);
625 tab_vline(t, TAL_2, 2, 0, n_rows - 1);
628 tab_title (t, 0, _("Contrast Coefficients"));
630 tab_text (t, 0, 2, TAB_LEFT | TAT_TITLE, _("Contrast"));
632 s = (indep_var->label) ? indep_var->label : indep_var->name;
634 tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE, s);
636 for (group_value = hsh_first (global_group_hash,&g);
638 group_value = hsh_next(global_group_hash,&g))
644 lab = val_labs_find(indep_var->val_labs,*group_value);
647 tab_text (t, count + 2, 1,
648 TAB_CENTER | TAT_TITLE ,lab);
650 tab_text (t, count + 2, 1,
651 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%g", group_value->f);
653 for (i = 0 ; i < cmd.sbc_contrast ; ++i )
656 tab_text(t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
658 if ( bad_contrast[i] )
659 tab_text(t, count + 2, i + 2, TAB_RIGHT, "?" );
661 tab_text(t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
662 subc_list_double_at(&cmd.dl_contrast[i],count)
674 /* Show the results of the contrast tests */
676 show_contrast_tests(short *bad_contrast)
680 int n_rows = 1 + n_vars * 2 * cmd.sbc_contrast;
684 t = tab_create (n_cols,n_rows,0);
685 tab_headers (t, 3, 0, 1, 0);
686 tab_dim (t, tab_natural_dimensions);
688 /* Put a frame around the entire box, and vertical lines inside */
693 n_cols - 1, n_rows - 1);
701 tab_hline(t, TAL_2, 0, n_cols - 1, 1);
702 tab_vline(t, TAL_2, 3, 0, n_rows - 1);
705 tab_title (t, 0, _("Contrast Tests"));
707 tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("Contrast"));
708 tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("Value of Contrast"));
709 tab_text (t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Error"));
710 tab_text (t, 5, 0, TAB_CENTER | TAT_TITLE, _("t"));
711 tab_text (t, 6, 0, TAB_CENTER | TAT_TITLE, _("df"));
712 tab_text (t, 7, 0, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)"));
714 for ( v = 0 ; v < n_vars ; ++v )
717 int lines_per_variable = 2 * cmd.sbc_contrast;
720 tab_text (t, 0, (v * lines_per_variable) + 1, TAB_LEFT | TAT_TITLE,
721 vars[v]->label?vars[v]->label:vars[v]->name);
725 for ( i = 0 ; i < cmd.sbc_contrast ; ++i )
728 double contrast_value = 0.0;
729 double coef_msq = 0.0;
730 struct group_proc *grp_data = &vars[v]->p.grp_data ;
731 struct hsh_table *group_hash = grp_data->group_hash;
732 struct hsh_iterator g;
733 struct group_statistics *gs;
736 double std_error_contrast ;
741 /* Note: The calculation of the degrees of freedom in the variances
742 not equal case is painfull!!
743 The following formula may help to understand it:
744 \frac{\left(\sum_{i=1}^k{c_i^2\frac{s_i^2}{n_i}}\right)^2}
747 \frac{\left(c_i^2\frac{s_i^2}{n_i}\right)^2} {n_i-1}
752 double df_denominator = 0.0;
753 double df_numerator = 0.0;
758 tab_text (t, 1, (v * lines_per_variable) + i + 1,
759 TAB_LEFT | TAT_TITLE,
760 _("Assume equal variances"));
762 tab_text (t, 1, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
763 TAB_LEFT | TAT_TITLE,
764 _("Does not assume equal"));
767 tab_text (t, 2, (v * lines_per_variable) + i + 1,
768 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
771 tab_text (t, 2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
772 TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d",i+1);
775 if ( bad_contrast[i])
778 /* FIXME: Potential danger here.
779 We're ASSUMING THE array is in the order corresponding to the
781 for (ci = 0, gs = hsh_first (group_hash,&g);
783 ++ci, gs = hsh_next(group_hash,&g))
786 const double coef = subc_list_double_at(&cmd.dl_contrast[i],ci);
787 const double winv = (gs->std_dev * gs->std_dev) / gs->n;
789 contrast_value += coef * gs->mean;
791 coef_msq += (coef * coef) / gs->n ;
793 sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ;
795 df_numerator += (coef * coef) * winv;
796 df_denominator += pow2((coef * coef) * winv) / (gs->n - 1);
799 sec_vneq = sqrt(sec_vneq);
801 df_numerator = pow2(df_numerator);
803 tab_float (t, 3, (v * lines_per_variable) + i + 1,
804 TAB_RIGHT, contrast_value, 8,2);
806 tab_float (t, 3, (v * lines_per_variable) + i + 1 +
808 TAB_RIGHT, contrast_value, 8,2);
810 std_error_contrast = sqrt(vars[v]->p.grp_data.mse * coef_msq);
813 tab_float (t, 4, (v * lines_per_variable) + i + 1,
814 TAB_RIGHT, std_error_contrast,
817 T = fabs(contrast_value / std_error_contrast) ;
821 tab_float (t, 5, (v * lines_per_variable) + i + 1,
825 df = grp_data->ugs.n - grp_data->n_groups;
827 /* Degrees of Freedom */
828 tab_float (t, 6, (v * lines_per_variable) + i + 1,
833 /* Significance TWO TAILED !!*/
834 tab_float (t, 7, (v * lines_per_variable) + i + 1,
835 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
839 /* Now for the Variances NOT Equal case */
843 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
848 T = contrast_value / sec_vneq;
850 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
855 df = df_numerator / df_denominator;
858 (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
862 /* The Significance */
864 tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
865 TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df),
872 tab_hline(t, TAL_1, 0, n_cols - 1, (v * lines_per_variable) + 1);
880 /* ONEWAY ANOVA Calculations */
882 static void postcalc ( struct cmd_oneway *cmd UNUSED );
884 static void precalc ( struct cmd_oneway *cmd UNUSED );
888 /* Pre calculations */
890 precalc ( struct cmd_oneway *cmd UNUSED )
894 for(i=0; i< n_vars ; ++i)
896 struct group_statistics *totals = &vars[i]->p.grp_data.ugs;
898 /* Create a hash for each of the dependent variables.
899 The hash contains a group_statistics structure,
900 and is keyed by value of the independent variable */
902 vars[i]->p.grp_data.group_hash =
904 (hsh_compare_func *) compare_group,
905 (hsh_hash_func *) hash_group,
906 (hsh_free_func *) free_group,
907 (void *) indep_var->width );
914 totals->maximum = - DBL_MAX;
915 totals->minimum = DBL_MAX;
921 run_oneway(const struct casefile *cf, void *cmd_)
923 struct casereader *r;
926 struct cmd_oneway *cmd = (struct cmd_oneway *) cmd_;
928 global_group_hash = hsh_create(4,
929 (hsh_compare_func *) compare_values,
930 (hsh_hash_func *) hash_value,
932 (void *) indep_var->width );
935 for(r = casefile_get_reader (cf);
936 casereader_read (r, &c) ;
941 const double weight =
942 dict_get_case_weight(default_dict,&c,&bad_weight_warn);
944 const union value *indep_val = case_data (&c, indep_var->fv);
946 /* Deal with missing values */
947 if ( value_is_missing(indep_val,indep_var) )
950 /* Skip the entire case if /MISSING=LISTWISE is set */
951 if ( cmd->miss == ONEWAY_LISTWISE )
953 for(i = 0; i < n_vars ; ++i)
955 const struct variable *v = vars[i];
956 const union value *val = case_data (&c, v->fv);
958 if (value_is_missing(val,v) )
967 hsh_insert ( global_group_hash, (void *) indep_val );
969 for ( i = 0 ; i < n_vars ; ++i )
971 const struct variable *v = vars[i];
973 const union value *val = case_data (&c, v->fv);
975 struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash;
977 struct group_statistics *gs;
979 gs = hsh_find(group_hash, (void *) indep_val );
983 gs = (struct group_statistics *)
984 xmalloc (sizeof(struct group_statistics));
991 gs->minimum = DBL_MAX;
992 gs->maximum = -DBL_MAX;
994 hsh_insert ( group_hash, (void *) gs );
997 if (! value_is_missing(val,v) )
999 struct group_statistics *totals = &vars[i]->p.grp_data.ugs;
1002 totals->sum+=weight * val->f;
1003 totals->ssq+=weight * val->f * val->f;
1005 if ( val->f * weight < totals->minimum )
1006 totals->minimum = val->f * weight;
1008 if ( val->f * weight > totals->maximum )
1009 totals->maximum = val->f * weight;
1012 gs->sum+=weight * val->f;
1013 gs->ssq+=weight * val->f * val->f;
1015 if ( val->f * weight < gs->minimum )
1016 gs->minimum = val->f * weight;
1018 if ( val->f * weight > gs->maximum )
1019 gs->maximum = val->f * weight;
1022 vars[i]->p.grp_data.n_groups = hsh_count ( group_hash );
1026 casereader_destroy (r);
1031 if ( stat_tables & STAT_HOMO )
1032 levene(cf, indep_var, n_vars, vars,
1033 (cmd->miss == ONEWAY_LISTWISE) ? LEV_LISTWISE : LEV_ANALYSIS ,
1036 ostensible_number_of_groups = hsh_count (global_group_hash);
1045 /* Post calculations for the ONEWAY command */
1047 postcalc ( struct cmd_oneway *cmd UNUSED )
1052 for(i = 0; i < n_vars ; ++i)
1054 struct hsh_table *group_hash = vars[i]->p.grp_data.group_hash;
1055 struct group_statistics *totals = &vars[i]->p.grp_data.ugs;
1057 struct hsh_iterator g;
1058 struct group_statistics *gs;
1060 for (gs = hsh_first (group_hash,&g);
1062 gs = hsh_next(group_hash,&g))
1064 gs->mean=gs->sum / gs->n;
1065 gs->s_std_dev= sqrt(
1066 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1071 ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
1074 gs->se_mean = gs->std_dev / sqrt(gs->n);
1075 gs->mean_diff= gs->sum_diff / gs->n;
1081 totals->mean = totals->sum / totals->n;
1082 totals->std_dev= sqrt(
1083 totals->n/(totals->n-1) *
1084 ( (totals->ssq / totals->n ) - totals->mean * totals->mean )
1087 totals->se_mean = totals->std_dev / sqrt(totals->n);