1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004, 2008, 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include <gsl/gsl_cdf.h>
20 #include <libpspp/message.h>
25 #include <math/sort.h>
26 #include <math/order-stats.h>
27 #include <math/percentiles.h>
28 #include <math/tukey-hinges.h>
29 #include <math/box-whisker.h>
30 #include <math/trimmed-mean.h>
31 #include <math/extrema.h>
33 #include <data/case.h>
34 #include <data/casegrouper.h>
35 #include <data/casereader.h>
36 #include <data/casewriter.h>
37 #include <data/dictionary.h>
38 #include <data/procedure.h>
39 #include <data/subcase.h>
40 #include <data/value-labels.h>
41 #include <data/variable.h>
42 #include <language/command.h>
43 #include <language/dictionary/split-file.h>
44 #include <language/lexer/lexer.h>
45 #include <libpspp/compiler.h>
46 #include <libpspp/hash.h>
47 #include <libpspp/message.h>
48 #include <libpspp/misc.h>
49 #include <libpspp/str.h>
50 #include <math/moments.h>
51 #include <output/charts/box-whisker.h>
52 #include <output/charts/cartesian.h>
53 #include <output/manager.h>
54 #include <output/table.h>
60 #define _(msgid) gettext (msgid)
61 #define N_(msgid) msgid
64 #include <output/chart.h>
65 #include <output/charts/plot-hist.h>
66 #include <output/charts/plot-chart.h>
67 #include <math/histogram.h>
74 missing=miss:pairwise/!listwise,
76 incl:include/!exclude;
77 +compare=cmp:variables/!groups;
80 +plot[plt_]=stemleaf,boxplot,npplot,:spreadlevel(*d:n),histogram,all,none;
82 +statistics[st_]=descriptives,:extreme(*d:n),all,none.
90 static struct cmd_examine cmd;
92 static const struct variable **dependent_vars;
93 static size_t n_dependent_vars;
97 static subc_list_double percentile_list;
98 static enum pc_alg percentile_algorithm;
100 struct factor_metrics
102 struct moments1 *moments;
104 struct percentile **ptl;
107 struct statistic *tukey_hinges;
108 struct statistic *box_whisker;
109 struct statistic *trimmed_mean;
110 struct statistic *histogram;
111 struct order_stats *np;
113 /* Three quartiles indexing into PTL */
114 struct percentile **quartiles;
116 /* A reader sorted in ASCENDING order */
117 struct casereader *up_reader;
119 /* The minimum value of all the weights */
122 /* Sum of all weights, including those for missing values */
125 /* Sum of weights of non_missing values */
138 struct extrema *minima;
139 struct extrema *maxima;
146 union value *value[2];
148 /* An array of factor metrics, one for each variable */
149 struct factor_metrics *metrics;
154 /* We need to make a list of this structure */
157 /* The independent variable */
158 const struct variable const* indep_var[2];
160 /* A list of results for this factor */
161 struct ll_list result_list ;
166 factor_destroy (struct xfactor *fctr)
168 struct ll *ll = ll_head (&fctr->result_list);
169 while (ll != ll_null (&fctr->result_list))
172 struct factor_result *result =
173 ll_data (ll, struct factor_result, ll);
175 for (v = 0; v < n_dependent_vars; ++v)
178 moments1_destroy (result->metrics[v].moments);
179 extrema_destroy (result->metrics[v].minima);
180 extrema_destroy (result->metrics[v].maxima);
181 statistic_destroy (result->metrics[v].trimmed_mean);
182 statistic_destroy (result->metrics[v].tukey_hinges);
183 statistic_destroy (result->metrics[v].box_whisker);
184 statistic_destroy (result->metrics[v].histogram);
185 for (i = 0 ; i < result->metrics[v].n_ptiles; ++i)
186 statistic_destroy ((struct statistic *) result->metrics[v].ptl[i]);
187 free (result->metrics[v].ptl);
188 free (result->metrics[v].quartiles);
189 casereader_destroy (result->metrics[v].up_reader);
192 free (result->value[0]);
193 free (result->value[1]);
194 free (result->metrics);
200 static struct xfactor level0_factor;
201 static struct ll_list factor_list;
203 /* Parse the clause specifying the factors */
204 static int examine_parse_independent_vars (struct lexer *lexer,
205 const struct dictionary *dict,
206 struct cmd_examine *cmd);
208 /* Output functions */
209 static void show_summary (const struct variable **dependent_var, int n_dep_var,
210 const struct xfactor *f);
213 static void show_descriptives (const struct variable **dependent_var,
215 const struct xfactor *f);
218 static void show_percentiles (const struct variable **dependent_var,
220 const struct xfactor *f);
223 static void show_extremes (const struct variable **dependent_var,
225 const struct xfactor *f);
230 /* Per Split function */
231 static void run_examine (struct cmd_examine *, struct casereader *,
234 static void output_examine (void);
237 void factor_calc (const struct ccase *c, int case_no,
238 double weight, bool case_missing);
241 /* Represent a factor as a string, so it can be
242 printed in a human readable fashion */
243 static void factor_to_string (const struct xfactor *fctr,
244 const struct factor_result *result,
247 /* Represent a factor as a string, so it can be
248 printed in a human readable fashion,
249 but sacrificing some readablility for the sake of brevity */
251 factor_to_string_concise (const struct xfactor *fctr,
252 const struct factor_result *result,
258 /* Categories of missing values to exclude. */
259 static enum mv_class exclude_values;
262 cmd_examine (struct lexer *lexer, struct dataset *ds)
264 struct casegrouper *grouper;
265 struct casereader *group;
268 subc_list_double_create (&percentile_list);
269 percentile_algorithm = PC_HAVERAGE;
271 ll_init (&factor_list);
273 if ( !parse_examine (lexer, ds, &cmd, NULL) )
275 subc_list_double_destroy (&percentile_list);
279 /* If /MISSING=INCLUDE is set, then user missing values are ignored */
280 exclude_values = cmd.incl == XMN_INCLUDE ? MV_SYSTEM : MV_ANY;
282 if ( cmd.st_n == SYSMIS )
285 if ( ! cmd.sbc_cinterval)
286 cmd.n_cinterval[0] = 95.0;
288 /* If descriptives have been requested, make sure the
289 quartiles are calculated */
290 if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES] )
292 subc_list_double_push (&percentile_list, 25);
293 subc_list_double_push (&percentile_list, 50);
294 subc_list_double_push (&percentile_list, 75);
297 grouper = casegrouper_create_splits (proc_open (ds), dataset_dict (ds));
299 while (casegrouper_get_next_group (grouper, &group))
301 struct casereader *reader =
302 casereader_create_arithmetic_sequence (group, 1, 1);
304 run_examine (&cmd, reader, ds);
307 ok = casegrouper_destroy (grouper);
308 ok = proc_commit (ds) && ok;
310 if ( dependent_vars )
311 free (dependent_vars);
313 subc_list_double_destroy (&percentile_list);
315 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
319 /* Plot the normal and detrended normal plots for RESULT.
320 Label the plots with LABEL */
322 np_plot (struct np *np, const char *label)
324 double yfirst = 0, ylast = 0;
331 struct chart *np_chart;
333 /* Detrended Normal Plot */
334 struct chart *dnp_chart;
336 /* The slope and intercept of the ideal normal probability line */
337 const double slope = 1.0 / np->stddev;
338 const double intercept = -np->mean / np->stddev;
342 msg (MW, _("Not creating plot because data set is empty."));
346 np_chart = chart_create ();
347 dnp_chart = chart_create ();
349 if ( !np_chart || ! dnp_chart )
352 chart_write_title (np_chart, _("Normal Q-Q Plot of %s"), label);
353 chart_write_xlabel (np_chart, _("Observed Value"));
354 chart_write_ylabel (np_chart, _("Expected Normal"));
356 chart_write_title (dnp_chart, _("Detrended Normal Q-Q Plot of %s"),
358 chart_write_xlabel (dnp_chart, _("Observed Value"));
359 chart_write_ylabel (dnp_chart, _("Dev from Normal"));
361 yfirst = gsl_cdf_ugaussian_Pinv (1 / (np->n + 1));
362 ylast = gsl_cdf_ugaussian_Pinv (np->n / (np->n + 1));
364 /* Need to make sure that both the scatter plot and the ideal fit into the
366 x_lower = MIN (np->y_min, (yfirst - intercept) / slope) ;
367 x_upper = MAX (np->y_max, (ylast - intercept) / slope) ;
368 slack = (x_upper - x_lower) * 0.05 ;
370 chart_write_xscale (np_chart, x_lower - slack, x_upper + slack, 5);
371 chart_write_xscale (dnp_chart, np->y_min, np->y_max, 5);
373 chart_write_yscale (np_chart, yfirst, ylast, 5);
374 chart_write_yscale (dnp_chart, np->dns_min, np->dns_max, 5);
377 struct casereader *reader = casewriter_make_reader (np->writer);
379 while ((c = casereader_read (reader)) != NULL)
381 chart_datum (np_chart, 0, case_data_idx (c, NP_IDX_Y)->f, case_data_idx (c, NP_IDX_NS)->f);
382 chart_datum (dnp_chart, 0, case_data_idx (c, NP_IDX_Y)->f, case_data_idx (c, NP_IDX_DNS)->f);
386 casereader_destroy (reader);
389 chart_line (dnp_chart, 0, 0, np->y_min, np->y_max , CHART_DIM_X);
390 chart_line (np_chart, slope, intercept, yfirst, ylast , CHART_DIM_Y);
392 chart_submit (np_chart);
393 chart_submit (dnp_chart);
398 show_npplot (const struct variable **dependent_var,
400 const struct xfactor *fctr)
404 for (v = 0; v < n_dep_var; ++v)
407 for (ll = ll_head (&fctr->result_list);
408 ll != ll_null (&fctr->result_list);
412 const struct factor_result *result =
413 ll_data (ll, struct factor_result, ll);
415 ds_init_empty (&str);
416 ds_put_format (&str, "%s ", var_get_name (dependent_var[v]));
418 factor_to_string (fctr, result, &str);
420 np_plot ((struct np*) result->metrics[v].np, ds_cstr(&str));
422 statistic_destroy ((struct statistic *)result->metrics[v].np);
431 show_histogram (const struct variable **dependent_var,
433 const struct xfactor *fctr)
437 for (v = 0; v < n_dep_var; ++v)
440 for (ll = ll_head (&fctr->result_list);
441 ll != ll_null (&fctr->result_list);
445 const struct factor_result *result =
446 ll_data (ll, struct factor_result, ll);
448 ds_init_empty (&str);
449 ds_put_format (&str, "%s ", var_get_name (dependent_var[v]));
451 factor_to_string (fctr, result, &str);
453 histogram_plot ((struct histogram *) result->metrics[v].histogram,
455 (struct moments1 *) result->metrics[v].moments);
465 show_boxplot_groups (const struct variable **dependent_var,
467 const struct xfactor *fctr)
471 for (v = 0; v < n_dep_var; ++v)
475 struct chart *ch = chart_create ();
476 double y_min = DBL_MAX;
477 double y_max = -DBL_MAX;
479 for (ll = ll_head (&fctr->result_list);
480 ll != ll_null (&fctr->result_list);
483 const struct extremum *max, *min;
484 const struct factor_result *result =
485 ll_data (ll, struct factor_result, ll);
487 const struct ll_list *max_list =
488 extrema_list (result->metrics[v].maxima);
490 const struct ll_list *min_list =
491 extrema_list (result->metrics[v].minima);
493 if ( ll_is_empty (max_list))
495 msg (MW, _("Not creating plot because data set is empty."));
499 max = (const struct extremum *)
500 ll_data (ll_head(max_list), struct extremum, ll);
502 min = (const struct extremum *)
503 ll_data (ll_head (min_list), struct extremum, ll);
505 y_max = MAX (y_max, max->value);
506 y_min = MIN (y_min, min->value);
509 boxplot_draw_yscale (ch, y_max, y_min);
511 if ( fctr->indep_var[0])
512 chart_write_title (ch, _("Boxplot of %s vs. %s"),
513 var_to_string (dependent_var[v]),
514 var_to_string (fctr->indep_var[0]) );
516 chart_write_title (ch, _("Boxplot of %s"),
517 var_to_string (dependent_var[v]));
519 for (ll = ll_head (&fctr->result_list);
520 ll != ll_null (&fctr->result_list);
523 const struct factor_result *result =
524 ll_data (ll, struct factor_result, ll);
527 const double box_width = (ch->data_right - ch->data_left)
528 / (ll_count (&fctr->result_list) * 2.0 ) ;
530 const double box_centre = (f++ * 2 + 1) * box_width + ch->data_left;
532 ds_init_empty (&str);
533 factor_to_string_concise (fctr, result, &str);
535 boxplot_draw_boxplot (ch,
536 box_centre, box_width,
537 (const struct box_whisker *)
538 result->metrics[v].box_whisker,
551 show_boxplot_variables (const struct variable **dependent_var,
553 const struct xfactor *fctr
559 const struct ll_list *result_list = &fctr->result_list;
561 for (ll = ll_head (result_list);
562 ll != ll_null (result_list);
567 struct chart *ch = chart_create ();
568 double y_min = DBL_MAX;
569 double y_max = -DBL_MAX;
571 const struct factor_result *result =
572 ll_data (ll, struct factor_result, ll);
574 const double box_width = (ch->data_right - ch->data_left)
575 / (n_dep_var * 2.0 ) ;
577 for (v = 0; v < n_dep_var; ++v)
579 const struct ll *max_ll =
580 ll_head (extrema_list (result->metrics[v].maxima));
581 const struct ll *min_ll =
582 ll_head (extrema_list (result->metrics[v].minima));
584 const struct extremum *max =
585 (const struct extremum *) ll_data (max_ll, struct extremum, ll);
587 const struct extremum *min =
588 (const struct extremum *) ll_data (min_ll, struct extremum, ll);
590 y_max = MAX (y_max, max->value);
591 y_min = MIN (y_min, min->value);
595 boxplot_draw_yscale (ch, y_max, y_min);
597 ds_init_empty (&title);
598 factor_to_string (fctr, result, &title);
601 ds_put_format (&title, "%s = ", var_get_name (fctr->indep_var[0]));
602 var_append_value_name (fctr->indep_var[0], result->value[0], &title);
605 chart_write_title (ch, ds_cstr (&title));
608 for (v = 0; v < n_dep_var; ++v)
611 const double box_centre = (v * 2 + 1) * box_width + ch->data_left;
613 ds_init_empty (&str);
614 ds_init_cstr (&str, var_get_name (dependent_var[v]));
616 boxplot_draw_boxplot (ch,
617 box_centre, box_width,
618 (const struct box_whisker *) result->metrics[v].box_whisker,
629 /* Show all the appropriate tables */
631 output_examine (void)
635 show_summary (dependent_vars, n_dependent_vars, &level0_factor);
637 if ( cmd.a_statistics[XMN_ST_EXTREME] )
638 show_extremes (dependent_vars, n_dependent_vars, &level0_factor);
640 if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES] )
641 show_descriptives (dependent_vars, n_dependent_vars, &level0_factor);
643 if ( cmd.sbc_percentiles)
644 show_percentiles (dependent_vars, n_dependent_vars, &level0_factor);
648 if (cmd.a_plot[XMN_PLT_BOXPLOT])
649 show_boxplot_groups (dependent_vars, n_dependent_vars, &level0_factor);
651 if (cmd.a_plot[XMN_PLT_HISTOGRAM])
652 show_histogram (dependent_vars, n_dependent_vars, &level0_factor);
654 if (cmd.a_plot[XMN_PLT_NPPLOT])
655 show_npplot (dependent_vars, n_dependent_vars, &level0_factor);
658 for (ll = ll_head (&factor_list);
659 ll != ll_null (&factor_list); ll = ll_next (ll))
661 struct xfactor *factor = ll_data (ll, struct xfactor, ll);
662 show_summary (dependent_vars, n_dependent_vars, factor);
664 if ( cmd.a_statistics[XMN_ST_EXTREME] )
665 show_extremes (dependent_vars, n_dependent_vars, factor);
667 if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES] )
668 show_descriptives (dependent_vars, n_dependent_vars, factor);
670 if ( cmd.sbc_percentiles)
671 show_percentiles (dependent_vars, n_dependent_vars, factor);
673 if (cmd.a_plot[XMN_PLT_BOXPLOT] &&
674 cmd.cmp == XMN_GROUPS)
675 show_boxplot_groups (dependent_vars, n_dependent_vars, factor);
678 if (cmd.a_plot[XMN_PLT_BOXPLOT] &&
679 cmd.cmp == XMN_VARIABLES)
680 show_boxplot_variables (dependent_vars, n_dependent_vars,
683 if (cmd.a_plot[XMN_PLT_HISTOGRAM])
684 show_histogram (dependent_vars, n_dependent_vars, factor);
686 if (cmd.a_plot[XMN_PLT_NPPLOT])
687 show_npplot (dependent_vars, n_dependent_vars, factor);
691 /* Parse the PERCENTILES subcommand */
693 xmn_custom_percentiles (struct lexer *lexer, struct dataset *ds UNUSED,
694 struct cmd_examine *p UNUSED, void *aux UNUSED)
696 lex_match (lexer, '=');
698 lex_match (lexer, '(');
700 while ( lex_is_number (lexer) )
702 subc_list_double_push (&percentile_list, lex_number (lexer));
706 lex_match (lexer, ',') ;
708 lex_match (lexer, ')');
710 lex_match (lexer, '=');
712 if ( lex_match_id (lexer, "HAVERAGE"))
713 percentile_algorithm = PC_HAVERAGE;
715 else if ( lex_match_id (lexer, "WAVERAGE"))
716 percentile_algorithm = PC_WAVERAGE;
718 else if ( lex_match_id (lexer, "ROUND"))
719 percentile_algorithm = PC_ROUND;
721 else if ( lex_match_id (lexer, "EMPIRICAL"))
722 percentile_algorithm = PC_EMPIRICAL;
724 else if ( lex_match_id (lexer, "AEMPIRICAL"))
725 percentile_algorithm = PC_AEMPIRICAL;
727 else if ( lex_match_id (lexer, "NONE"))
728 percentile_algorithm = PC_NONE;
731 if ( 0 == subc_list_double_count (&percentile_list))
733 subc_list_double_push (&percentile_list, 5);
734 subc_list_double_push (&percentile_list, 10);
735 subc_list_double_push (&percentile_list, 25);
736 subc_list_double_push (&percentile_list, 50);
737 subc_list_double_push (&percentile_list, 75);
738 subc_list_double_push (&percentile_list, 90);
739 subc_list_double_push (&percentile_list, 95);
745 /* TOTAL and NOTOTAL are simple, mutually exclusive flags */
747 xmn_custom_total (struct lexer *lexer UNUSED, struct dataset *ds UNUSED,
748 struct cmd_examine *p, void *aux UNUSED)
750 if ( p->sbc_nototal )
752 msg (SE, _("%s and %s are mutually exclusive"),"TOTAL","NOTOTAL");
760 xmn_custom_nototal (struct lexer *lexer UNUSED, struct dataset *ds UNUSED,
761 struct cmd_examine *p, void *aux UNUSED)
765 msg (SE, _("%s and %s are mutually exclusive"), "TOTAL", "NOTOTAL");
774 /* Parser for the variables sub command
775 Returns 1 on success */
777 xmn_custom_variables (struct lexer *lexer, struct dataset *ds,
778 struct cmd_examine *cmd,
781 const struct dictionary *dict = dataset_dict (ds);
782 lex_match (lexer, '=');
784 if ( (lex_token (lexer) != T_ID || dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
785 && lex_token (lexer) != T_ALL)
790 if (!parse_variables_const (lexer, dict, &dependent_vars, &n_dependent_vars,
791 PV_NO_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH) )
793 free (dependent_vars);
797 assert (n_dependent_vars);
800 if ( lex_match (lexer, T_BY))
803 success = examine_parse_independent_vars (lexer, dict, cmd);
806 free (dependent_vars);
816 /* Parse the clause specifying the factors */
818 examine_parse_independent_vars (struct lexer *lexer,
819 const struct dictionary *dict,
820 struct cmd_examine *cmd)
823 struct xfactor *sf = xmalloc (sizeof *sf);
825 ll_init (&sf->result_list);
827 if ( (lex_token (lexer) != T_ID ||
828 dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
829 && lex_token (lexer) != T_ALL)
835 sf->indep_var[0] = parse_variable (lexer, dict);
836 sf->indep_var[1] = NULL;
838 if ( lex_token (lexer) == T_BY )
840 lex_match (lexer, T_BY);
842 if ( (lex_token (lexer) != T_ID ||
843 dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
844 && lex_token (lexer) != T_ALL)
850 sf->indep_var[1] = parse_variable (lexer, dict);
852 ll_push_tail (&factor_list, &sf->ll);
855 ll_push_tail (&factor_list, &sf->ll);
857 lex_match (lexer, ',');
859 if ( lex_token (lexer) == '.' || lex_token (lexer) == '/' )
862 success = examine_parse_independent_vars (lexer, dict, cmd);
871 examine_group (struct cmd_examine *cmd, struct casereader *reader, int level,
872 const struct dictionary *dict, struct xfactor *factor)
875 const struct variable *wv = dict_get_weight (dict);
878 struct factor_result *result = xzalloc (sizeof (*result));
880 result->metrics = xcalloc (n_dependent_vars, sizeof (*result->metrics));
882 if ( cmd->a_statistics[XMN_ST_EXTREME] )
883 n_extrema = cmd->st_n;
886 c = casereader_peek (reader, 0);
892 value_dup (case_data (c, factor->indep_var[0]),
893 var_get_width (factor->indep_var[0]));
897 value_dup (case_data (c, factor->indep_var[1]),
898 var_get_width (factor->indep_var[1]));
903 for (v = 0; v < n_dependent_vars; ++v)
905 struct casewriter *writer;
906 struct casereader *input = casereader_clone (reader);
908 result->metrics[v].moments = moments1_create (MOMENT_KURTOSIS);
909 result->metrics[v].minima = extrema_create (n_extrema, EXTREME_MINIMA);
910 result->metrics[v].maxima = extrema_create (n_extrema, EXTREME_MAXIMA);
911 result->metrics[v].cmin = DBL_MAX;
913 if (cmd->a_statistics[XMN_ST_DESCRIPTIVES] ||
914 cmd->a_plot[XMN_PLT_BOXPLOT] ||
915 cmd->a_plot[XMN_PLT_NPPLOT] ||
916 cmd->sbc_percentiles)
918 /* In this case, we need to sort the data, so we create a sorting
920 struct subcase up_ordering;
921 subcase_init_var (&up_ordering, dependent_vars[v], SC_ASCEND);
922 writer = sort_create_writer (&up_ordering,
923 casereader_get_value_cnt (reader));
924 subcase_destroy (&up_ordering);
928 /* but in this case, sorting is unnecessary, so an ordinary
929 casewriter is sufficient */
931 autopaging_writer_create (casereader_get_value_cnt (reader));
935 /* Sort or just iterate, whilst calculating moments etc */
936 while ((c = casereader_read (input)) != NULL)
938 const casenumber loc =
939 case_data_idx (c, casereader_get_value_cnt (reader) - 1)->f;
941 const double weight = wv ? case_data (c, wv)->f : 1.0;
942 const union value *value = case_data (c, dependent_vars[v]);
944 if (weight != SYSMIS)
945 minimize (&result->metrics[v].cmin, weight);
947 moments1_add (result->metrics[v].moments,
951 result->metrics[v].n += weight;
953 if ( ! var_is_value_missing (dependent_vars[v], value, MV_ANY) )
954 result->metrics[v].n_valid += weight;
956 extrema_add (result->metrics[v].maxima,
961 extrema_add (result->metrics[v].minima,
966 casewriter_write (writer, c);
968 casereader_destroy (input);
969 result->metrics[v].up_reader = casewriter_make_reader (writer);
972 /* If percentiles or descriptives have been requested, then a
973 second pass through the data (which has now been sorted)
975 if ( cmd->a_statistics[XMN_ST_DESCRIPTIVES] ||
976 cmd->a_plot[XMN_PLT_BOXPLOT] ||
977 cmd->a_plot[XMN_PLT_NPPLOT] ||
978 cmd->sbc_percentiles)
980 for (v = 0; v < n_dependent_vars; ++v)
984 struct order_stats **os ;
985 struct factor_metrics *metric = &result->metrics[v];
987 metric->n_ptiles = percentile_list.n_data;
989 metric->ptl = xcalloc (metric->n_ptiles,
990 sizeof (struct percentile *));
992 metric->quartiles = xcalloc (3, sizeof (*metric->quartiles));
994 for (i = 0 ; i < metric->n_ptiles; ++i)
996 metric->ptl[i] = (struct percentile *)
997 percentile_create (percentile_list.data[i] / 100.0, metric->n_valid);
999 if ( percentile_list.data[i] == 25)
1000 metric->quartiles[0] = metric->ptl[i];
1001 else if ( percentile_list.data[i] == 50)
1002 metric->quartiles[1] = metric->ptl[i];
1003 else if ( percentile_list.data[i] == 75)
1004 metric->quartiles[2] = metric->ptl[i];
1007 metric->tukey_hinges = tukey_hinges_create (metric->n, metric->cmin);
1008 metric->trimmed_mean = trimmed_mean_create (metric->n, 0.05);
1010 n_os = metric->n_ptiles + 2;
1012 if ( cmd->a_plot[XMN_PLT_NPPLOT] )
1014 metric->np = np_create (metric->moments);
1018 os = xcalloc (sizeof (struct order_stats *), n_os);
1020 for (i = 0 ; i < metric->n_ptiles ; ++i )
1022 os[i] = (struct order_stats *) metric->ptl[i];
1025 os[i] = (struct order_stats *) metric->tukey_hinges;
1026 os[i+1] = (struct order_stats *) metric->trimmed_mean;
1028 if (cmd->a_plot[XMN_PLT_NPPLOT])
1029 os[i+2] = metric->np;
1031 order_stats_accumulate (os, n_os,
1032 casereader_clone (metric->up_reader),
1033 wv, dependent_vars[v], MV_ANY);
1038 /* FIXME: Do this in the above loop */
1039 if ( cmd->a_plot[XMN_PLT_HISTOGRAM] )
1042 struct casereader *input = casereader_clone (reader);
1044 for (v = 0; v < n_dependent_vars; ++v)
1046 const struct extremum *max, *min;
1047 struct factor_metrics *metric = &result->metrics[v];
1049 const struct ll_list *max_list =
1050 extrema_list (result->metrics[v].maxima);
1052 const struct ll_list *min_list =
1053 extrema_list (result->metrics[v].minima);
1055 if ( ll_is_empty (max_list))
1057 msg (MW, _("Not creating plot because data set is empty."));
1061 assert (! ll_is_empty (min_list));
1063 max = (const struct extremum *)
1064 ll_data (ll_head(max_list), struct extremum, ll);
1066 min = (const struct extremum *)
1067 ll_data (ll_head (min_list), struct extremum, ll);
1069 metric->histogram = histogram_create (10, min->value, max->value);
1072 while ((c = casereader_read (input)) != NULL)
1074 const double weight = wv ? case_data (c, wv)->f : 1.0;
1076 for (v = 0; v < n_dependent_vars; ++v)
1078 struct factor_metrics *metric = &result->metrics[v];
1079 if ( metric->histogram)
1080 histogram_add ((struct histogram *) metric->histogram,
1081 case_data (c, dependent_vars[v])->f, weight);
1085 casereader_destroy (input);
1088 /* In this case, a third iteration is required */
1089 if (cmd->a_plot[XMN_PLT_BOXPLOT])
1091 for (v = 0; v < n_dependent_vars; ++v)
1093 struct factor_metrics *metric = &result->metrics[v];
1095 metric->box_whisker =
1096 box_whisker_create ((struct tukey_hinges *) metric->tukey_hinges,
1098 casereader_get_value_cnt (metric->up_reader)
1101 order_stats_accumulate ((struct order_stats **) &metric->box_whisker,
1103 casereader_clone (metric->up_reader),
1104 wv, dependent_vars[v], MV_ANY);
1108 ll_push_tail (&factor->result_list, &result->ll);
1109 casereader_destroy (reader);
1114 run_examine (struct cmd_examine *cmd, struct casereader *input,
1118 const struct dictionary *dict = dataset_dict (ds);
1120 struct casereader *level0 = casereader_clone (input);
1122 c = casereader_peek (input, 0);
1125 casereader_destroy (input);
1129 output_split_file_values (ds, c);
1132 ll_init (&level0_factor.result_list);
1134 examine_group (cmd, level0, 0, dict, &level0_factor);
1136 for (ll = ll_head (&factor_list);
1137 ll != ll_null (&factor_list);
1140 struct xfactor *factor = ll_data (ll, struct xfactor, ll);
1142 struct casereader *group = NULL;
1143 struct casereader *level1;
1144 struct casegrouper *grouper1 = NULL;
1146 level1 = casereader_clone (input);
1147 level1 = sort_execute_1var (level1, factor->indep_var[0]);
1148 grouper1 = casegrouper_create_vars (level1, &factor->indep_var[0], 1);
1150 while (casegrouper_get_next_group (grouper1, &group))
1152 struct casereader *group_copy = casereader_clone (group);
1154 if ( !factor->indep_var[1])
1155 examine_group (cmd, group_copy, 1, dict, factor);
1159 struct casereader *group2 = NULL;
1160 struct casegrouper *grouper2 = NULL;
1162 group_copy = sort_execute_1var (group_copy,
1163 factor->indep_var[1]);
1165 grouper2 = casegrouper_create_vars (group_copy,
1166 &factor->indep_var[1], 1);
1168 while (casegrouper_get_next_group (grouper2, &group2))
1170 examine_group (cmd, group2, 2, dict, factor);
1173 casegrouper_destroy (grouper2);
1176 casereader_destroy (group);
1178 casegrouper_destroy (grouper1);
1181 casereader_destroy (input);
1185 factor_destroy (&level0_factor);
1189 for (ll = ll_head (&factor_list);
1190 ll != ll_null (&factor_list);
1193 struct xfactor *f = ll_data (ll, struct xfactor, ll);
1202 show_summary (const struct variable **dependent_var, int n_dep_var,
1203 const struct xfactor *fctr)
1205 static const char *subtitle[]=
1213 int heading_columns = 1;
1215 const int heading_rows = 3;
1216 struct tab_table *tbl;
1223 if ( fctr->indep_var[0] )
1225 heading_columns = 2;
1227 if ( fctr->indep_var[1] )
1229 heading_columns = 3;
1233 n_rows *= ll_count (&fctr->result_list);
1234 n_rows += heading_rows;
1236 n_cols = heading_columns + 6;
1238 tbl = tab_create (n_cols, n_rows, 0);
1239 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1241 tab_dim (tbl, tab_natural_dimensions);
1243 /* Outline the box */
1248 n_cols - 1, n_rows - 1);
1250 /* Vertical lines for the data only */
1255 n_cols - 1, n_rows - 1);
1258 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1259 tab_hline (tbl, TAL_1, heading_columns, n_cols - 1, 1 );
1260 tab_hline (tbl, TAL_1, heading_columns, n_cols - 1, heading_rows -1 );
1262 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1265 tab_title (tbl, _("Case Processing Summary"));
1267 tab_joint_text (tbl, heading_columns, 0,
1269 TAB_CENTER | TAT_TITLE,
1272 /* Remove lines ... */
1279 for (j = 0 ; j < 3 ; ++j)
1281 tab_text (tbl, heading_columns + j * 2 , 2, TAB_CENTER | TAT_TITLE,
1284 tab_text (tbl, heading_columns + j * 2 + 1, 2, TAB_CENTER | TAT_TITLE,
1287 tab_joint_text (tbl, heading_columns + j * 2 , 1,
1288 heading_columns + j * 2 + 1, 1,
1289 TAB_CENTER | TAT_TITLE,
1292 tab_box (tbl, -1, -1,
1294 heading_columns + j * 2, 1,
1295 heading_columns + j * 2 + 1, 1);
1299 /* Titles for the independent variables */
1300 if ( fctr->indep_var[0] )
1302 tab_text (tbl, 1, heading_rows - 1, TAB_CENTER | TAT_TITLE,
1303 var_to_string (fctr->indep_var[0]));
1305 if ( fctr->indep_var[1] )
1307 tab_text (tbl, 2, heading_rows - 1, TAB_CENTER | TAT_TITLE,
1308 var_to_string (fctr->indep_var[1]));
1312 for (v = 0 ; v < n_dep_var ; ++v)
1316 union value *last_value = NULL;
1319 tab_hline (tbl, TAL_1, 0, n_cols -1 ,
1320 v * ll_count (&fctr->result_list)
1325 v * ll_count (&fctr->result_list) + heading_rows,
1326 TAB_LEFT | TAT_TITLE,
1327 var_to_string (dependent_var[v])
1331 for (ll = ll_head (&fctr->result_list);
1332 ll != ll_null (&fctr->result_list); ll = ll_next (ll))
1335 const struct factor_result *result =
1336 ll_data (ll, struct factor_result, ll);
1338 if ( fctr->indep_var[0] )
1341 if ( last_value == NULL ||
1342 compare_values_short (last_value, result->value[0],
1343 fctr->indep_var[0]))
1347 last_value = result->value[0];
1348 ds_init_empty (&str);
1350 var_append_value_name (fctr->indep_var[0], result->value[0],
1355 v * ll_count (&fctr->result_list),
1356 TAB_LEFT | TAT_TITLE,
1361 if ( fctr->indep_var[1] && j > 0)
1362 tab_hline (tbl, TAL_1, 1, n_cols - 1,
1364 v * ll_count (&fctr->result_list));
1367 if ( fctr->indep_var[1])
1371 ds_init_empty (&str);
1373 var_append_value_name (fctr->indep_var[1],
1374 result->value[1], &str);
1378 v * ll_count (&fctr->result_list),
1379 TAB_LEFT | TAT_TITLE,
1387 moments1_calculate (result->metrics[v].moments,
1388 &n, &result->metrics[v].mean,
1389 &result->metrics[v].variance,
1390 &result->metrics[v].skewness,
1391 &result->metrics[v].kurtosis);
1393 result->metrics[v].se_mean = sqrt (result->metrics[v].variance / n) ;
1396 tab_float (tbl, heading_columns,
1397 heading_rows + j + v * ll_count (&fctr->result_list),
1401 tab_text (tbl, heading_columns + 1,
1402 heading_rows + j + v * ll_count (&fctr->result_list),
1403 TAB_RIGHT | TAT_PRINTF,
1404 "%g%%", n * 100.0 / result->metrics[v].n);
1407 tab_float (tbl, heading_columns + 2,
1408 heading_rows + j + v * ll_count (&fctr->result_list),
1410 result->metrics[v].n - n,
1413 tab_text (tbl, heading_columns + 3,
1414 heading_rows + j + v * ll_count (&fctr->result_list),
1415 TAB_RIGHT | TAT_PRINTF,
1417 (result->metrics[v].n - n) * 100.0 / result->metrics[v].n
1420 /* Total Valid + Missing */
1421 tab_float (tbl, heading_columns + 4,
1422 heading_rows + j + v * ll_count (&fctr->result_list),
1424 result->metrics[v].n,
1427 tab_text (tbl, heading_columns + 5,
1428 heading_rows + j + v * ll_count (&fctr->result_list),
1429 TAB_RIGHT | TAT_PRINTF,
1431 (result->metrics[v].n) * 100.0 / result->metrics[v].n
1442 #define DESCRIPTIVE_ROWS 13
1445 show_descriptives (const struct variable **dependent_var,
1447 const struct xfactor *fctr)
1450 int heading_columns = 3;
1452 const int heading_rows = 1;
1453 struct tab_table *tbl;
1460 if ( fctr->indep_var[0] )
1462 heading_columns = 4;
1464 if ( fctr->indep_var[1] )
1466 heading_columns = 5;
1470 n_rows *= ll_count (&fctr->result_list) * DESCRIPTIVE_ROWS;
1471 n_rows += heading_rows;
1473 n_cols = heading_columns + 2;
1475 tbl = tab_create (n_cols, n_rows, 0);
1476 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1478 tab_dim (tbl, tab_natural_dimensions);
1480 /* Outline the box */
1485 n_cols - 1, n_rows - 1);
1488 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1489 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
1491 tab_vline (tbl, TAL_1, n_cols - 1, 0, n_rows - 1);
1494 if ( fctr->indep_var[0])
1495 tab_text (tbl, 1, 0, TAT_TITLE, var_to_string (fctr->indep_var[0]));
1497 if ( fctr->indep_var[1])
1498 tab_text (tbl, 2, 0, TAT_TITLE, var_to_string (fctr->indep_var[1]));
1500 for (v = 0 ; v < n_dep_var ; ++v )
1505 const int row_var_start =
1506 v * DESCRIPTIVE_ROWS * ll_count(&fctr->result_list);
1510 heading_rows + row_var_start,
1511 TAB_LEFT | TAT_TITLE,
1512 var_to_string (dependent_var[v])
1515 for (ll = ll_head (&fctr->result_list);
1516 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
1518 const struct factor_result *result =
1519 ll_data (ll, struct factor_result, ll);
1522 gsl_cdf_tdist_Qinv ((1 - cmd.n_cinterval[0] / 100.0) / 2.0,
1523 result->metrics[v].n - 1);
1525 if ( i > 0 || v > 0 )
1527 const int left_col = (i == 0) ? 0 : 1;
1528 tab_hline (tbl, TAL_1, left_col, n_cols - 1,
1529 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS);
1532 if ( fctr->indep_var[0])
1535 ds_init_empty (&vstr);
1536 var_append_value_name (fctr->indep_var[0],
1537 result->value[0], &vstr);
1540 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1549 tab_text (tbl, n_cols - 4,
1550 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1554 tab_text (tbl, n_cols - 4,
1555 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1556 TAB_LEFT | TAT_PRINTF,
1557 _("%g%% Confidence Interval for Mean"),
1558 cmd.n_cinterval[0]);
1560 tab_text (tbl, n_cols - 3,
1561 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1565 tab_text (tbl, n_cols - 3,
1566 heading_rows + row_var_start + 2 + i * DESCRIPTIVE_ROWS,
1570 tab_text (tbl, n_cols - 4,
1571 heading_rows + row_var_start + 3 + i * DESCRIPTIVE_ROWS,
1572 TAB_LEFT | TAT_PRINTF,
1573 _("5%% Trimmed Mean"));
1575 tab_text (tbl, n_cols - 4,
1576 heading_rows + row_var_start + 4 + i * DESCRIPTIVE_ROWS,
1580 tab_text (tbl, n_cols - 4,
1581 heading_rows + row_var_start + 5 + i * DESCRIPTIVE_ROWS,
1585 tab_text (tbl, n_cols - 4,
1586 heading_rows + row_var_start + 6 + i * DESCRIPTIVE_ROWS,
1588 _("Std. Deviation"));
1590 tab_text (tbl, n_cols - 4,
1591 heading_rows + row_var_start + 7 + i * DESCRIPTIVE_ROWS,
1595 tab_text (tbl, n_cols - 4,
1596 heading_rows + row_var_start + 8 + i * DESCRIPTIVE_ROWS,
1600 tab_text (tbl, n_cols - 4,
1601 heading_rows + row_var_start + 9 + i * DESCRIPTIVE_ROWS,
1605 tab_text (tbl, n_cols - 4,
1606 heading_rows + row_var_start + 10 + i * DESCRIPTIVE_ROWS,
1608 _("Interquartile Range"));
1611 tab_text (tbl, n_cols - 4,
1612 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1616 tab_text (tbl, n_cols - 4,
1617 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1622 /* Now the statistics ... */
1624 tab_float (tbl, n_cols - 2,
1625 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1627 result->metrics[v].mean,
1630 tab_float (tbl, n_cols - 1,
1631 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1633 result->metrics[v].se_mean,
1637 tab_float (tbl, n_cols - 2,
1638 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1640 result->metrics[v].mean - t *
1641 result->metrics[v].se_mean,
1644 tab_float (tbl, n_cols - 2,
1645 heading_rows + row_var_start + 2 + i * DESCRIPTIVE_ROWS,
1647 result->metrics[v].mean + t *
1648 result->metrics[v].se_mean,
1652 tab_float (tbl, n_cols - 2,
1653 heading_rows + row_var_start + 3 + i * DESCRIPTIVE_ROWS,
1655 trimmed_mean_calculate ((struct trimmed_mean *) result->metrics[v].trimmed_mean),
1659 tab_float (tbl, n_cols - 2,
1660 heading_rows + row_var_start + 4 + i * DESCRIPTIVE_ROWS,
1662 percentile_calculate (result->metrics[v].quartiles[1], percentile_algorithm),
1666 tab_float (tbl, n_cols - 2,
1667 heading_rows + row_var_start + 5 + i * DESCRIPTIVE_ROWS,
1669 result->metrics[v].variance,
1672 tab_float (tbl, n_cols - 2,
1673 heading_rows + row_var_start + 6 + i * DESCRIPTIVE_ROWS,
1675 sqrt (result->metrics[v].variance),
1678 tab_float (tbl, n_cols - 2,
1679 heading_rows + row_var_start + 10 + i * DESCRIPTIVE_ROWS,
1681 percentile_calculate (result->metrics[v].quartiles[2],
1682 percentile_algorithm) -
1683 percentile_calculate (result->metrics[v].quartiles[0],
1684 percentile_algorithm),
1688 tab_float (tbl, n_cols - 2,
1689 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1691 result->metrics[v].skewness,
1694 tab_float (tbl, n_cols - 2,
1695 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1697 result->metrics[v].kurtosis,
1700 tab_float (tbl, n_cols - 1,
1701 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1703 calc_seskew (result->metrics[v].n),
1706 tab_float (tbl, n_cols - 1,
1707 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1709 calc_sekurt (result->metrics[v].n),
1713 struct extremum *minimum, *maximum ;
1715 struct ll *max_ll = ll_head (extrema_list (result->metrics[v].maxima));
1716 struct ll *min_ll = ll_head (extrema_list (result->metrics[v].minima));
1718 maximum = ll_data (max_ll, struct extremum, ll);
1719 minimum = ll_data (min_ll, struct extremum, ll);
1721 tab_float (tbl, n_cols - 2,
1722 heading_rows + row_var_start + 7 + i * DESCRIPTIVE_ROWS,
1727 tab_float (tbl, n_cols - 2,
1728 heading_rows + row_var_start + 8 + i * DESCRIPTIVE_ROWS,
1733 tab_float (tbl, n_cols - 2,
1734 heading_rows + row_var_start + 9 + i * DESCRIPTIVE_ROWS,
1736 maximum->value - minimum->value,
1742 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1744 tab_title (tbl, _("Descriptives"));
1746 tab_text (tbl, n_cols - 2, 0, TAB_CENTER | TAT_TITLE,
1749 tab_text (tbl, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
1758 show_extremes (const struct variable **dependent_var,
1760 const struct xfactor *fctr)
1763 int heading_columns = 3;
1765 const int heading_rows = 1;
1766 struct tab_table *tbl;
1773 if ( fctr->indep_var[0] )
1775 heading_columns = 4;
1777 if ( fctr->indep_var[1] )
1779 heading_columns = 5;
1783 n_rows *= ll_count (&fctr->result_list) * cmd.st_n * 2;
1784 n_rows += heading_rows;
1786 n_cols = heading_columns + 2;
1788 tbl = tab_create (n_cols, n_rows, 0);
1789 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1791 tab_dim (tbl, tab_natural_dimensions);
1793 /* Outline the box */
1798 n_cols - 1, n_rows - 1);
1801 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1802 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
1803 tab_vline (tbl, TAL_1, n_cols - 1, 0, n_rows - 1);
1805 if ( fctr->indep_var[0])
1806 tab_text (tbl, 1, 0, TAT_TITLE, var_to_string (fctr->indep_var[0]));
1808 if ( fctr->indep_var[1])
1809 tab_text (tbl, 2, 0, TAT_TITLE, var_to_string (fctr->indep_var[1]));
1811 for (v = 0 ; v < n_dep_var ; ++v )
1815 const int row_var_start = v * cmd.st_n * 2 * ll_count(&fctr->result_list);
1819 heading_rows + row_var_start,
1820 TAB_LEFT | TAT_TITLE,
1821 var_to_string (dependent_var[v])
1824 for (ll = ll_head (&fctr->result_list);
1825 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
1830 const int row_result_start = i * cmd.st_n * 2;
1832 const struct factor_result *result =
1833 ll_data (ll, struct factor_result, ll);
1836 tab_hline (tbl, TAL_1, 1, n_cols - 1,
1837 heading_rows + row_var_start + row_result_start);
1839 tab_hline (tbl, TAL_1, heading_columns - 2, n_cols - 1,
1840 heading_rows + row_var_start + row_result_start + cmd.st_n);
1842 for ( e = 1; e <= cmd.st_n; ++e )
1844 tab_text (tbl, n_cols - 3,
1845 heading_rows + row_var_start + row_result_start + e - 1,
1846 TAB_RIGHT | TAT_PRINTF,
1849 tab_text (tbl, n_cols - 3,
1850 heading_rows + row_var_start + row_result_start + cmd.st_n + e - 1,
1851 TAB_RIGHT | TAT_PRINTF,
1856 min_ll = ll_head (extrema_list (result->metrics[v].minima));
1857 for (e = 0; e < cmd.st_n;)
1859 struct extremum *minimum = ll_data (min_ll, struct extremum, ll);
1860 double weight = minimum->weight;
1862 while (weight-- > 0 && e < cmd.st_n)
1864 tab_float (tbl, n_cols - 1,
1865 heading_rows + row_var_start + row_result_start + cmd.st_n + e,
1871 tab_float (tbl, n_cols - 2,
1872 heading_rows + row_var_start + row_result_start + cmd.st_n + e,
1879 min_ll = ll_next (min_ll);
1883 max_ll = ll_head (extrema_list (result->metrics[v].maxima));
1884 for (e = 0; e < cmd.st_n;)
1886 struct extremum *maximum = ll_data (max_ll, struct extremum, ll);
1887 double weight = maximum->weight;
1889 while (weight-- > 0 && e < cmd.st_n)
1891 tab_float (tbl, n_cols - 1,
1892 heading_rows + row_var_start + row_result_start + e,
1898 tab_float (tbl, n_cols - 2,
1899 heading_rows + row_var_start + row_result_start + e,
1906 max_ll = ll_next (max_ll);
1910 if ( fctr->indep_var[0])
1913 ds_init_empty (&vstr);
1914 var_append_value_name (fctr->indep_var[0],
1915 result->value[0], &vstr);
1918 heading_rows + row_var_start + row_result_start,
1927 tab_text (tbl, n_cols - 4,
1928 heading_rows + row_var_start + row_result_start,
1932 tab_text (tbl, n_cols - 4,
1933 heading_rows + row_var_start + row_result_start + cmd.st_n,
1939 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1942 tab_title (tbl, _("Extreme Values"));
1945 tab_text (tbl, n_cols - 2, 0, TAB_CENTER | TAT_TITLE,
1949 tab_text (tbl, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
1955 #define PERCENTILE_ROWS 2
1958 show_percentiles (const struct variable **dependent_var,
1960 const struct xfactor *fctr)
1964 int heading_columns = 2;
1966 const int n_percentiles = subc_list_double_count (&percentile_list);
1967 const int heading_rows = 2;
1968 struct tab_table *tbl;
1975 if ( fctr->indep_var[0] )
1977 heading_columns = 3;
1979 if ( fctr->indep_var[1] )
1981 heading_columns = 4;
1985 n_rows *= ll_count (&fctr->result_list) * PERCENTILE_ROWS;
1986 n_rows += heading_rows;
1988 n_cols = heading_columns + n_percentiles;
1990 tbl = tab_create (n_cols, n_rows, 0);
1991 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1993 tab_dim (tbl, tab_natural_dimensions);
1995 /* Outline the box */
2000 n_cols - 1, n_rows - 1);
2003 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
2004 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
2006 if ( fctr->indep_var[0])
2007 tab_text (tbl, 1, 1, TAT_TITLE, var_to_string (fctr->indep_var[0]));
2009 if ( fctr->indep_var[1])
2010 tab_text (tbl, 2, 1, TAT_TITLE, var_to_string (fctr->indep_var[1]));
2012 for (v = 0 ; v < n_dep_var ; ++v )
2018 const int row_var_start =
2019 v * PERCENTILE_ROWS * ll_count(&fctr->result_list);
2023 heading_rows + row_var_start,
2024 TAB_LEFT | TAT_TITLE,
2025 var_to_string (dependent_var[v])
2028 for (ll = ll_head (&fctr->result_list);
2029 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
2032 const struct factor_result *result =
2033 ll_data (ll, struct factor_result, ll);
2035 if ( i > 0 || v > 0 )
2037 const int left_col = (i == 0) ? 0 : 1;
2038 tab_hline (tbl, TAL_1, left_col, n_cols - 1,
2039 heading_rows + row_var_start + i * PERCENTILE_ROWS);
2042 if ( fctr->indep_var[0])
2045 ds_init_empty (&vstr);
2046 var_append_value_name (fctr->indep_var[0],
2047 result->value[0], &vstr);
2050 heading_rows + row_var_start + i * PERCENTILE_ROWS,
2059 tab_text (tbl, n_cols - n_percentiles - 1,
2060 heading_rows + row_var_start + i * PERCENTILE_ROWS,
2062 ptile_alg_desc [percentile_algorithm]);
2065 tab_text (tbl, n_cols - n_percentiles - 1,
2066 heading_rows + row_var_start + 1 + i * PERCENTILE_ROWS,
2068 _("Tukey's Hinges"));
2071 tab_vline (tbl, TAL_1, n_cols - n_percentiles -1, heading_rows, n_rows - 1);
2073 tukey_hinges_calculate ((struct tukey_hinges *) result->metrics[v].tukey_hinges,
2076 for (j = 0; j < n_percentiles; ++j)
2078 double hinge = SYSMIS;
2079 tab_float (tbl, n_cols - n_percentiles + j,
2080 heading_rows + row_var_start + i * PERCENTILE_ROWS,
2082 percentile_calculate (result->metrics[v].ptl[j],
2083 percentile_algorithm),
2087 if ( result->metrics[v].ptl[j]->ptile == 0.5)
2089 else if ( result->metrics[v].ptl[j]->ptile == 0.25)
2091 else if ( result->metrics[v].ptl[j]->ptile == 0.75)
2094 if ( hinge != SYSMIS)
2095 tab_float (tbl, n_cols - n_percentiles + j,
2096 heading_rows + row_var_start + 1 + i * PERCENTILE_ROWS,
2106 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
2108 tab_title (tbl, _("Percentiles"));
2111 for (i = 0 ; i < n_percentiles; ++i )
2113 tab_text (tbl, n_cols - n_percentiles + i, 1,
2114 TAB_CENTER | TAT_TITLE | TAT_PRINTF,
2116 subc_list_double_at (&percentile_list, i)
2122 tab_joint_text (tbl,
2123 n_cols - n_percentiles, 0,
2125 TAB_CENTER | TAT_TITLE,
2128 /* Vertical lines for the data only */
2132 n_cols - n_percentiles, 1,
2133 n_cols - 1, n_rows - 1);
2135 tab_hline (tbl, TAL_1, n_cols - n_percentiles, n_cols - 1, 1);
2143 factor_to_string_concise (const struct xfactor *fctr,
2144 const struct factor_result *result,
2148 if (fctr->indep_var[0])
2150 var_append_value_name (fctr->indep_var[0], result->value[0], str);
2152 if ( fctr->indep_var[1] )
2154 ds_put_cstr (str, ",");
2156 var_append_value_name (fctr->indep_var[1], result->value[1], str);
2158 ds_put_cstr (str, ")");
2165 factor_to_string (const struct xfactor *fctr,
2166 const struct factor_result *result,
2170 if (fctr->indep_var[0])
2172 ds_put_format (str, "(%s = ", var_get_name (fctr->indep_var[0]));
2174 var_append_value_name (fctr->indep_var[0], result->value[0], str);
2176 if ( fctr->indep_var[1] )
2178 ds_put_cstr (str, ",");
2179 ds_put_format (str, "%s = ", var_get_name (fctr->indep_var[1]));
2181 var_append_value_name (fctr->indep_var[1], result->value[1], str);
2183 ds_put_cstr (str, ")");