X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fcochran.c;h=9b03296f19a730e0d45b0c86754302d4a25894de;hb=604b7adbf9c26922f7a20887b2baf16a3f0acef6;hp=8576f985e215e8030512fc61998593b5bed91167;hpb=81579d9e9f994fb2908f50af41c3eb033d216e58;p=pspp diff --git a/src/language/stats/cochran.c b/src/language/stats/cochran.c index 8576f985e2..9b03296f19 100644 --- a/src/language/stats/cochran.c +++ b/src/language/stats/cochran.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 2010, 2011, 2014 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 @@ -18,22 +18,24 @@ #include "language/stats/cochran.h" +#include #include #include #include "data/casereader.h" +#include "data/dataset.h" #include "data/dictionary.h" #include "data/format.h" -#include "data/procedure.h" #include "data/val-type.h" #include "data/variable.h" #include "language/stats/npar.h" #include "libpspp/cast.h" #include "libpspp/message.h" #include "libpspp/misc.h" -#include "output/tab.h" +#include "output/pivot-table.h" #include "gettext.h" +#define N_(msgid) msgid #define _(msgid) gettext (msgid) struct cochran @@ -78,16 +80,16 @@ cochran_execute (const struct dataset *ds, for (; (c = casereader_read (input)); case_unref (c)) { double case_hits = 0.0; - const double w = weight ? case_data (c, weight)->f: 1.0; + const double w = weight ? case_num (c, weight) : 1.0; for (v = 0; v < ct->n_vars; ++v) { const struct variable *var = ct->vars[v]; const union value *val = case_data (c, var); - if ( var_is_value_missing (var, val, exclude)) + if (var_is_value_missing (var, val) & exclude) continue; - if ( ch.success == SYSMIS) + if (ch.success == SYSMIS) { ch.success = val->f; } @@ -95,12 +97,12 @@ cochran_execute (const struct dataset *ds, { ch.failure = val->f; } - if ( ch.success == val->f) + if (ch.success == val->f) { ch.hits[v] += w; case_hits += w; } - else if ( ch.failure == val->f) + else if (ch.failure == val->f) { ch.misses[v] += w; } @@ -114,7 +116,7 @@ cochran_execute (const struct dataset *ds, rowsq += pow2 (case_hits); } casereader_destroy (input); - + { double c_l = 0; double c_l2 = 0; @@ -129,7 +131,7 @@ cochran_execute (const struct dataset *ds, ch.q *= ct->n_vars - 1; ch.q /= ct->n_vars * c_l - rowsq; - + ch.df = ct->n_vars - 1; } @@ -145,99 +147,53 @@ cochran_execute (const struct dataset *ds, static void show_freqs_box (const struct one_sample_test *ost, const struct cochran *ct) { - int i; - const struct variable *weight = dict_get_weight (ct->dict); - const struct fmt_spec *wfmt = weight ? var_get_print_format (weight) : &F_8_0; - - const int row_headers = 1; - const int column_headers = 2; - struct tab_table *table = - tab_create (row_headers + 2, column_headers + ost->n_vars); - - tab_headers (table, row_headers, 0, column_headers, 0); - - tab_title (table, _("Frequencies")); - - /* Vertical lines inside the box */ - tab_box (table, 1, 0, -1, TAL_1, - row_headers, 0, tab_nc (table) - 1, tab_nr (table) - 1 ); - - /* Box around the table */ - tab_box (table, TAL_2, TAL_2, -1, -1, - 0, 0, tab_nc (table) - 1, tab_nr (table) - 1 ); - - tab_joint_text (table, 1, 0, 2, 0, - TAT_TITLE | TAB_CENTER, _("Value")); - - tab_text_format (table, 1, 1, 0, _("Success (%g)"), ct->success); - tab_text_format (table, 2, 1, 0, _("Failure (%g)"), ct->failure); - - 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) + struct pivot_table *table = pivot_table_create (N_("Frequencies")); + pivot_table_set_weight_var (table, dict_get_weight (ct->dict)); + + char *success = xasprintf (_("Success (%.*g)"), DBL_DIG + 1, ct->success); + char *failure = xasprintf (_("Failure (%.*g)"), DBL_DIG + 1, ct->failure); + struct pivot_dimension *values = pivot_dimension_create ( + table, PIVOT_AXIS_COLUMN, N_("Value"), + success, PIVOT_RC_COUNT, + failure, PIVOT_RC_COUNT); + values->root->show_label = true; + free (failure); + free (success); + + struct pivot_dimension *variables = pivot_dimension_create ( + table, PIVOT_AXIS_ROW, N_("Variable")); + + for (size_t i = 0 ; i < ost->n_vars ; ++i) { - tab_text (table, 0, column_headers + i, - TAB_LEFT, var_to_string (ost->vars[i])); - - tab_double (table, 1, column_headers + i, 0, - ct->hits[i], wfmt); + int row = pivot_category_create_leaf ( + variables->root, pivot_value_new_variable (ost->vars[i])); - tab_double (table, 2, column_headers + i, 0, - ct->misses[i], wfmt); + pivot_table_put2 (table, 0, row, pivot_value_new_number (ct->hits[i])); + pivot_table_put2 (table, 1, row, pivot_value_new_number (ct->misses[i])); } - tab_submit (table); + pivot_table_submit (table); } - - static void show_sig_box (const struct cochran *ch) { - const struct variable *weight = dict_get_weight (ch->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 + 4); - - tab_headers (table, row_headers, 0, column_headers, 0); - - tab_title (table, _("Test Statistics")); - - tab_text (table, 0, column_headers, - TAT_TITLE | TAB_LEFT , _("N")); - - tab_text (table, 0, 1 + column_headers, - TAT_TITLE | TAB_LEFT , _("Cochran's Q")); - - tab_text (table, 0, 2 + column_headers, - TAT_TITLE | TAB_LEFT, _("df")); - - tab_text (table, 0, 3 + column_headers, - 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); - - tab_double (table, 1, column_headers, - 0, ch->cc, wfmt); + struct pivot_table *table = pivot_table_create (N_("Test Statistics")); - tab_double (table, 1, column_headers + 1, - 0, ch->q, 0); + pivot_table_set_weight_format (table, dict_get_weight_format (ch->dict)); - tab_double (table, 1, column_headers + 2, - 0, ch->df, &F_8_0); + pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Value"), N_("Value")); - tab_double (table, 1, column_headers + 3, - 0, gsl_cdf_chisq_Q (ch->q, ch->df), - 0); + pivot_dimension_create ( + table, PIVOT_AXIS_ROW, N_("Statistics"), + N_("N"), PIVOT_RC_COUNT, + N_("Cochran's Q"), PIVOT_RC_SIGNIFICANCE, + N_("df"), PIVOT_RC_INTEGER, + N_("Asymp. Sig."), PIVOT_RC_SIGNIFICANCE); - tab_submit (table); + double sig = gsl_cdf_chisq_Q (ch->q, ch->df); + double entries[] = { ch->cc, ch->q, ch->df, sig }; + for (size_t i = 0; i < sizeof entries / sizeof *entries; i++) + pivot_table_put2 (table, 0, i, pivot_value_new_number (entries[i])); + pivot_table_submit (table); }