X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Ffrequencies.c;h=da1a3828d1d13a2ca4f42768537258b67fc08eff;hb=0011a559f8ba51cddbebeb035d8a02bbd4776bdc;hp=1f8290cf2c696d418b28d3c92a039dfecbd800a7;hpb=171bd1341565bf922cd3361e564d3d02b18c9547;p=pspp diff --git a/src/language/stats/frequencies.c b/src/language/stats/frequencies.c index 1f8290cf2c..da1a3828d1 100644 --- a/src/language/stats/frequencies.c +++ b/src/language/stats/frequencies.c @@ -286,6 +286,7 @@ dump_freq_table (const struct var_freqs *vf, const struct variable *wv) n_categories = ft->n_valid + ft->n_missing; t = tab_create (6, n_categories + 2); + tab_set_format (t, RC_WEIGHT, wfmt); tab_headers (t, 0, 0, 1, 0); for (x = 0; x < 6; x++) @@ -308,10 +309,10 @@ dump_freq_table (const struct var_freqs *vf, const struct variable *wv) tab_text (t, 0, r, TAB_LEFT, label); tab_value (t, 1, r, TAB_NONE, &f->value, vf->var, NULL); - tab_double (t, 2, r, TAB_NONE, f->count, wfmt); - tab_double (t, 3, r, TAB_NONE, percent, NULL); - tab_double (t, 4, r, TAB_NONE, valid_percent, NULL); - tab_double (t, 5, r, TAB_NONE, cum_total, NULL); + tab_double (t, 2, r, TAB_NONE, f->count, NULL, RC_WEIGHT); + tab_double (t, 3, r, TAB_NONE, percent, NULL, RC_OTHER); + tab_double (t, 4, r, TAB_NONE, valid_percent, NULL, RC_OTHER); + tab_double (t, 5, r, TAB_NONE, cum_total, NULL, RC_OTHER); r++; } for (; f < &ft->valid[n_categories]; f++) @@ -325,9 +326,9 @@ dump_freq_table (const struct var_freqs *vf, const struct variable *wv) tab_text (t, 0, r, TAB_LEFT, label); tab_value (t, 1, r, TAB_NONE, &f->value, vf->var, NULL); - tab_double (t, 2, r, TAB_NONE, f->count, wfmt); + tab_double (t, 2, r, TAB_NONE, f->count, NULL, RC_WEIGHT); tab_double (t, 3, r, TAB_NONE, - f->count / ft->total_cases * 100.0, NULL); + f->count / ft->total_cases * 100.0, NULL, RC_OTHER); tab_text (t, 4, r, TAB_NONE, _("Missing")); r++; } @@ -337,9 +338,9 @@ dump_freq_table (const struct var_freqs *vf, const struct variable *wv) tab_hline (t, TAL_2, 0, 5, r); tab_joint_text (t, 0, r, 1, r, TAB_RIGHT | TAT_TITLE, _("Total")); tab_vline (t, TAL_0, 1, r, r); - tab_double (t, 2, r, TAB_NONE, cum_freq, wfmt); - tab_fixed (t, 3, r, TAB_NONE, 100.0, 5, 1); - tab_fixed (t, 4, r, TAB_NONE, 100.0, 5, 1); + tab_double (t, 2, r, TAB_NONE, cum_freq, NULL, RC_WEIGHT); + tab_double (t, 3, r, TAB_NONE, 100.0, &F_5_1, RC_OTHER); + tab_double (t, 4, r, TAB_NONE, 100.0, &F_5_1, RC_OTHER); tab_title (t, "%s", var_to_string (vf->var)); tab_submit (t); @@ -625,6 +626,7 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds) for (i = 0; i < frq.n_vars; ++i) { frq.vars[i].var = vars[i]; + frq.vars[i].width = var_get_width (vars[i]); } while (lex_token (lexer) != T_ENDCMD) @@ -633,10 +635,18 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds) if (lex_match_id (lexer, "STATISTICS")) { - lex_match (lexer, T_EQUALS); - - frq.stats = 0; - frq.n_stats = 0; + frq.stats = BIT_INDEX (FRQ_ST_MEAN) + | BIT_INDEX (FRQ_ST_STDDEV) + | BIT_INDEX (FRQ_ST_MINIMUM) + | BIT_INDEX (FRQ_ST_MAXIMUM); + + frq.n_stats = 4; + + if (lex_match (lexer, T_EQUALS)) + { + frq.n_stats = 0; + frq.stats = 0; + } while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) @@ -889,7 +899,7 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds) hi_pcnt = lex_integer (lexer); if (hi_pcnt <= 0) { - lex_error (lexer, _("Histogram percentaage must be greater than zero.")); + lex_error (lexer, _("Histogram percentage must be greater than zero.")); } lex_get (lexer); lex_force_match (lexer, T_RPAREN); @@ -992,7 +1002,7 @@ cmd_frequencies (struct lexer *lexer, struct dataset *ds) } } - if (frq.stats & FRQ_ST_MEDIAN) + if (frq.stats & BIT_INDEX (FRQ_ST_MEDIAN)) { frq.percentiles = xrealloc (frq.percentiles, @@ -1195,9 +1205,16 @@ freq_tab_to_hist (const struct frq_proc *frq, const struct freq_tab *ft, } } - /* Freedman-Diaconis' choice of bin width. */ + iqr = calculate_iqr (frq); - bin_width = 2 * iqr / pow (valid_freq, 1.0 / 3.0); + + if (iqr > 0) + /* Freedman-Diaconis' choice of bin width. */ + bin_width = 2 * iqr / pow (valid_freq, 1.0 / 3.0); + + else + /* Sturges Rule */ + bin_width = (x_max - x_min) / (1 + log2 (valid_freq)); histogram = histogram_create (bin_width, x_min, x_max); @@ -1355,8 +1372,9 @@ dump_statistics (const struct frq_proc *frq, const struct var_freqs *vf, } calc_stats (vf, stat_value); - t = tab_create (3, ((frq->stats & FRQ_ST_MEDIAN) ? frq->n_stats - 1 : frq->n_stats) + frq->n_show_percentiles + 2); - + t = tab_create (3, ((frq->stats & BIT_INDEX (FRQ_ST_MEDIAN)) ? frq->n_stats - 1 : frq->n_stats) + + frq->n_show_percentiles + 2); + tab_set_format (t, RC_WEIGHT, wfmt); tab_box (t, TAL_1, TAL_1, -1, -1 , 0 , 0 , 2, tab_nr(t) - 1) ; @@ -1374,7 +1392,7 @@ dump_statistics (const struct frq_proc *frq, const struct var_freqs *vf, { tab_text (t, 0, r, TAB_LEFT | TAT_TITLE, gettext (st_name[i])); - tab_double (t, 2, r, TAB_NONE, stat_value[i], NULL); + tab_double (t, 2, r, TAB_NONE, stat_value[i], NULL, RC_OTHER); r++; } } @@ -1383,8 +1401,8 @@ dump_statistics (const struct frq_proc *frq, const struct var_freqs *vf, tab_text (t, 1, 0, TAB_LEFT | TAT_TITLE, _("Valid")); tab_text (t, 1, 1, TAB_LEFT | TAT_TITLE, _("Missing")); - tab_double (t, 2, 0, TAB_NONE, ft->valid_cases, wfmt); - tab_double (t, 2, 1, TAB_NONE, ft->total_cases - ft->valid_cases, wfmt); + tab_double (t, 2, 0, TAB_NONE, ft->valid_cases, NULL, RC_WEIGHT); + tab_double (t, 2, 1, TAB_NONE, ft->total_cases - ft->valid_cases, NULL, RC_WEIGHT); for (i = 0; i < frq->n_percentiles; i++) { @@ -1401,9 +1419,9 @@ dump_statistics (const struct frq_proc *frq, const struct var_freqs *vf, if (pc->p == 0.5) tab_text (t, 1, r, TAB_LEFT, _("50 (Median)")); else - tab_fixed (t, 1, r, TAB_LEFT, pc->p * 100, 3, 0); + tab_double (t, 1, r, TAB_LEFT, pc->p * 100, NULL, RC_INTEGER); tab_double (t, 2, r, TAB_NONE, pc->value, - var_get_print_format (vf->var)); + var_get_print_format (vf->var), RC_OTHER); r++; }