X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Ffriedman.c;h=55e42489f4e3a420790c7184c432b1968d5f17af;hb=f5711a3a6d3f28e53513269e774bfa1e8274c1c5;hp=9950543f706c3c3ef16fedc179881b0767d87670;hpb=036ae30df61b1c998e1aa027863ac2349a67066b;p=pspp diff --git a/src/language/stats/friedman.c b/src/language/stats/friedman.c index 9950543f70..55e42489f4 100644 --- a/src/language/stats/friedman.c +++ b/src/language/stats/friedman.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. -*-c-*- - Copyright (C) 2010 Free Software Foundation, Inc. + Copyright (C) 2010, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,22 +17,22 @@ #include -#include "friedman.h" +#include "language/stats/friedman.h" #include #include -#include - -#include -#include -#include -#include -#include -#include - +#include "data/casereader.h" +#include "data/dataset.h" +#include "data/dictionary.h" +#include "data/format.h" +#include "data/variable.h" +#include "libpspp/message.h" +#include "libpspp/misc.h" +#include "output/pivot-table.h" #include "gettext.h" +#define N_(msgid) msgid #define _(msgid) gettext (msgid) @@ -45,7 +45,7 @@ struct friedman const struct dictionary *dict; }; -static void show_ranks_box (const struct one_sample_test *ost, +static void show_ranks_box (const struct one_sample_test *ost, const struct friedman *fr); static void show_sig_box (const struct one_sample_test *ost, @@ -65,7 +65,7 @@ cmp_x (const void *a_, const void *b_) if (a->x < b->x) return -1; - + return (a->x > b->x); } @@ -77,7 +77,7 @@ cmp_posn (const void *a_, const void *b_) if (a->posn < b->posn) return -1; - + return (a->posn > b->posn); } @@ -100,8 +100,8 @@ friedman_execute (const struct dataset *ds, struct friedman_test *ft = UP_CAST (ost, struct friedman_test, parent); bool warn = true; - double sigma_t = 0.0; - struct datum *row = xcalloc (ost->n_vars, sizeof *row); + double sigma_t = 0.0; + struct datum *row = XCALLOC (ost->n_vars, struct datum); double rsq; struct friedman fr; fr.rank_sum = xcalloc (ost->n_vars, sizeof *fr.rank_sum); @@ -123,7 +123,7 @@ friedman_execute (const struct dataset *ds, double prev_x = SYSMIS; int run_length = 0; - const double w = weight ? case_data (c, weight)->f: 1.0; + const double w = weight ? case_num (c, weight) : 1.0; fr.cc += w; @@ -139,7 +139,7 @@ friedman_execute (const struct dataset *ds, { double x = row[v].x; /* Replace value by the Rank */ - if ( prev_x == x) + if (prev_x == x) { /* Deal with ties */ int i; @@ -155,7 +155,7 @@ friedman_execute (const struct dataset *ds, else { row[v].x = v + 1; - if ( run_length > 0) + if (run_length > 0) { double t = run_length + 1; sigma_t += w * (pow3 (t) - t); @@ -164,10 +164,10 @@ friedman_execute (const struct dataset *ds, } prev_x = x; } - if ( run_length > 0) + if (run_length > 0) { double t = run_length + 1; - sigma_t += w * (pow3 (t) - t ); + sigma_t += w * (pow3 (t) - t); } qsort (row, ost->n_vars, sizeof *row, cmp_posn); @@ -186,14 +186,14 @@ friedman_execute (const struct dataset *ds, rsq = numerator; - numerator *= 12.0 / (fr.cc * ost->n_vars * ( ost->n_vars + 1)); - numerator -= 3 * fr.cc * ( ost->n_vars + 1); + numerator *= 12.0 / (fr.cc * ost->n_vars * (ost->n_vars + 1)); + numerator -= 3 * fr.cc * (ost->n_vars + 1); - denominator = 1 - sigma_t / ( fr.cc * ost->n_vars * ( pow2 (ost->n_vars) - 1)); + denominator = 1 - sigma_t / (fr.cc * ost->n_vars * (pow2 (ost->n_vars) - 1)); fr.chi_sq = numerator / denominator; - if ( ft->kendalls_w) + if (ft->kendalls_w) { fr.w = 12 * rsq ; fr.w -= 3 * pow2 (fr.cc) * @@ -213,45 +213,28 @@ friedman_execute (const struct dataset *ds, -#include static void show_ranks_box (const struct one_sample_test *ost, const struct friedman *fr) { - int i; - const int row_headers = 1; - const int column_headers = 1; - struct tab_table *table = - tab_create (row_headers + 1, column_headers + ost->n_vars); - - tab_headers (table, row_headers, 0, column_headers, 0); + struct pivot_table *table = pivot_table_create (N_("Ranks")); - tab_title (table, _("Ranks")); + pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Mean Rank"), + N_("Mean Rank"), PIVOT_RC_OTHER); - /* Vertical lines inside the box */ - tab_box (table, 1, 0, -1, TAL_1, - row_headers, 0, tab_nc (table) - 1, tab_nr (table) - 1 ); + struct pivot_dimension *variables = pivot_dimension_create ( + table, PIVOT_AXIS_ROW, N_("Variable")); - /* Box around the table */ - tab_box (table, TAL_2, TAL_2, -1, -1, - 0, 0, tab_nc (table) - 1, tab_nr (table) - 1 ); - - - tab_text (table, 1, 0, 0, _("Mean Rank")); - - tab_hline (table, TAL_2, 0, tab_nc (table) - 1, column_headers); - tab_vline (table, TAL_2, row_headers, 0, tab_nr (table) - 1); - - for (i = 0 ; i < ost->n_vars ; ++i) + for (size_t i = 0 ; i < ost->n_vars ; ++i) { - tab_text (table, 0, row_headers + i, - TAB_LEFT, var_to_string (ost->vars[i])); + int row = pivot_category_create_leaf ( + variables->root, pivot_value_new_variable (ost->vars[i])); - tab_double (table, 1, row_headers + i, - 0, fr->rank_sum[i] / fr->cc, 0); + pivot_table_put2 (table, 0, row, + pivot_value_new_number (fr->rank_sum[i] / fr->cc)); } - tab_submit (table); + pivot_table_submit (table); } @@ -259,61 +242,34 @@ static void show_sig_box (const struct one_sample_test *ost, const struct friedman *fr) { const struct friedman_test *ft = UP_CAST (ost, const struct friedman_test, parent); - - int row = 0; - const struct variable *weight = dict_get_weight (fr->dict); - const struct fmt_spec *wfmt = weight ? var_get_print_format (weight) : &F_8_0; - - const int row_headers = 1; - const int column_headers = 0; - struct tab_table *table = - tab_create (row_headers + 1, column_headers + (ft->kendalls_w ? 5 : 4)); - tab_headers (table, row_headers, 0, column_headers, 0); - - tab_title (table, _("Test Statistics")); - - tab_text (table, 0, column_headers + row++, - TAT_TITLE | TAB_LEFT , _("N")); - - if ( ft->kendalls_w) - tab_text (table, 0, column_headers + row++, - TAT_TITLE | TAB_LEFT , _("Kendall's W")); - - tab_text (table, 0, column_headers + row++, - TAT_TITLE | TAB_LEFT , _("Chi-Square")); - - tab_text (table, 0, column_headers + row++, - TAT_TITLE | TAB_LEFT, _("df")); - - tab_text (table, 0, column_headers + row++, - TAT_TITLE | TAB_LEFT, _("Asymp. Sig.")); - - /* Box around the table */ - tab_box (table, TAL_2, TAL_2, -1, -1, - 0, 0, tab_nc (table) - 1, tab_nr (table) - 1 ); - - - tab_hline (table, TAL_2, 0, tab_nc (table) -1, column_headers); - tab_vline (table, TAL_2, row_headers, 0, tab_nr (table) - 1); - - row = 0; - tab_double (table, 1, column_headers + row++, - 0, fr->cc, wfmt); + struct pivot_table *table = pivot_table_create (N_("Test Statistics")); + pivot_table_set_weight_var (table, dict_get_weight (fr->dict)); + struct pivot_dimension *statistics = pivot_dimension_create ( + table, PIVOT_AXIS_ROW, N_("Statistics"), + N_("N"), PIVOT_RC_COUNT); if (ft->kendalls_w) - tab_double (table, 1, column_headers + row++, - 0, fr->w, 0); + pivot_category_create_leaves (statistics->root, N_("Kendall's W"), + PIVOT_RC_OTHER); + pivot_category_create_leaves (statistics->root, + N_("Chi-Square"), PIVOT_RC_OTHER, + N_("df"), PIVOT_RC_INTEGER, + N_("Asymp. Sig."), PIVOT_RC_SIGNIFICANCE); - tab_double (table, 1, column_headers + row++, - 0, fr->chi_sq, 0); + double entries[5]; + int n = 0; - tab_double (table, 1, column_headers + row++, - 0, ost->n_vars - 1, &F_8_0); + entries[n++] = fr->cc; + if (ft->kendalls_w) + entries[n++] = fr->w; + entries[n++] = fr->chi_sq; + entries[n++] = ost->n_vars - 1; + entries[n++] = gsl_cdf_chisq_Q (fr->chi_sq, ost->n_vars - 1); + assert (n <= sizeof entries / sizeof *entries); - tab_double (table, 1, column_headers + row++, - 0, gsl_cdf_chisq_Q (fr->chi_sq, ost->n_vars - 1), - 0); + for (size_t i = 0; i < n; i++) + pivot_table_put1 (table, i, pivot_value_new_number (entries[i])); - tab_submit (table); + pivot_table_submit (table); }