X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Fnpar-summary.c;h=e1870f62fd28f962979f79aff4498633feb13606;hb=81579d9e9f994fb2908f50af41c3eb033d216e58;hp=04c83e1a0ed694456d3518e5c9ccad30101a2abb;hpb=8953baa61127d6d3b91f763663ea647bf3e4e793;p=pspp-builds.git diff --git a/src/language/stats/npar-summary.c b/src/language/stats/npar-summary.c index 04c83e1a..e1870f62 100644 --- a/src/language/stats/npar-summary.c +++ b/src/language/stats/npar-summary.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 2006, 2009, 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 @@ -15,16 +15,20 @@ along with this program. If not, see . */ #include -#include -#include -#include -#include -#include "npar-summary.h" -#include -#include -#include + +#include "language/stats/npar-summary.h" + #include -#include + +#include "data/case.h" +#include "data/casereader.h" +#include "data/dictionary.h" +#include "data/format.h" +#include "data/variable.h" +#include "math/moments.h" +#include "output/tab.h" + +#include "gl/minmax.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -35,18 +39,18 @@ npar_summary_calc_descriptives (struct descriptives *desc, struct casereader *input, const struct dictionary *dict, const struct variable *const *vv, - int n_vars UNUSED, + int n_vars, enum mv_class filter) { int i = 0; - while (*vv) + for (i = 0 ; i < n_vars; ++i) { double minimum = DBL_MAX; double maximum = -DBL_MAX; double var; struct moments1 *moments = moments1_create (MOMENT_VARIANCE); struct ccase *c; - const struct variable *v = *vv++; + const struct variable *v = vv[i]; struct casereader *pass; pass = casereader_clone (input); @@ -77,9 +81,8 @@ npar_summary_calc_descriptives (struct descriptives *desc, desc[i].min = minimum; desc[i].max = maximum; - - i++; } + casereader_destroy (input); } @@ -97,20 +100,18 @@ do_summary_box (const struct descriptives *desc, int columns = 1 ; struct tab_table *table ; - if ( desc ) columns += 5; if ( quartiles ) columns += 3; - table = tab_create (columns, 2 + n_vars, 0); + table = tab_create (columns, 2 + n_vars); - tab_dim (table, tab_natural_dimensions); tab_title (table, _("Descriptive Statistics")); tab_headers (table, 1, 0, 1, 0); tab_box (table, TAL_1, TAL_1, -1, TAL_1, - 0, 0, table->nc - 1, tab_nr(table) - 1 ); + 0, 0, tab_nc (table) - 1, tab_nr(table) - 1 ); tab_hline (table, TAL_2, 0, tab_nc (table) -1, 2); tab_vline (table, TAL_2, 1, 0, tab_nr (table) - 1); @@ -152,15 +153,23 @@ do_summary_box (const struct descriptives *desc, col++; } + for ( v = 0 ; v < n_vars ; ++v ) { - tab_text (table, 0, 2 + v, TAT_NONE, var_to_string (vv[v])); - - tab_float (table, 1, 2 + v, TAT_NONE, desc[v].n, 8, 0); - tab_float (table, 2, 2 + v, TAT_NONE, desc[v].mean, 8, 3); - tab_float (table, 3, 2 + v, TAT_NONE, desc[v].std_dev, 8, 3); - tab_float (table, 4, 2 + v, TAT_NONE, desc[v].min, 8, 3); - tab_float (table, 5, 2 + v, TAT_NONE, desc[v].max, 8, 3); + const struct variable *var = vv[v]; + const struct fmt_spec *fmt = var_get_print_format (var); + + tab_text (table, 0, 2 + v, 0, var_to_string (var)); + + col = 1; + if (desc != NULL) + { + tab_double (table, col++, 2 + v, 0, desc[v].n, fmt); + tab_double (table, col++, 2 + v, 0, desc[v].mean, fmt); + tab_double (table, col++, 2 + v, 0, desc[v].std_dev, fmt); + tab_double (table, col++, 2 + v, 0, desc[v].min, fmt); + tab_double (table, col++, 2 + v, 0, desc[v].max, fmt); + } }