From c87fb686f323f651a1d3f3892c31bf66788916d9 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 30 Oct 2004 01:21:21 +0000 Subject: [PATCH] Fixed a bug in the levene test, and added the levene test to the oneway cmd --- src/ChangeLog | 8 ++++ src/group.h | 8 ---- src/levene.c | 8 ++-- src/oneway.q | 74 +++++++++++++++++++-------------- src/t-test.q | 8 ++-- tests/command/oneway.sh | 91 +++++++++++++++++++++++++++++++++++------ 6 files changed, 137 insertions(+), 60 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 9ae138ff66..3c7527c7c9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +Sat Oct 30 09:16:29 WST 2004 John Darrington + + * levene.c oneway.q Fixed a buglet with the levene statistic and + incorporated the levene test into the oneway command. + + * group.h t-test.q Moved the CMP_EQ and CMP_LE symbols out of + global scope, since they're only relevant to T-TEST + Fri Oct 29 17:39:03 WST 2004 John Darrington * group.c group.h group_proc.h levene.c oneway.q t-test.q diff --git a/src/group.h b/src/group.h index c9050604bc..9845235742 100644 --- a/src/group.h +++ b/src/group.h @@ -18,7 +18,6 @@ 02111-1307, USA. */ - #ifndef GROUP_H #define GROUP_H @@ -26,13 +25,6 @@ #include "val.h" -enum comparison - { - CMP_LE = -2, - CMP_EQ = 0, - }; - - /* Statistics for grouped data */ struct group_statistics { diff --git a/src/levene.c b/src/levene.c index 4659f199ac..e29e77629c 100644 --- a/src/levene.c +++ b/src/levene.c @@ -232,8 +232,8 @@ levene_postcalc (void *_l) for (v = 0; v < l->n_dep; ++v) { + /* This is Z_LL */ lz[v].grand_mean = lz[v].grand_total / lz[v].total_n ; - } } @@ -344,17 +344,15 @@ levene2_postcalc (void *_l) g != 0 ; g = (struct group_statistics *) hsh_next(hash,&hi) ) { - lz_numerator += g->n * pow2(g->lz_mean - lz[v].grand_mean ); - - } lz_numerator *= ( l->v_dep[v]->p.grp_data.ugs.n - l->v_dep[v]->p.grp_data.n_groups ); - lz_denominator[v] /= (l->v_dep[v]->p.grp_data.n_groups - 1); + lz_denominator[v] *= (l->v_dep[v]->p.grp_data.n_groups - 1); l->v_dep[v]->p.grp_data.levene = lz_numerator/lz_denominator[v] ; + } /* Now clear up after ourselves */ diff --git a/src/oneway.q b/src/oneway.q index 7477a3f065..185a96303a 100644 --- a/src/oneway.q +++ b/src/oneway.q @@ -95,6 +95,10 @@ static void show_contrast_coeffs(void); static void show_contrast_tests(void); +enum stat_table_t {STAT_DESC, STAT_HOMO}; + +static enum stat_table_t stat_tables ; + int cmd_oneway(void) @@ -110,6 +114,25 @@ cmd_oneway(void) else value_is_missing = is_missing; + /* What statistics were requested */ + if ( cmd.sbc_statistics ) + { + + for (i = 0 ; i < ONEWAY_ST_count ; ++i ) + { + if ( ! cmd.a_statistics[i] ) continue; + + switch (i) { + case ONEWAY_ST_DESCRIPTIVES: + stat_tables |= STAT_DESC; + break; + case ONEWAY_ST_HOMOGENEITY: + stat_tables |= STAT_HOMO; + break; + } + } + } + multipass_procedure_with_splits (calculate, &cmd); /* Check the sanity of the given contrast values */ @@ -133,26 +156,11 @@ cmd_oneway(void) msg(SW,_("Coefficients for contrast %d do not total zero"),i + 1); } + if ( stat_tables & STAT_DESC ) + show_descriptives(); - - /* Show the statistics tables */ - if ( cmd.sbc_statistics ) - { - for (i = 0 ; i < ONEWAY_ST_count ; ++i ) - { - if ( ! cmd.a_statistics[i] ) continue; - - switch (i) { - case ONEWAY_ST_DESCRIPTIVES: - show_descriptives(); - break; - case ONEWAY_ST_HOMOGENEITY: - show_homogeneity(); - break; - } - } - } - + if ( stat_tables & STAT_HOMO ) + show_homogeneity(); show_anova_table(); @@ -526,19 +534,23 @@ show_homogeneity(void) for ( v=0 ; v < n_vars ; ++v ) { - char *s = (vars[v]->label) ? vars[v]->label : vars[v]->name; - struct group_statistics *totals = &vars[v]->p.grp_data.ugs; - - const double df1 = vars[v]->p.grp_data.n_groups - 1; - const double df2 = totals->n - vars[v]->p.grp_data.n_groups ; + double F; + const struct variable *var = vars[v]; + const char *s = (var->label) ? var->label : var->name; + const struct group_statistics *totals = &var->p.grp_data.ugs; + const double df1 = var->p.grp_data.n_groups - 1; + const double df2 = totals->n - var->p.grp_data.n_groups ; tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s); - - + F = var->p.grp_data.levene; + tab_float (t, 1, v + 1, TAB_RIGHT, F, 8,3); tab_float (t, 2, v + 1, TAB_RIGHT, df1 ,8,0); tab_float (t, 3, v + 1, TAB_RIGHT, df2 ,8,0); + + /* Now the significance */ + tab_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3); } tab_submit (t); @@ -884,7 +896,6 @@ calculate(const struct casefile *cf, void *cmd_) struct casereader *r; struct ccase c; - struct cmd_oneway *cmd = (struct cmd_oneway *) cmd_; global_group_hash = hsh_create(4, @@ -893,9 +904,10 @@ calculate(const struct casefile *cf, void *cmd_) 0, (void *) indep_var->width ); - precalc(cmd); + precalc(cmd); + for(r = casefile_get_reader (cf); casereader_read (r, &c) ; @@ -972,9 +984,9 @@ calculate(const struct casefile *cf, void *cmd_) postcalc(cmd); - /* - levene(cf, indep_var, n_vars, vars, LEV_LISTWISE, value_is_missing); - */ + + if ( stat_tables & STAT_HOMO ) + levene(cf, indep_var, n_vars, vars, LEV_LISTWISE, value_is_missing); ostensible_number_of_groups = hsh_count (global_group_hash); diff --git a/src/t-test.q b/src/t-test.q index a991f29ed6..44dd502ee7 100644 --- a/src/t-test.q +++ b/src/t-test.q @@ -66,9 +66,11 @@ static is_missing_func value_is_missing; /* Variable for the GROUPS subcommand, if given. */ static struct variable *indep_var; -/* GROUPS: Number of values specified by the user; the values - specified if any. */ - +enum comparison + { + CMP_LE = -2, + CMP_EQ = 0, + }; struct group_properties { diff --git a/tests/command/oneway.sh b/tests/command/oneway.sh index 193ab64774..f647e4e0bb 100755 --- a/tests/command/oneway.sh +++ b/tests/command/oneway.sh @@ -47,19 +47,36 @@ cd $TEMPDIR activity="create program" cat > $TEMPDIR/out.stat <