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 */
135 struct extrema *minima;
136 struct extrema *maxima;
143 union value *value[2];
145 /* An array of factor metrics, one for each variable */
146 struct factor_metrics *metrics;
151 /* We need to make a list of this structure */
154 /* The independent variable */
155 const struct variable const* indep_var[2];
157 /* A list of results for this factor */
158 struct ll_list result_list ;
163 factor_destroy (struct xfactor *fctr)
165 struct ll *ll = ll_head (&fctr->result_list);
166 while (ll != ll_null (&fctr->result_list))
169 struct factor_result *result =
170 ll_data (ll, struct factor_result, ll);
172 for (v = 0; v < n_dependent_vars; ++v)
175 moments1_destroy (result->metrics[v].moments);
176 extrema_destroy (result->metrics[v].minima);
177 extrema_destroy (result->metrics[v].maxima);
178 statistic_destroy (result->metrics[v].trimmed_mean);
179 statistic_destroy (result->metrics[v].tukey_hinges);
180 statistic_destroy (result->metrics[v].box_whisker);
181 statistic_destroy (result->metrics[v].histogram);
182 for (i = 0 ; i < result->metrics[v].n_ptiles; ++i)
183 statistic_destroy ((struct statistic *) result->metrics[v].ptl[i]);
184 free (result->metrics[v].ptl);
185 free (result->metrics[v].quartiles);
186 casereader_destroy (result->metrics[v].up_reader);
189 free (result->value[0]);
190 free (result->value[1]);
191 free (result->metrics);
197 static struct xfactor level0_factor;
198 static struct ll_list factor_list = LL_INITIALIZER (factor_list);
200 /* Parse the clause specifying the factors */
201 static int examine_parse_independent_vars (struct lexer *lexer,
202 const struct dictionary *dict,
203 struct cmd_examine *cmd);
205 /* Output functions */
206 static void show_summary (const struct variable **dependent_var, int n_dep_var,
207 const struct xfactor *f);
210 static void show_descriptives (const struct variable **dependent_var,
212 const struct xfactor *f);
215 static void show_percentiles (const struct variable **dependent_var,
217 const struct xfactor *f);
220 static void show_extremes (const struct variable **dependent_var,
222 const struct xfactor *f);
227 /* Per Split function */
228 static void run_examine (struct cmd_examine *, struct casereader *,
231 static void output_examine (void);
234 void factor_calc (const struct ccase *c, int case_no,
235 double weight, bool case_missing);
238 /* Represent a factor as a string, so it can be
239 printed in a human readable fashion */
240 static void factor_to_string (const struct xfactor *fctr,
241 const struct factor_result *result,
244 /* Represent a factor as a string, so it can be
245 printed in a human readable fashion,
246 but sacrificing some readablility for the sake of brevity */
248 factor_to_string_concise (const struct xfactor *fctr,
249 const struct factor_result *result,
255 /* Categories of missing values to exclude. */
256 static enum mv_class exclude_values;
259 cmd_examine (struct lexer *lexer, struct dataset *ds)
261 struct casegrouper *grouper;
262 struct casereader *group;
265 subc_list_double_create (&percentile_list);
266 percentile_algorithm = PC_HAVERAGE;
268 if ( !parse_examine (lexer, ds, &cmd, NULL) )
270 subc_list_double_destroy (&percentile_list);
274 /* If /MISSING=INCLUDE is set, then user missing values are ignored */
275 exclude_values = cmd.incl == XMN_INCLUDE ? MV_SYSTEM : MV_ANY;
277 if ( cmd.st_n == SYSMIS )
280 if ( ! cmd.sbc_cinterval)
281 cmd.n_cinterval[0] = 95.0;
283 /* If descriptives have been requested, make sure the
284 quartiles are calculated */
285 if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES] )
287 subc_list_double_push (&percentile_list, 25);
288 subc_list_double_push (&percentile_list, 50);
289 subc_list_double_push (&percentile_list, 75);
292 grouper = casegrouper_create_splits (proc_open (ds), dataset_dict (ds));
294 while (casegrouper_get_next_group (grouper, &group))
296 struct casereader *reader =
297 casereader_create_arithmetic_sequence (group, 1, 1);
299 run_examine (&cmd, reader, ds);
302 ok = casegrouper_destroy (grouper);
303 ok = proc_commit (ds) && ok;
305 if ( dependent_vars )
306 free (dependent_vars);
308 subc_list_double_destroy (&percentile_list);
310 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
314 /* Plot the normal and detrended normal plots for RESULT.
315 Label the plots with LABEL */
317 np_plot (struct np *np, const char *label)
319 double yfirst = 0, ylast = 0;
326 struct chart *np_chart;
328 /* Detrended Normal Plot */
329 struct chart *dnp_chart;
331 /* The slope and intercept of the ideal normal probability line */
332 const double slope = 1.0 / np->stddev;
333 const double intercept = -np->mean / np->stddev;
337 msg (MW, _("Not creating plot because data set is empty."));
341 np_chart = chart_create ();
342 dnp_chart = chart_create ();
344 if ( !np_chart || ! dnp_chart )
347 chart_write_title (np_chart, _("Normal Q-Q Plot of %s"), label);
348 chart_write_xlabel (np_chart, _("Observed Value"));
349 chart_write_ylabel (np_chart, _("Expected Normal"));
351 chart_write_title (dnp_chart, _("Detrended Normal Q-Q Plot of %s"),
353 chart_write_xlabel (dnp_chart, _("Observed Value"));
354 chart_write_ylabel (dnp_chart, _("Dev from Normal"));
356 yfirst = gsl_cdf_ugaussian_Pinv (1 / (np->n + 1));
357 ylast = gsl_cdf_ugaussian_Pinv (np->n / (np->n + 1));
359 /* Need to make sure that both the scatter plot and the ideal fit into the
361 x_lower = MIN (np->y_min, (yfirst - intercept) / slope) ;
362 x_upper = MAX (np->y_max, (ylast - intercept) / slope) ;
363 slack = (x_upper - x_lower) * 0.05 ;
365 chart_write_xscale (np_chart, x_lower - slack, x_upper + slack, 5);
366 chart_write_xscale (dnp_chart, np->y_min, np->y_max, 5);
368 chart_write_yscale (np_chart, yfirst, ylast, 5);
369 chart_write_yscale (dnp_chart, np->dns_min, np->dns_max, 5);
372 struct casereader *reader = casewriter_make_reader (np->writer);
374 while ((c = casereader_read (reader)) != NULL)
376 chart_datum (np_chart, 0, case_data_idx (c, NP_IDX_Y)->f, case_data_idx (c, NP_IDX_NS)->f);
377 chart_datum (dnp_chart, 0, case_data_idx (c, NP_IDX_Y)->f, case_data_idx (c, NP_IDX_DNS)->f);
381 casereader_destroy (reader);
384 chart_line (dnp_chart, 0, 0, np->y_min, np->y_max , CHART_DIM_X);
385 chart_line (np_chart, slope, intercept, yfirst, ylast , CHART_DIM_Y);
387 chart_submit (np_chart);
388 chart_submit (dnp_chart);
393 show_npplot (const struct variable **dependent_var,
395 const struct xfactor *fctr)
399 for (v = 0; v < n_dep_var; ++v)
402 for (ll = ll_head (&fctr->result_list);
403 ll != ll_null (&fctr->result_list);
407 const struct factor_result *result =
408 ll_data (ll, struct factor_result, ll);
410 ds_init_empty (&str);
411 ds_put_format (&str, "%s ", var_get_name (dependent_var[v]));
413 factor_to_string (fctr, result, &str);
415 np_plot ((struct np*) result->metrics[v].np, ds_cstr(&str));
417 statistic_destroy ((struct statistic *)result->metrics[v].np);
426 show_histogram (const struct variable **dependent_var,
428 const struct xfactor *fctr)
432 for (v = 0; v < n_dep_var; ++v)
435 for (ll = ll_head (&fctr->result_list);
436 ll != ll_null (&fctr->result_list);
440 const struct factor_result *result =
441 ll_data (ll, struct factor_result, ll);
443 ds_init_empty (&str);
444 ds_put_format (&str, "%s ", var_get_name (dependent_var[v]));
446 factor_to_string (fctr, result, &str);
448 histogram_plot ((struct histogram *) result->metrics[v].histogram,
450 (struct moments1 *) result->metrics[v].moments);
460 show_boxplot_groups (const struct variable **dependent_var,
462 const struct xfactor *fctr)
466 for (v = 0; v < n_dep_var; ++v)
470 struct chart *ch = chart_create ();
471 double y_min = DBL_MAX;
472 double y_max = -DBL_MAX;
474 for (ll = ll_head (&fctr->result_list);
475 ll != ll_null (&fctr->result_list);
478 const struct extremum *max, *min;
479 const struct factor_result *result =
480 ll_data (ll, struct factor_result, ll);
482 const struct ll_list *max_list =
483 extrema_list (result->metrics[v].maxima);
485 const struct ll_list *min_list =
486 extrema_list (result->metrics[v].minima);
488 if ( ll_is_empty (max_list))
490 msg (MW, _("Not creating plot because data set is empty."));
494 max = (const struct extremum *)
495 ll_data (ll_head(max_list), struct extremum, ll);
497 min = (const struct extremum *)
498 ll_data (ll_head (min_list), struct extremum, ll);
500 y_max = MAX (y_max, max->value);
501 y_min = MIN (y_min, min->value);
504 boxplot_draw_yscale (ch, y_max, y_min);
506 if ( fctr->indep_var[0])
507 chart_write_title (ch, _("Boxplot of %s vs. %s"),
508 var_to_string (dependent_var[v]),
509 var_to_string (fctr->indep_var[0]) );
511 chart_write_title (ch, _("Boxplot of %s"),
512 var_to_string (dependent_var[v]));
514 for (ll = ll_head (&fctr->result_list);
515 ll != ll_null (&fctr->result_list);
518 const struct factor_result *result =
519 ll_data (ll, struct factor_result, ll);
522 const double box_width = (ch->data_right - ch->data_left)
523 / (ll_count (&fctr->result_list) * 2.0 ) ;
525 const double box_centre = (f++ * 2 + 1) * box_width + ch->data_left;
527 ds_init_empty (&str);
528 factor_to_string_concise (fctr, result, &str);
530 boxplot_draw_boxplot (ch,
531 box_centre, box_width,
532 (const struct box_whisker *)
533 result->metrics[v].box_whisker,
546 show_boxplot_variables (const struct variable **dependent_var,
548 const struct xfactor *fctr
554 const struct ll_list *result_list = &fctr->result_list;
556 for (ll = ll_head (result_list);
557 ll != ll_null (result_list);
562 struct chart *ch = chart_create ();
563 double y_min = DBL_MAX;
564 double y_max = -DBL_MAX;
566 const struct factor_result *result =
567 ll_data (ll, struct factor_result, ll);
569 const double box_width = (ch->data_right - ch->data_left)
570 / (n_dep_var * 2.0 ) ;
572 for (v = 0; v < n_dep_var; ++v)
574 const struct ll *max_ll =
575 ll_head (extrema_list (result->metrics[v].maxima));
576 const struct ll *min_ll =
577 ll_head (extrema_list (result->metrics[v].minima));
579 const struct extremum *max =
580 (const struct extremum *) ll_data (max_ll, struct extremum, ll);
582 const struct extremum *min =
583 (const struct extremum *) ll_data (min_ll, struct extremum, ll);
585 y_max = MAX (y_max, max->value);
586 y_min = MIN (y_min, min->value);
590 boxplot_draw_yscale (ch, y_max, y_min);
592 ds_init_empty (&title);
593 factor_to_string (fctr, result, &title);
596 ds_put_format (&title, "%s = ", var_get_name (fctr->indep_var[0]));
597 var_append_value_name (fctr->indep_var[0], result->value[0], &title);
600 chart_write_title (ch, ds_cstr (&title));
603 for (v = 0; v < n_dep_var; ++v)
606 const double box_centre = (v * 2 + 1) * box_width + ch->data_left;
608 ds_init_empty (&str);
609 ds_init_cstr (&str, var_get_name (dependent_var[v]));
611 boxplot_draw_boxplot (ch,
612 box_centre, box_width,
613 (const struct box_whisker *) result->metrics[v].box_whisker,
624 /* Show all the appropriate tables */
626 output_examine (void)
630 show_summary (dependent_vars, n_dependent_vars, &level0_factor);
632 if ( cmd.a_statistics[XMN_ST_EXTREME] )
633 show_extremes (dependent_vars, n_dependent_vars, &level0_factor);
635 if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES] )
636 show_descriptives (dependent_vars, n_dependent_vars, &level0_factor);
638 if ( cmd.sbc_percentiles)
639 show_percentiles (dependent_vars, n_dependent_vars, &level0_factor);
643 if (cmd.a_plot[XMN_PLT_BOXPLOT])
644 show_boxplot_groups (dependent_vars, n_dependent_vars, &level0_factor);
646 if (cmd.a_plot[XMN_PLT_HISTOGRAM])
647 show_histogram (dependent_vars, n_dependent_vars, &level0_factor);
649 if (cmd.a_plot[XMN_PLT_NPPLOT])
650 show_npplot (dependent_vars, n_dependent_vars, &level0_factor);
653 for (ll = ll_head (&factor_list);
654 ll != ll_null (&factor_list); ll = ll_next (ll))
656 struct xfactor *factor = ll_data (ll, struct xfactor, ll);
657 show_summary (dependent_vars, n_dependent_vars, factor);
659 if ( cmd.a_statistics[XMN_ST_EXTREME] )
660 show_extremes (dependent_vars, n_dependent_vars, factor);
662 if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES] )
663 show_descriptives (dependent_vars, n_dependent_vars, factor);
665 if ( cmd.sbc_percentiles)
666 show_percentiles (dependent_vars, n_dependent_vars, factor);
668 if (cmd.a_plot[XMN_PLT_BOXPLOT] &&
669 cmd.cmp == XMN_GROUPS)
670 show_boxplot_groups (dependent_vars, n_dependent_vars, factor);
673 if (cmd.a_plot[XMN_PLT_BOXPLOT] &&
674 cmd.cmp == XMN_VARIABLES)
675 show_boxplot_variables (dependent_vars, n_dependent_vars,
678 if (cmd.a_plot[XMN_PLT_HISTOGRAM])
679 show_histogram (dependent_vars, n_dependent_vars, factor);
681 if (cmd.a_plot[XMN_PLT_NPPLOT])
682 show_npplot (dependent_vars, n_dependent_vars, factor);
686 /* Parse the PERCENTILES subcommand */
688 xmn_custom_percentiles (struct lexer *lexer, struct dataset *ds UNUSED,
689 struct cmd_examine *p UNUSED, void *aux UNUSED)
691 lex_match (lexer, '=');
693 lex_match (lexer, '(');
695 while ( lex_is_number (lexer) )
697 subc_list_double_push (&percentile_list, lex_number (lexer));
701 lex_match (lexer, ',') ;
703 lex_match (lexer, ')');
705 lex_match (lexer, '=');
707 if ( lex_match_id (lexer, "HAVERAGE"))
708 percentile_algorithm = PC_HAVERAGE;
710 else if ( lex_match_id (lexer, "WAVERAGE"))
711 percentile_algorithm = PC_WAVERAGE;
713 else if ( lex_match_id (lexer, "ROUND"))
714 percentile_algorithm = PC_ROUND;
716 else if ( lex_match_id (lexer, "EMPIRICAL"))
717 percentile_algorithm = PC_EMPIRICAL;
719 else if ( lex_match_id (lexer, "AEMPIRICAL"))
720 percentile_algorithm = PC_AEMPIRICAL;
722 else if ( lex_match_id (lexer, "NONE"))
723 percentile_algorithm = PC_NONE;
726 if ( 0 == subc_list_double_count (&percentile_list))
728 subc_list_double_push (&percentile_list, 5);
729 subc_list_double_push (&percentile_list, 10);
730 subc_list_double_push (&percentile_list, 25);
731 subc_list_double_push (&percentile_list, 50);
732 subc_list_double_push (&percentile_list, 75);
733 subc_list_double_push (&percentile_list, 90);
734 subc_list_double_push (&percentile_list, 95);
740 /* TOTAL and NOTOTAL are simple, mutually exclusive flags */
742 xmn_custom_total (struct lexer *lexer UNUSED, struct dataset *ds UNUSED,
743 struct cmd_examine *p, void *aux UNUSED)
745 if ( p->sbc_nototal )
747 msg (SE, _("%s and %s are mutually exclusive"),"TOTAL","NOTOTAL");
755 xmn_custom_nototal (struct lexer *lexer UNUSED, struct dataset *ds UNUSED,
756 struct cmd_examine *p, void *aux UNUSED)
760 msg (SE, _("%s and %s are mutually exclusive"), "TOTAL", "NOTOTAL");
769 /* Parser for the variables sub command
770 Returns 1 on success */
772 xmn_custom_variables (struct lexer *lexer, struct dataset *ds,
773 struct cmd_examine *cmd,
776 const struct dictionary *dict = dataset_dict (ds);
777 lex_match (lexer, '=');
779 if ( (lex_token (lexer) != T_ID || dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
780 && lex_token (lexer) != T_ALL)
785 if (!parse_variables_const (lexer, dict, &dependent_vars, &n_dependent_vars,
786 PV_NO_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH) )
788 free (dependent_vars);
792 assert (n_dependent_vars);
795 if ( lex_match (lexer, T_BY))
798 success = examine_parse_independent_vars (lexer, dict, cmd);
801 free (dependent_vars);
811 /* Parse the clause specifying the factors */
813 examine_parse_independent_vars (struct lexer *lexer,
814 const struct dictionary *dict,
815 struct cmd_examine *cmd)
818 struct xfactor *sf = xmalloc (sizeof *sf);
820 ll_init (&sf->result_list);
822 if ( (lex_token (lexer) != T_ID ||
823 dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
824 && lex_token (lexer) != T_ALL)
830 sf->indep_var[0] = parse_variable (lexer, dict);
831 sf->indep_var[1] = NULL;
833 if ( lex_token (lexer) == T_BY )
835 lex_match (lexer, T_BY);
837 if ( (lex_token (lexer) != T_ID ||
838 dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
839 && lex_token (lexer) != T_ALL)
845 sf->indep_var[1] = parse_variable (lexer, dict);
847 ll_push_tail (&factor_list, &sf->ll);
850 ll_push_tail (&factor_list, &sf->ll);
852 lex_match (lexer, ',');
854 if ( lex_token (lexer) == '.' || lex_token (lexer) == '/' )
857 success = examine_parse_independent_vars (lexer, dict, cmd);
866 examine_group (struct cmd_examine *cmd, struct casereader *reader, int level,
867 const struct dictionary *dict, struct xfactor *factor)
870 const struct variable *wv = dict_get_weight (dict);
873 struct factor_result *result = xzalloc (sizeof (*result));
875 result->metrics = xcalloc (n_dependent_vars, sizeof (*result->metrics));
877 if ( cmd->a_statistics[XMN_ST_EXTREME] )
878 n_extrema = cmd->st_n;
881 c = casereader_peek (reader, 0);
887 value_dup (case_data (c, factor->indep_var[0]),
888 var_get_width (factor->indep_var[0]));
892 value_dup (case_data (c, factor->indep_var[1]),
893 var_get_width (factor->indep_var[1]));
898 for (v = 0; v < n_dependent_vars; ++v)
900 struct casewriter *writer;
901 struct casereader *input = casereader_clone (reader);
903 result->metrics[v].moments = moments1_create (MOMENT_KURTOSIS);
904 result->metrics[v].minima = extrema_create (n_extrema, EXTREME_MINIMA);
905 result->metrics[v].maxima = extrema_create (n_extrema, EXTREME_MAXIMA);
906 result->metrics[v].cmin = DBL_MAX;
908 if (cmd->a_statistics[XMN_ST_DESCRIPTIVES] ||
909 cmd->a_plot[XMN_PLT_BOXPLOT] ||
910 cmd->a_plot[XMN_PLT_NPPLOT] ||
911 cmd->sbc_percentiles)
913 /* In this case, we need to sort the data, so we create a sorting
915 struct subcase up_ordering;
916 subcase_init_var (&up_ordering, dependent_vars[v], SC_ASCEND);
917 writer = sort_create_writer (&up_ordering,
918 casereader_get_value_cnt (reader));
919 subcase_destroy (&up_ordering);
923 /* but in this case, sorting is unnecessary, so an ordinary
924 casewriter is sufficient */
926 autopaging_writer_create (casereader_get_value_cnt (reader));
930 /* Sort or just iterate, whilst calculating moments etc */
931 while ((c = casereader_read (input)) != NULL)
933 const casenumber loc =
934 case_data_idx (c, casereader_get_value_cnt (reader) - 1)->f;
936 const double weight = wv ? case_data (c, wv)->f : 1.0;
938 if (weight != SYSMIS)
939 minimize (&result->metrics[v].cmin, weight);
941 moments1_add (result->metrics[v].moments,
942 case_data (c, dependent_vars[v])->f,
945 result->metrics[v].n += weight;
947 extrema_add (result->metrics[v].maxima,
948 case_data (c, dependent_vars[v])->f,
952 extrema_add (result->metrics[v].minima,
953 case_data (c, dependent_vars[v])->f,
957 casewriter_write (writer, c);
959 casereader_destroy (input);
960 result->metrics[v].up_reader = casewriter_make_reader (writer);
963 /* If percentiles or descriptives have been requested, then a
964 second pass through the data (which has now been sorted)
966 if ( cmd->a_statistics[XMN_ST_DESCRIPTIVES] ||
967 cmd->a_plot[XMN_PLT_BOXPLOT] ||
968 cmd->a_plot[XMN_PLT_NPPLOT] ||
969 cmd->sbc_percentiles)
971 for (v = 0; v < n_dependent_vars; ++v)
975 struct order_stats **os ;
976 struct factor_metrics *metric = &result->metrics[v];
978 metric->n_ptiles = percentile_list.n_data;
980 metric->ptl = xcalloc (metric->n_ptiles,
981 sizeof (struct percentile *));
983 metric->quartiles = xcalloc (3, sizeof (*metric->quartiles));
985 for (i = 0 ; i < metric->n_ptiles; ++i)
987 metric->ptl[i] = (struct percentile *)
988 percentile_create (percentile_list.data[i] / 100.0, metric->n);
990 if ( percentile_list.data[i] == 25)
991 metric->quartiles[0] = metric->ptl[i];
992 else if ( percentile_list.data[i] == 50)
993 metric->quartiles[1] = metric->ptl[i];
994 else if ( percentile_list.data[i] == 75)
995 metric->quartiles[2] = metric->ptl[i];
998 metric->tukey_hinges = tukey_hinges_create (metric->n, metric->cmin);
999 metric->trimmed_mean = trimmed_mean_create (metric->n, 0.05);
1001 n_os = metric->n_ptiles + 2;
1003 if ( cmd->a_plot[XMN_PLT_NPPLOT] )
1005 metric->np = np_create (metric->moments);
1009 os = xcalloc (sizeof (struct order_stats *), n_os);
1011 for (i = 0 ; i < metric->n_ptiles ; ++i )
1013 os[i] = (struct order_stats *) metric->ptl[i];
1016 os[i] = (struct order_stats *) metric->tukey_hinges;
1017 os[i+1] = (struct order_stats *) metric->trimmed_mean;
1019 if (cmd->a_plot[XMN_PLT_NPPLOT])
1020 os[i+2] = metric->np;
1022 order_stats_accumulate (os, n_os,
1023 casereader_clone (metric->up_reader),
1024 wv, dependent_vars[v], MV_ANY);
1029 /* FIXME: Do this in the above loop */
1030 if ( cmd->a_plot[XMN_PLT_HISTOGRAM] )
1033 struct casereader *input = casereader_clone (reader);
1035 for (v = 0; v < n_dependent_vars; ++v)
1037 const struct extremum *max, *min;
1038 struct factor_metrics *metric = &result->metrics[v];
1040 const struct ll_list *max_list =
1041 extrema_list (result->metrics[v].maxima);
1043 const struct ll_list *min_list =
1044 extrema_list (result->metrics[v].minima);
1046 if ( ll_is_empty (max_list))
1048 msg (MW, _("Not creating plot because data set is empty."));
1052 assert (! ll_is_empty (min_list));
1054 max = (const struct extremum *)
1055 ll_data (ll_head(max_list), struct extremum, ll);
1057 min = (const struct extremum *)
1058 ll_data (ll_head (min_list), struct extremum, ll);
1060 metric->histogram = histogram_create (10, min->value, max->value);
1063 while ((c = casereader_read (input)) != NULL)
1065 const double weight = wv ? case_data (c, wv)->f : 1.0;
1067 for (v = 0; v < n_dependent_vars; ++v)
1069 struct factor_metrics *metric = &result->metrics[v];
1070 if ( metric->histogram)
1071 histogram_add ((struct histogram *) metric->histogram,
1072 case_data (c, dependent_vars[v])->f, weight);
1076 casereader_destroy (input);
1079 /* In this case, a third iteration is required */
1080 if (cmd->a_plot[XMN_PLT_BOXPLOT])
1082 for (v = 0; v < n_dependent_vars; ++v)
1084 struct factor_metrics *metric = &result->metrics[v];
1086 metric->box_whisker =
1087 box_whisker_create ((struct tukey_hinges *) metric->tukey_hinges,
1089 casereader_get_value_cnt (metric->up_reader)
1092 order_stats_accumulate ((struct order_stats **) &metric->box_whisker,
1094 casereader_clone (metric->up_reader),
1095 wv, dependent_vars[v], MV_ANY);
1099 ll_push_tail (&factor->result_list, &result->ll);
1100 casereader_destroy (reader);
1105 run_examine (struct cmd_examine *cmd, struct casereader *input,
1109 const struct dictionary *dict = dataset_dict (ds);
1111 struct casereader *level0 = casereader_clone (input);
1113 c = casereader_peek (input, 0);
1116 casereader_destroy (input);
1120 output_split_file_values (ds, c);
1123 ll_init (&level0_factor.result_list);
1125 examine_group (cmd, level0, 0, dict, &level0_factor);
1127 for (ll = ll_head (&factor_list);
1128 ll != ll_null (&factor_list);
1131 struct xfactor *factor = ll_data (ll, struct xfactor, ll);
1133 struct casereader *group = NULL;
1134 struct casereader *level1;
1135 struct casegrouper *grouper1 = NULL;
1137 level1 = casereader_clone (input);
1138 level1 = sort_execute_1var (level1, factor->indep_var[0]);
1139 grouper1 = casegrouper_create_vars (level1, &factor->indep_var[0], 1);
1141 while (casegrouper_get_next_group (grouper1, &group))
1143 struct casereader *group_copy = casereader_clone (group);
1145 if ( !factor->indep_var[1])
1146 examine_group (cmd, group_copy, 1, dict, factor);
1150 struct casereader *group2 = NULL;
1151 struct casegrouper *grouper2 = NULL;
1153 group_copy = sort_execute_1var (group_copy,
1154 factor->indep_var[1]);
1156 grouper2 = casegrouper_create_vars (group_copy,
1157 &factor->indep_var[1], 1);
1159 while (casegrouper_get_next_group (grouper2, &group2))
1161 examine_group (cmd, group2, 2, dict, factor);
1164 casegrouper_destroy (grouper2);
1167 casereader_destroy (group);
1169 casegrouper_destroy (grouper1);
1172 casereader_destroy (input);
1176 factor_destroy (&level0_factor);
1180 for (ll = ll_head (&factor_list);
1181 ll != ll_null (&factor_list);
1184 struct xfactor *f = ll_data (ll, struct xfactor, ll);
1193 show_summary (const struct variable **dependent_var, int n_dep_var,
1194 const struct xfactor *fctr)
1196 static const char *subtitle[]=
1204 int heading_columns = 1;
1206 const int heading_rows = 3;
1207 struct tab_table *tbl;
1214 if ( fctr->indep_var[0] )
1216 heading_columns = 2;
1218 if ( fctr->indep_var[1] )
1220 heading_columns = 3;
1224 n_rows *= ll_count (&fctr->result_list);
1225 n_rows += heading_rows;
1227 n_cols = heading_columns + 6;
1229 tbl = tab_create (n_cols, n_rows, 0);
1230 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1232 tab_dim (tbl, tab_natural_dimensions);
1234 /* Outline the box */
1239 n_cols - 1, n_rows - 1);
1241 /* Vertical lines for the data only */
1246 n_cols - 1, n_rows - 1);
1249 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1250 tab_hline (tbl, TAL_1, heading_columns, n_cols - 1, 1 );
1251 tab_hline (tbl, TAL_1, heading_columns, n_cols - 1, heading_rows -1 );
1253 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1256 tab_title (tbl, _("Case Processing Summary"));
1258 tab_joint_text (tbl, heading_columns, 0,
1260 TAB_CENTER | TAT_TITLE,
1263 /* Remove lines ... */
1270 for (j = 0 ; j < 3 ; ++j)
1272 tab_text (tbl, heading_columns + j * 2 , 2, TAB_CENTER | TAT_TITLE,
1275 tab_text (tbl, heading_columns + j * 2 + 1, 2, TAB_CENTER | TAT_TITLE,
1278 tab_joint_text (tbl, heading_columns + j * 2 , 1,
1279 heading_columns + j * 2 + 1, 1,
1280 TAB_CENTER | TAT_TITLE,
1283 tab_box (tbl, -1, -1,
1285 heading_columns + j * 2, 1,
1286 heading_columns + j * 2 + 1, 1);
1290 /* Titles for the independent variables */
1291 if ( fctr->indep_var[0] )
1293 tab_text (tbl, 1, heading_rows - 1, TAB_CENTER | TAT_TITLE,
1294 var_to_string (fctr->indep_var[0]));
1296 if ( fctr->indep_var[1] )
1298 tab_text (tbl, 2, heading_rows - 1, TAB_CENTER | TAT_TITLE,
1299 var_to_string (fctr->indep_var[1]));
1303 for (v = 0 ; v < n_dep_var ; ++v)
1307 union value *last_value = NULL;
1310 tab_hline (tbl, TAL_1, 0, n_cols -1 ,
1311 v * ll_count (&fctr->result_list)
1316 v * ll_count (&fctr->result_list) + heading_rows,
1317 TAB_LEFT | TAT_TITLE,
1318 var_to_string (dependent_var[v])
1322 for (ll = ll_head (&fctr->result_list);
1323 ll != ll_null (&fctr->result_list); ll = ll_next (ll))
1326 const struct factor_result *result =
1327 ll_data (ll, struct factor_result, ll);
1329 if ( fctr->indep_var[0] )
1332 if ( last_value == NULL ||
1333 compare_values_short (last_value, result->value[0],
1334 fctr->indep_var[0]))
1338 last_value = result->value[0];
1339 ds_init_empty (&str);
1341 var_append_value_name (fctr->indep_var[0], result->value[0],
1346 v * ll_count (&fctr->result_list),
1347 TAB_LEFT | TAT_TITLE,
1352 if ( fctr->indep_var[1] && j > 0)
1353 tab_hline (tbl, TAL_1, 1, n_cols - 1,
1355 v * ll_count (&fctr->result_list));
1358 if ( fctr->indep_var[1])
1362 ds_init_empty (&str);
1364 var_append_value_name (fctr->indep_var[1],
1365 result->value[1], &str);
1369 v * ll_count (&fctr->result_list),
1370 TAB_LEFT | TAT_TITLE,
1378 moments1_calculate (result->metrics[v].moments,
1379 &n, &result->metrics[v].mean,
1380 &result->metrics[v].variance,
1381 &result->metrics[v].skewness,
1382 &result->metrics[v].kurtosis);
1384 result->metrics[v].se_mean = sqrt (result->metrics[v].variance / n) ;
1387 tab_float (tbl, heading_columns,
1388 heading_rows + j + v * ll_count (&fctr->result_list),
1392 tab_text (tbl, heading_columns + 1,
1393 heading_rows + j + v * ll_count (&fctr->result_list),
1394 TAB_RIGHT | TAT_PRINTF,
1395 "%g%%", n * 100.0 / result->metrics[v].n);
1398 tab_float (tbl, heading_columns + 2,
1399 heading_rows + j + v * ll_count (&fctr->result_list),
1401 result->metrics[v].n - n,
1404 tab_text (tbl, heading_columns + 3,
1405 heading_rows + j + v * ll_count (&fctr->result_list),
1406 TAB_RIGHT | TAT_PRINTF,
1408 (result->metrics[v].n - n) * 100.0 / result->metrics[v].n
1411 /* Total Valid + Missing */
1412 tab_float (tbl, heading_columns + 4,
1413 heading_rows + j + v * ll_count (&fctr->result_list),
1415 result->metrics[v].n,
1418 tab_text (tbl, heading_columns + 5,
1419 heading_rows + j + v * ll_count (&fctr->result_list),
1420 TAB_RIGHT | TAT_PRINTF,
1422 (result->metrics[v].n) * 100.0 / result->metrics[v].n
1433 #define DESCRIPTIVE_ROWS 13
1436 show_descriptives (const struct variable **dependent_var,
1438 const struct xfactor *fctr)
1441 int heading_columns = 3;
1443 const int heading_rows = 1;
1444 struct tab_table *tbl;
1451 if ( fctr->indep_var[0] )
1453 heading_columns = 4;
1455 if ( fctr->indep_var[1] )
1457 heading_columns = 5;
1461 n_rows *= ll_count (&fctr->result_list) * DESCRIPTIVE_ROWS;
1462 n_rows += heading_rows;
1464 n_cols = heading_columns + 2;
1466 tbl = tab_create (n_cols, n_rows, 0);
1467 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1469 tab_dim (tbl, tab_natural_dimensions);
1471 /* Outline the box */
1476 n_cols - 1, n_rows - 1);
1479 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1480 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
1482 tab_vline (tbl, TAL_1, n_cols - 1, 0, n_rows - 1);
1485 if ( fctr->indep_var[0])
1486 tab_text (tbl, 1, 0, TAT_TITLE, var_to_string (fctr->indep_var[0]));
1488 if ( fctr->indep_var[1])
1489 tab_text (tbl, 2, 0, TAT_TITLE, var_to_string (fctr->indep_var[1]));
1491 for (v = 0 ; v < n_dep_var ; ++v )
1496 const int row_var_start =
1497 v * DESCRIPTIVE_ROWS * ll_count(&fctr->result_list);
1501 heading_rows + row_var_start,
1502 TAB_LEFT | TAT_TITLE,
1503 var_to_string (dependent_var[v])
1506 for (ll = ll_head (&fctr->result_list);
1507 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
1509 const struct factor_result *result =
1510 ll_data (ll, struct factor_result, ll);
1513 gsl_cdf_tdist_Qinv ((1 - cmd.n_cinterval[0] / 100.0) / 2.0,
1514 result->metrics[v].n - 1);
1516 if ( i > 0 || v > 0 )
1518 const int left_col = (i == 0) ? 0 : 1;
1519 tab_hline (tbl, TAL_1, left_col, n_cols - 1,
1520 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS);
1523 if ( fctr->indep_var[0])
1526 ds_init_empty (&vstr);
1527 var_append_value_name (fctr->indep_var[0],
1528 result->value[0], &vstr);
1531 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1540 tab_text (tbl, n_cols - 4,
1541 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1545 tab_text (tbl, n_cols - 4,
1546 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1547 TAB_LEFT | TAT_PRINTF,
1548 _("%g%% Confidence Interval for Mean"),
1549 cmd.n_cinterval[0]);
1551 tab_text (tbl, n_cols - 3,
1552 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1556 tab_text (tbl, n_cols - 3,
1557 heading_rows + row_var_start + 2 + i * DESCRIPTIVE_ROWS,
1561 tab_text (tbl, n_cols - 4,
1562 heading_rows + row_var_start + 3 + i * DESCRIPTIVE_ROWS,
1563 TAB_LEFT | TAT_PRINTF,
1564 _("5%% Trimmed Mean"));
1566 tab_text (tbl, n_cols - 4,
1567 heading_rows + row_var_start + 4 + i * DESCRIPTIVE_ROWS,
1571 tab_text (tbl, n_cols - 4,
1572 heading_rows + row_var_start + 5 + i * DESCRIPTIVE_ROWS,
1576 tab_text (tbl, n_cols - 4,
1577 heading_rows + row_var_start + 6 + i * DESCRIPTIVE_ROWS,
1579 _("Std. Deviation"));
1581 tab_text (tbl, n_cols - 4,
1582 heading_rows + row_var_start + 7 + i * DESCRIPTIVE_ROWS,
1586 tab_text (tbl, n_cols - 4,
1587 heading_rows + row_var_start + 8 + i * DESCRIPTIVE_ROWS,
1591 tab_text (tbl, n_cols - 4,
1592 heading_rows + row_var_start + 9 + i * DESCRIPTIVE_ROWS,
1596 tab_text (tbl, n_cols - 4,
1597 heading_rows + row_var_start + 10 + i * DESCRIPTIVE_ROWS,
1599 _("Interquartile Range"));
1602 tab_text (tbl, n_cols - 4,
1603 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1607 tab_text (tbl, n_cols - 4,
1608 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1613 /* Now the statistics ... */
1615 tab_float (tbl, n_cols - 2,
1616 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1618 result->metrics[v].mean,
1621 tab_float (tbl, n_cols - 1,
1622 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1624 result->metrics[v].se_mean,
1628 tab_float (tbl, n_cols - 2,
1629 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1631 result->metrics[v].mean - t *
1632 result->metrics[v].se_mean,
1635 tab_float (tbl, n_cols - 2,
1636 heading_rows + row_var_start + 2 + i * DESCRIPTIVE_ROWS,
1638 result->metrics[v].mean + t *
1639 result->metrics[v].se_mean,
1643 tab_float (tbl, n_cols - 2,
1644 heading_rows + row_var_start + 3 + i * DESCRIPTIVE_ROWS,
1646 trimmed_mean_calculate ((struct trimmed_mean *) result->metrics[v].trimmed_mean),
1650 tab_float (tbl, n_cols - 2,
1651 heading_rows + row_var_start + 4 + i * DESCRIPTIVE_ROWS,
1653 percentile_calculate (result->metrics[v].quartiles[1], percentile_algorithm),
1657 tab_float (tbl, n_cols - 2,
1658 heading_rows + row_var_start + 5 + i * DESCRIPTIVE_ROWS,
1660 result->metrics[v].variance,
1663 tab_float (tbl, n_cols - 2,
1664 heading_rows + row_var_start + 6 + i * DESCRIPTIVE_ROWS,
1666 sqrt (result->metrics[v].variance),
1669 tab_float (tbl, n_cols - 2,
1670 heading_rows + row_var_start + 10 + i * DESCRIPTIVE_ROWS,
1672 percentile_calculate (result->metrics[v].quartiles[2],
1673 percentile_algorithm) -
1674 percentile_calculate (result->metrics[v].quartiles[0],
1675 percentile_algorithm),
1679 tab_float (tbl, n_cols - 2,
1680 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1682 result->metrics[v].skewness,
1685 tab_float (tbl, n_cols - 2,
1686 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1688 result->metrics[v].kurtosis,
1691 tab_float (tbl, n_cols - 1,
1692 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1694 calc_seskew (result->metrics[v].n),
1697 tab_float (tbl, n_cols - 1,
1698 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1700 calc_sekurt (result->metrics[v].n),
1704 struct extremum *minimum, *maximum ;
1706 struct ll *max_ll = ll_head (extrema_list (result->metrics[v].maxima));
1707 struct ll *min_ll = ll_head (extrema_list (result->metrics[v].minima));
1709 maximum = ll_data (max_ll, struct extremum, ll);
1710 minimum = ll_data (min_ll, struct extremum, ll);
1712 tab_float (tbl, n_cols - 2,
1713 heading_rows + row_var_start + 7 + i * DESCRIPTIVE_ROWS,
1718 tab_float (tbl, n_cols - 2,
1719 heading_rows + row_var_start + 8 + i * DESCRIPTIVE_ROWS,
1724 tab_float (tbl, n_cols - 2,
1725 heading_rows + row_var_start + 9 + i * DESCRIPTIVE_ROWS,
1727 maximum->value - minimum->value,
1733 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1735 tab_title (tbl, _("Descriptives"));
1737 tab_text (tbl, n_cols - 2, 0, TAB_CENTER | TAT_TITLE,
1740 tab_text (tbl, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
1749 show_extremes (const struct variable **dependent_var,
1751 const struct xfactor *fctr)
1754 int heading_columns = 3;
1756 const int heading_rows = 1;
1757 struct tab_table *tbl;
1764 if ( fctr->indep_var[0] )
1766 heading_columns = 4;
1768 if ( fctr->indep_var[1] )
1770 heading_columns = 5;
1774 n_rows *= ll_count (&fctr->result_list) * cmd.st_n * 2;
1775 n_rows += heading_rows;
1777 n_cols = heading_columns + 2;
1779 tbl = tab_create (n_cols, n_rows, 0);
1780 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1782 tab_dim (tbl, tab_natural_dimensions);
1784 /* Outline the box */
1789 n_cols - 1, n_rows - 1);
1792 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1793 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
1794 tab_vline (tbl, TAL_1, n_cols - 1, 0, n_rows - 1);
1796 if ( fctr->indep_var[0])
1797 tab_text (tbl, 1, 0, TAT_TITLE, var_to_string (fctr->indep_var[0]));
1799 if ( fctr->indep_var[1])
1800 tab_text (tbl, 2, 0, TAT_TITLE, var_to_string (fctr->indep_var[1]));
1802 for (v = 0 ; v < n_dep_var ; ++v )
1806 const int row_var_start = v * cmd.st_n * 2 * ll_count(&fctr->result_list);
1810 heading_rows + row_var_start,
1811 TAB_LEFT | TAT_TITLE,
1812 var_to_string (dependent_var[v])
1815 for (ll = ll_head (&fctr->result_list);
1816 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
1821 const int row_result_start = i * cmd.st_n * 2;
1823 const struct factor_result *result =
1824 ll_data (ll, struct factor_result, ll);
1827 tab_hline (tbl, TAL_1, 1, n_cols - 1,
1828 heading_rows + row_var_start + row_result_start);
1830 tab_hline (tbl, TAL_1, heading_columns - 2, n_cols - 1,
1831 heading_rows + row_var_start + row_result_start + cmd.st_n);
1833 for ( e = 1; e <= cmd.st_n; ++e )
1835 tab_text (tbl, n_cols - 3,
1836 heading_rows + row_var_start + row_result_start + e - 1,
1837 TAB_RIGHT | TAT_PRINTF,
1840 tab_text (tbl, n_cols - 3,
1841 heading_rows + row_var_start + row_result_start + cmd.st_n + e - 1,
1842 TAB_RIGHT | TAT_PRINTF,
1847 min_ll = ll_head (extrema_list (result->metrics[v].minima));
1848 for (e = 0; e < cmd.st_n;)
1850 struct extremum *minimum = ll_data (min_ll, struct extremum, ll);
1851 double weight = minimum->weight;
1853 while (weight-- > 0 && e < cmd.st_n)
1855 tab_float (tbl, n_cols - 1,
1856 heading_rows + row_var_start + row_result_start + cmd.st_n + e,
1862 tab_float (tbl, n_cols - 2,
1863 heading_rows + row_var_start + row_result_start + cmd.st_n + e,
1870 min_ll = ll_next (min_ll);
1874 max_ll = ll_head (extrema_list (result->metrics[v].maxima));
1875 for (e = 0; e < cmd.st_n;)
1877 struct extremum *maximum = ll_data (max_ll, struct extremum, ll);
1878 double weight = maximum->weight;
1880 while (weight-- > 0 && e < cmd.st_n)
1882 tab_float (tbl, n_cols - 1,
1883 heading_rows + row_var_start + row_result_start + e,
1889 tab_float (tbl, n_cols - 2,
1890 heading_rows + row_var_start + row_result_start + e,
1897 max_ll = ll_next (max_ll);
1901 if ( fctr->indep_var[0])
1904 ds_init_empty (&vstr);
1905 var_append_value_name (fctr->indep_var[0],
1906 result->value[0], &vstr);
1909 heading_rows + row_var_start + row_result_start,
1918 tab_text (tbl, n_cols - 4,
1919 heading_rows + row_var_start + row_result_start,
1923 tab_text (tbl, n_cols - 4,
1924 heading_rows + row_var_start + row_result_start + cmd.st_n,
1930 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1933 tab_title (tbl, _("Extreme Values"));
1936 tab_text (tbl, n_cols - 2, 0, TAB_CENTER | TAT_TITLE,
1940 tab_text (tbl, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
1946 #define PERCENTILE_ROWS 2
1949 show_percentiles (const struct variable **dependent_var,
1951 const struct xfactor *fctr)
1955 int heading_columns = 2;
1957 const int n_percentiles = subc_list_double_count (&percentile_list);
1958 const int heading_rows = 2;
1959 struct tab_table *tbl;
1966 if ( fctr->indep_var[0] )
1968 heading_columns = 3;
1970 if ( fctr->indep_var[1] )
1972 heading_columns = 4;
1976 n_rows *= ll_count (&fctr->result_list) * PERCENTILE_ROWS;
1977 n_rows += heading_rows;
1979 n_cols = heading_columns + n_percentiles;
1981 tbl = tab_create (n_cols, n_rows, 0);
1982 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1984 tab_dim (tbl, tab_natural_dimensions);
1986 /* Outline the box */
1991 n_cols - 1, n_rows - 1);
1994 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1995 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
1997 if ( fctr->indep_var[0])
1998 tab_text (tbl, 1, 1, TAT_TITLE, var_to_string (fctr->indep_var[0]));
2000 if ( fctr->indep_var[1])
2001 tab_text (tbl, 2, 1, TAT_TITLE, var_to_string (fctr->indep_var[1]));
2003 for (v = 0 ; v < n_dep_var ; ++v )
2009 const int row_var_start =
2010 v * PERCENTILE_ROWS * ll_count(&fctr->result_list);
2014 heading_rows + row_var_start,
2015 TAB_LEFT | TAT_TITLE,
2016 var_to_string (dependent_var[v])
2019 for (ll = ll_head (&fctr->result_list);
2020 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
2023 const struct factor_result *result =
2024 ll_data (ll, struct factor_result, ll);
2026 if ( i > 0 || v > 0 )
2028 const int left_col = (i == 0) ? 0 : 1;
2029 tab_hline (tbl, TAL_1, left_col, n_cols - 1,
2030 heading_rows + row_var_start + i * PERCENTILE_ROWS);
2033 if ( fctr->indep_var[0])
2036 ds_init_empty (&vstr);
2037 var_append_value_name (fctr->indep_var[0],
2038 result->value[0], &vstr);
2041 heading_rows + row_var_start + i * PERCENTILE_ROWS,
2050 tab_text (tbl, n_cols - n_percentiles - 1,
2051 heading_rows + row_var_start + i * PERCENTILE_ROWS,
2053 ptile_alg_desc [percentile_algorithm]);
2056 tab_text (tbl, n_cols - n_percentiles - 1,
2057 heading_rows + row_var_start + 1 + i * PERCENTILE_ROWS,
2059 _("Tukey's Hinges"));
2062 tab_vline (tbl, TAL_1, n_cols - n_percentiles -1, heading_rows, n_rows - 1);
2064 tukey_hinges_calculate ((struct tukey_hinges *) result->metrics[v].tukey_hinges,
2067 for (j = 0; j < n_percentiles; ++j)
2069 double hinge = SYSMIS;
2070 tab_float (tbl, n_cols - n_percentiles + j,
2071 heading_rows + row_var_start + i * PERCENTILE_ROWS,
2073 percentile_calculate (result->metrics[v].ptl[j],
2074 percentile_algorithm),
2078 if ( result->metrics[v].ptl[j]->ptile == 0.5)
2080 else if ( result->metrics[v].ptl[j]->ptile == 0.25)
2082 else if ( result->metrics[v].ptl[j]->ptile == 0.75)
2085 if ( hinge != SYSMIS)
2086 tab_float (tbl, n_cols - n_percentiles + j,
2087 heading_rows + row_var_start + 1 + i * PERCENTILE_ROWS,
2097 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
2099 tab_title (tbl, _("Percentiles"));
2102 for (i = 0 ; i < n_percentiles; ++i )
2104 tab_text (tbl, n_cols - n_percentiles + i, 1,
2105 TAB_CENTER | TAT_TITLE | TAT_PRINTF,
2107 subc_list_double_at (&percentile_list, i)
2113 tab_joint_text (tbl,
2114 n_cols - n_percentiles, 0,
2116 TAB_CENTER | TAT_TITLE,
2119 /* Vertical lines for the data only */
2123 n_cols - n_percentiles, 1,
2124 n_cols - 1, n_rows - 1);
2126 tab_hline (tbl, TAL_1, n_cols - n_percentiles, n_cols - 1, 1);
2134 factor_to_string_concise (const struct xfactor *fctr,
2135 const struct factor_result *result,
2139 if (fctr->indep_var[0])
2141 var_append_value_name (fctr->indep_var[0], result->value[0], str);
2143 if ( fctr->indep_var[1] )
2145 ds_put_cstr (str, ",");
2147 var_append_value_name (fctr->indep_var[1], result->value[1], str);
2149 ds_put_cstr (str, ")");
2156 factor_to_string (const struct xfactor *fctr,
2157 const struct factor_result *result,
2161 if (fctr->indep_var[0])
2163 ds_put_format (str, "(%s = ", var_get_name (fctr->indep_var[0]));
2165 var_append_value_name (fctr->indep_var[0], result->value[0], str);
2167 if ( fctr->indep_var[1] )
2169 ds_put_cstr (str, ",");
2170 ds_put_format (str, "%s = ", var_get_name (fctr->indep_var[1]));
2172 var_append_value_name (fctr->indep_var[1], result->value[1], str);
2174 ds_put_cstr (str, ")");