X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Foneway.c;h=e210bc4772214912ef0341e28a2a0820d1ef00c2;hb=5424322a9f6fc37dfb09760c779a63460ecf7eb5;hp=c9ae255ad7508160e59d69d1a55e23fb070b5571;hpb=0d323042aa7503f67186c88a5d41d1517ba9926c;p=pspp diff --git a/src/language/stats/oneway.c b/src/language/stats/oneway.c index c9ae255ad7..e210bc4772 100644 --- a/src/language/stats/oneway.c +++ b/src/language/stats/oneway.c @@ -131,7 +131,7 @@ struct oneway_workspace /* Routines to show the output tables */ static void show_anova_table (const struct oneway_spec *, const struct oneway_workspace *); static void show_descriptives (const struct oneway_spec *); -static void show_homogeneity (const struct oneway_spec *); +static void show_homogeneity (const struct oneway_spec *, const struct oneway_workspace *); static void output_oneway (const struct oneway_spec *, struct oneway_workspace *ws); static void run_oneway (const struct oneway_spec *cmd, struct casereader *input, const struct dataset *ds); @@ -325,10 +325,14 @@ run_oneway (const struct oneway_spec *cmd, ws.vws = xmalloc (cmd->n_vars * sizeof (*ws.vws)); + for (v = 0; v < cmd->n_vars; ++v) { + struct categoricals *cats = categoricals_create (&cmd->indep_var, 1, + cmd->wv, cmd->exclude); + ws.vws[v].cov = covariance_2pass_create (1, &cmd->vars[v], - 1, &cmd->indep_var, + cats, cmd->wv, cmd->exclude); ws.vws[v].cc = 0; } @@ -553,8 +557,8 @@ postcalc (const struct oneway_spec *cmd) } } -static void show_contrast_coeffs (const struct oneway_spec *cmd, struct oneway_workspace *ws); -static void show_contrast_tests (const struct oneway_spec *cmd, struct oneway_workspace *ws); +static void show_contrast_coeffs (const struct oneway_spec *cmd, const struct oneway_workspace *ws); +static void show_contrast_tests (const struct oneway_spec *cmd, const struct oneway_workspace *ws); static void output_oneway (const struct oneway_spec *cmd, struct oneway_workspace *ws) @@ -589,7 +593,7 @@ output_oneway (const struct oneway_spec *cmd, struct oneway_workspace *ws) show_descriptives (cmd); if (cmd->stats & STATS_HOMOGENEITY) - show_homogeneity (cmd); + show_homogeneity (cmd, ws); show_anova_table (cmd, ws); @@ -850,7 +854,7 @@ show_descriptives (const struct oneway_spec *cmd) /* Show the homogeneity table */ static void -show_homogeneity (const struct oneway_spec *cmd) +show_homogeneity (const struct oneway_spec *cmd, const struct oneway_workspace *ws) { size_t v; int n_cols = 5; @@ -874,7 +878,6 @@ show_homogeneity (const struct oneway_spec *cmd) tab_hline (t, TAL_2, 0, n_cols - 1, 1); tab_vline (t, TAL_2, 1, 0, n_rows - 1); - tab_text (t, 1, 0, TAB_CENTER | TAT_TITLE, _("Levene Statistic")); tab_text (t, 2, 0, TAB_CENTER | TAT_TITLE, _("df1")); tab_text (t, 3, 0, TAB_CENTER | TAT_TITLE, _("df2")); @@ -884,24 +887,26 @@ show_homogeneity (const struct oneway_spec *cmd) for (v = 0; v < cmd->n_vars; ++v) { - double F; + const struct per_var_ws *pvw = &ws->vws[v]; + const struct categoricals *cats = covariance_get_categoricals (pvw->cov); + const struct variable *var = cmd->vars[v]; const struct group_proc *gp = group_proc_get (cmd->vars[v]); const char *s = var_to_string (var); - const struct group_statistics *totals = &gp->ugs; - const double df1 = gp->n_groups - 1; - const double df2 = totals->n - gp->n_groups; + const double df1 = pvw->n_groups - 1; + const double df2 = pvw->cc - pvw->n_groups; + double F = gp->levene; tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s); - F = gp->levene; + tab_double (t, 1, v + 1, TAB_RIGHT, F, NULL); tab_fixed (t, 2, v + 1, TAB_RIGHT, df1, 8, 0); tab_fixed (t, 3, v + 1, TAB_RIGHT, df2, 8, 0); /* Now the significance */ - tab_double (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q (F, df1, df2), NULL); + tab_double (t, 4, v + 1, TAB_RIGHT, gsl_cdf_fdist_Q (F, df1, df2), NULL); } tab_submit (t); @@ -910,7 +915,7 @@ show_homogeneity (const struct oneway_spec *cmd) /* Show the contrast coefficients table */ static void -show_contrast_coeffs (const struct oneway_spec *cmd, struct oneway_workspace *ws) +show_contrast_coeffs (const struct oneway_spec *cmd, const struct oneway_workspace *ws) { int c_num = 0; struct ll *cli; @@ -919,10 +924,10 @@ show_contrast_coeffs (const struct oneway_spec *cmd, struct oneway_workspace *ws int n_cols = 2 + ws->actual_number_of_groups; int n_rows = 2 + n_contrasts; - void *const *group_values; - struct tab_table *t; + const struct covariance *cov = ws->vws[0].cov ; + t = tab_create (n_cols, n_rows); tab_headers (t, 2, 0, 2, 0); @@ -958,31 +963,27 @@ show_contrast_coeffs (const struct oneway_spec *cmd, struct oneway_workspace *ws tab_joint_text (t, 2, 0, n_cols - 1, 0, TAB_CENTER | TAT_TITLE, var_to_string (cmd->indep_var)); - group_values = hsh_sort (ws->group_hash); - for ( cli = ll_head (&cmd->contrast_list); cli != ll_null (&cmd->contrast_list); cli = ll_next (cli)) { int count = 0; struct contrasts_node *cn = ll_data (cli, struct contrasts_node, ll); - struct ll *coeffi = ll_head (&cn->coefficient_list); + struct ll *coeffi ; tab_text_format (t, 1, c_num + 2, TAB_CENTER, "%d", c_num + 1); - for (count = 0; - count < hsh_count (ws->group_hash) && coeffi != ll_null (&cn->coefficient_list); - ++count) + for (coeffi = ll_head (&cn->coefficient_list); + coeffi != ll_null (&cn->coefficient_list); + ++count, coeffi = ll_next (coeffi)) { - double *group_value_p; - union value group_value; + const struct categoricals *cats = covariance_get_categoricals (cov); + const union value *val = categoricals_get_value_by_subscript (cats, count); struct string vstr; ds_init_empty (&vstr); - group_value_p = group_values[count]; - group_value.f = *group_value_p; - var_append_value_name (cmd->indep_var, &group_value, &vstr); + var_append_value_name (cmd->indep_var, val, &vstr); tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE, ds_cstr (&vstr)); @@ -996,8 +997,6 @@ show_contrast_coeffs (const struct oneway_spec *cmd, struct oneway_workspace *ws tab_text_format (t, count + 2, c_num + 2, TAB_RIGHT, "%g", coeffn->coeff); } - - coeffi = ll_next (coeffi); } ++c_num; } @@ -1008,7 +1007,7 @@ show_contrast_coeffs (const struct oneway_spec *cmd, struct oneway_workspace *ws /* Show the results of the contrast tests */ static void -show_contrast_tests (const struct oneway_spec *cmd, struct oneway_workspace *ws) +show_contrast_tests (const struct oneway_spec *cmd, const struct oneway_workspace *ws) { int n_contrasts = ll_count (&cmd->contrast_list); size_t v;