X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Foneway.q;h=34f2a216a1cc26571cd72d17c8e388ee4ac564b7;hb=dc44e4b118592d1719d9b9ae23ce64a2861fb198;hp=d10dbb5b6b311f14dbdeb9fbde1b947fb141152d;hpb=9f087e7aa4cdff1d5d46d5e188c0017a9d2d0029;p=pspp-builds.git diff --git a/src/language/stats/oneway.q b/src/language/stats/oneway.q index d10dbb5b..34f2a216 100644 --- a/src/language/stats/oneway.q +++ b/src/language/stats/oneway.q @@ -43,6 +43,7 @@ #include #include #include "sort-criteria.h" +#include #include "xalloc.h" @@ -89,7 +90,7 @@ static void run_oneway (struct cmd_oneway *, struct casereader *, /* Routines to show the output tables */ static void show_anova_table(void); -static void show_descriptives(void); +static void show_descriptives (const struct dictionary *dict); static void show_homogeneity(void); static void show_contrast_coeffs(short *); @@ -100,7 +101,7 @@ enum stat_table_t {STAT_DESC = 1, STAT_HOMO = 2}; static enum stat_table_t stat_tables ; -void output_oneway(void); +static void output_oneway (const struct dictionary *dict); int @@ -147,8 +148,8 @@ cmd_oneway (struct lexer *lexer, struct dataset *ds) } -void -output_oneway(void) +static void +output_oneway (const struct dictionary *dict) { size_t i; short *bad_contrast ; @@ -175,12 +176,11 @@ output_oneway(void) sum += subc_list_double_at(&cmd.dl_contrast[i],j); if ( sum != 0.0 ) - msg(SW,_("Coefficients for contrast %d do not total zero"), - (int) i + 1); + msg(SW,_("Coefficients for contrast %zu do not total zero"), i + 1); } if ( stat_tables & STAT_DESC ) - show_descriptives(); + show_descriptives (dict); if ( stat_tables & STAT_HOMO ) show_homogeneity(); @@ -320,29 +320,29 @@ show_anova_table(void) /* Sums of Squares */ - tab_float (t, 2, i * 3 + 1, 0, ssa, 10, 2); - tab_float (t, 2, i * 3 + 3, 0, sst, 10, 2); - tab_float (t, 2, i * 3 + 2, 0, sst - ssa, 10, 2); + tab_double (t, 2, i * 3 + 1, 0, ssa, NULL); + tab_double (t, 2, i * 3 + 3, 0, sst, NULL); + tab_double (t, 2, i * 3 + 2, 0, sst - ssa, NULL); /* Degrees of freedom */ - tab_float (t, 3, i * 3 + 1, 0, df1, 4, 0); - tab_float (t, 3, i * 3 + 2, 0, df2, 4, 0); - tab_float (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0); + tab_fixed (t, 3, i * 3 + 1, 0, df1, 4, 0); + tab_fixed (t, 3, i * 3 + 2, 0, df2, 4, 0); + tab_fixed (t, 3, i * 3 + 3, 0, totals->n - 1, 4, 0); /* Mean Squares */ - tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3); - tab_float (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, 8, 3); + tab_double (t, 4, i * 3 + 1, TAB_RIGHT, msa, NULL); + tab_double (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, NULL); { - const double F = msa/gp->mse ; + const double F = msa / gp->mse ; /* The F value */ - tab_float (t, 5, i * 3 + 1, 0, F, 8, 3); + tab_double (t, 5, i * 3 + 1, 0, F, NULL); /* The significance */ - tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3); + tab_double (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q (F, df1,df2), NULL); } } @@ -357,16 +357,18 @@ show_anova_table(void) /* Show the descriptives table */ static void -show_descriptives(void) +show_descriptives (const struct dictionary *dict) { size_t v; - int n_cols =10; + int n_cols = 10; struct tab_table *t; int row; - const double confidence=0.95; + const double confidence = 0.95; const double q = (1.0 - confidence) / 2.0; + const struct variable *wv = dict_get_weight (dict); + const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0; int n_rows = 2 ; @@ -420,7 +422,8 @@ show_descriptives(void) struct group_statistics *gs; struct group_statistics *totals = &gp->ugs; - const char *s = var_to_string(vars[v]); + const char *s = var_to_string (vars[v]); + const struct fmt_spec *fmt = var_get_print_format (vars[v]); struct group_statistics *const *gs_array = (struct group_statistics *const *) hsh_sort(gp->group_hash); @@ -430,78 +433,81 @@ show_descriptives(void) if ( v > 0) tab_hline(t, TAL_1, 0, n_cols - 1 , row); - for (count = 0 ; count < hsh_count(gp->group_hash) ; ++count) + for (count = 0; count < hsh_count (gp->group_hash); ++count) { + struct string vstr; + ds_init_empty (&vstr); gs = gs_array[count]; + var_append_value_name (indep_var, &gs->id, &vstr); + tab_text (t, 1, row + count, - TAB_LEFT | TAT_TITLE, var_get_value_name(indep_var, - &gs->id)); + TAB_LEFT | TAT_TITLE, + ds_cstr (&vstr)); + + ds_destroy (&vstr); /* Now fill in the numbers ... */ - tab_float (t, 2, row + count, 0, gs->n, 8,0); + tab_fixed (t, 2, row + count, 0, gs->n, 8, 0); - tab_float (t, 3, row + count, 0, gs->mean,8,2); + tab_double (t, 3, row + count, 0, gs->mean, NULL); - tab_float (t, 4, row + count, 0, gs->std_dev,8,2); + tab_double (t, 4, row + count, 0, gs->std_dev, NULL); - std_error = gs->std_dev/sqrt(gs->n) ; - tab_float (t, 5, row + count, 0, - std_error, 8,2); + std_error = gs->std_dev / sqrt (gs->n) ; + tab_double (t, 5, row + count, 0, + std_error, NULL); /* Now the confidence interval */ - T = gsl_cdf_tdist_Qinv(q,gs->n - 1); + T = gsl_cdf_tdist_Qinv (q, gs->n - 1); - tab_float(t, 6, row + count, 0, - gs->mean - T * std_error, 8, 2); + tab_double (t, 6, row + count, 0, + gs->mean - T * std_error, NULL); - tab_float(t, 7, row + count, 0, - gs->mean + T * std_error, 8, 2); + tab_double (t, 7, row + count, 0, + gs->mean + T * std_error, NULL); /* Min and Max */ - tab_float(t, 8, row + count, 0, gs->minimum, 8, 2); - tab_float(t, 9, row + count, 0, gs->maximum, 8, 2); - + tab_double (t, 8, row + count, 0, gs->minimum, fmt); + tab_double (t, 9, row + count, 0, gs->maximum, fmt); } tab_text (t, 1, row + count, TAB_LEFT | TAT_TITLE ,_("Total")); - tab_float (t, 2, row + count, 0, totals->n, 8,0); + tab_double (t, 2, row + count, 0, totals->n, wfmt); - tab_float (t, 3, row + count, 0, totals->mean, 8,2); + tab_double (t, 3, row + count, 0, totals->mean, NULL); - tab_float (t, 4, row + count, 0, totals->std_dev,8,2); + tab_double (t, 4, row + count, 0, totals->std_dev, NULL); - std_error = totals->std_dev/sqrt(totals->n) ; + std_error = totals->std_dev / sqrt (totals->n) ; - tab_float (t, 5, row + count, 0, std_error, 8,2); + tab_double (t, 5, row + count, 0, std_error, NULL); /* Now the confidence interval */ - T = gsl_cdf_tdist_Qinv(q,totals->n - 1); + T = gsl_cdf_tdist_Qinv (q, totals->n - 1); - tab_float(t, 6, row + count, 0, - totals->mean - T * std_error, 8, 2); + tab_double (t, 6, row + count, 0, + totals->mean - T * std_error, NULL); - tab_float(t, 7, row + count, 0, - totals->mean + T * std_error, 8, 2); + tab_double (t, 7, row + count, 0, + totals->mean + T * std_error, NULL); /* Min and Max */ - tab_float(t, 8, row + count, 0, totals->minimum, 8, 2); - tab_float(t, 9, row + count, 0, totals->maximum, 8, 2); + tab_double (t, 8, row + count, 0, totals->minimum, fmt); + tab_double (t, 9, row + count, 0, totals->maximum, fmt); row += gp->n_groups + 1; } tab_submit (t); - - } /* Show the homogeneity table */ @@ -553,12 +559,12 @@ show_homogeneity(void) tab_text (t, 0, v + 1, TAB_LEFT | TAT_TITLE, s); F = gp->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); + 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_float (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q(F,df1,df2), 8, 3); + tab_double (t, 4, v + 1, TAB_RIGHT,gsl_cdf_fdist_Q (F, df1, df2), NULL); } tab_submit (t); @@ -619,10 +625,18 @@ show_contrast_coeffs (short *bad_contrast) ++count) { int i; + struct string vstr; group_value = group_values[count]; + ds_init_empty (&vstr); + + var_append_value_name (indep_var, group_value, &vstr); + tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE, - var_get_value_name (indep_var, group_value)); + ds_cstr (&vstr)); + + ds_destroy (&vstr); + for (i = 0 ; i < cmd.sbc_contrast ; ++i ) { @@ -761,72 +775,72 @@ show_contrast_tests(short *bad_contrast) } sec_vneq = sqrt(sec_vneq); - df_numerator = pow2(df_numerator); + df_numerator = pow2 (df_numerator); - tab_float (t, 3, (v * lines_per_variable) + i + 1, - TAB_RIGHT, contrast_value, 8,2); + tab_double (t, 3, (v * lines_per_variable) + i + 1, + TAB_RIGHT, contrast_value, NULL); - tab_float (t, 3, (v * lines_per_variable) + i + 1 + + tab_double (t, 3, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast, - TAB_RIGHT, contrast_value, 8,2); + TAB_RIGHT, contrast_value, NULL); - std_error_contrast = sqrt(grp_data->mse * coef_msq); + std_error_contrast = sqrt (grp_data->mse * coef_msq); /* Std. Error */ - tab_float (t, 4, (v * lines_per_variable) + i + 1, + tab_double (t, 4, (v * lines_per_variable) + i + 1, TAB_RIGHT, std_error_contrast, - 8,3); + NULL); T = fabs(contrast_value / std_error_contrast) ; /* T Statistic */ - tab_float (t, 5, (v * lines_per_variable) + i + 1, + tab_double (t, 5, (v * lines_per_variable) + i + 1, TAB_RIGHT, T, - 8,3); + NULL); df = grp_data->ugs.n - grp_data->n_groups; /* Degrees of Freedom */ - tab_float (t, 6, (v * lines_per_variable) + i + 1, + tab_fixed (t, 6, (v * lines_per_variable) + i + 1, TAB_RIGHT, df, - 8,0); + 8, 0); /* Significance TWO TAILED !!*/ - tab_float (t, 7, (v * lines_per_variable) + i + 1, - TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df), - 8,3); + tab_double (t, 7, (v * lines_per_variable) + i + 1, + TAB_RIGHT, 2 * gsl_cdf_tdist_Q (T, df), + NULL); /* Now for the Variances NOT Equal case */ /* Std. Error */ - tab_float (t, 4, + tab_double (t, 4, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast, TAB_RIGHT, sec_vneq, - 8,3); + NULL); T = contrast_value / sec_vneq; - tab_float (t, 5, + tab_double (t, 5, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast, TAB_RIGHT, T, - 8,3); + NULL); df = df_numerator / df_denominator; - tab_float (t, 6, + tab_double (t, 6, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast, TAB_RIGHT, df, - 8,3); + NULL); /* The Significance */ - tab_float (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast, - TAB_RIGHT, 2 * gsl_cdf_tdist_Q(T,df), - 8,3); + tab_double (t, 7, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast, + TAB_RIGHT, 2 * gsl_cdf_tdist_Q (T,df), + NULL); } @@ -836,7 +850,6 @@ show_contrast_tests(short *bad_contrast) } tab_submit (t); - } @@ -1005,7 +1018,8 @@ run_oneway (struct cmd_oneway *cmd, ostensible_number_of_groups = hsh_count (global_group_hash); if (!taint_has_tainted_successor (taint)) - output_oneway(); + output_oneway (dict); + taint_destroy (taint); }