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 = LL_INITIALIZER (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 if ( !parse_examine (lexer, ds, &cmd, NULL) )
273 subc_list_double_destroy (&percentile_list);
277 /* If /MISSING=INCLUDE is set, then user missing values are ignored */
278 exclude_values = cmd.incl == XMN_INCLUDE ? MV_SYSTEM : MV_ANY;
280 if ( cmd.st_n == SYSMIS )
283 if ( ! cmd.sbc_cinterval)
284 cmd.n_cinterval[0] = 95.0;
286 /* If descriptives have been requested, make sure the
287 quartiles are calculated */
288 if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES] )
290 subc_list_double_push (&percentile_list, 25);
291 subc_list_double_push (&percentile_list, 50);
292 subc_list_double_push (&percentile_list, 75);
295 grouper = casegrouper_create_splits (proc_open (ds), dataset_dict (ds));
297 while (casegrouper_get_next_group (grouper, &group))
299 struct casereader *reader =
300 casereader_create_arithmetic_sequence (group, 1, 1);
302 run_examine (&cmd, reader, ds);
305 ok = casegrouper_destroy (grouper);
306 ok = proc_commit (ds) && ok;
308 if ( dependent_vars )
309 free (dependent_vars);
311 subc_list_double_destroy (&percentile_list);
313 return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
317 /* Plot the normal and detrended normal plots for RESULT.
318 Label the plots with LABEL */
320 np_plot (struct np *np, const char *label)
322 double yfirst = 0, ylast = 0;
329 struct chart *np_chart;
331 /* Detrended Normal Plot */
332 struct chart *dnp_chart;
334 /* The slope and intercept of the ideal normal probability line */
335 const double slope = 1.0 / np->stddev;
336 const double intercept = -np->mean / np->stddev;
340 msg (MW, _("Not creating plot because data set is empty."));
344 np_chart = chart_create ();
345 dnp_chart = chart_create ();
347 if ( !np_chart || ! dnp_chart )
350 chart_write_title (np_chart, _("Normal Q-Q Plot of %s"), label);
351 chart_write_xlabel (np_chart, _("Observed Value"));
352 chart_write_ylabel (np_chart, _("Expected Normal"));
354 chart_write_title (dnp_chart, _("Detrended Normal Q-Q Plot of %s"),
356 chart_write_xlabel (dnp_chart, _("Observed Value"));
357 chart_write_ylabel (dnp_chart, _("Dev from Normal"));
359 yfirst = gsl_cdf_ugaussian_Pinv (1 / (np->n + 1));
360 ylast = gsl_cdf_ugaussian_Pinv (np->n / (np->n + 1));
362 /* Need to make sure that both the scatter plot and the ideal fit into the
364 x_lower = MIN (np->y_min, (yfirst - intercept) / slope) ;
365 x_upper = MAX (np->y_max, (ylast - intercept) / slope) ;
366 slack = (x_upper - x_lower) * 0.05 ;
368 chart_write_xscale (np_chart, x_lower - slack, x_upper + slack, 5);
369 chart_write_xscale (dnp_chart, np->y_min, np->y_max, 5);
371 chart_write_yscale (np_chart, yfirst, ylast, 5);
372 chart_write_yscale (dnp_chart, np->dns_min, np->dns_max, 5);
375 struct casereader *reader = casewriter_make_reader (np->writer);
377 while ((c = casereader_read (reader)) != NULL)
379 chart_datum (np_chart, 0, case_data_idx (c, NP_IDX_Y)->f, case_data_idx (c, NP_IDX_NS)->f);
380 chart_datum (dnp_chart, 0, case_data_idx (c, NP_IDX_Y)->f, case_data_idx (c, NP_IDX_DNS)->f);
384 casereader_destroy (reader);
387 chart_line (dnp_chart, 0, 0, np->y_min, np->y_max , CHART_DIM_X);
388 chart_line (np_chart, slope, intercept, yfirst, ylast , CHART_DIM_Y);
390 chart_submit (np_chart);
391 chart_submit (dnp_chart);
396 show_npplot (const struct variable **dependent_var,
398 const struct xfactor *fctr)
402 for (v = 0; v < n_dep_var; ++v)
405 for (ll = ll_head (&fctr->result_list);
406 ll != ll_null (&fctr->result_list);
410 const struct factor_result *result =
411 ll_data (ll, struct factor_result, ll);
413 ds_init_empty (&str);
414 ds_put_format (&str, "%s ", var_get_name (dependent_var[v]));
416 factor_to_string (fctr, result, &str);
418 np_plot ((struct np*) result->metrics[v].np, ds_cstr(&str));
420 statistic_destroy ((struct statistic *)result->metrics[v].np);
429 show_histogram (const struct variable **dependent_var,
431 const struct xfactor *fctr)
435 for (v = 0; v < n_dep_var; ++v)
438 for (ll = ll_head (&fctr->result_list);
439 ll != ll_null (&fctr->result_list);
443 const struct factor_result *result =
444 ll_data (ll, struct factor_result, ll);
446 ds_init_empty (&str);
447 ds_put_format (&str, "%s ", var_get_name (dependent_var[v]));
449 factor_to_string (fctr, result, &str);
451 histogram_plot ((struct histogram *) result->metrics[v].histogram,
453 (struct moments1 *) result->metrics[v].moments);
463 show_boxplot_groups (const struct variable **dependent_var,
465 const struct xfactor *fctr)
469 for (v = 0; v < n_dep_var; ++v)
473 struct chart *ch = chart_create ();
474 double y_min = DBL_MAX;
475 double y_max = -DBL_MAX;
477 for (ll = ll_head (&fctr->result_list);
478 ll != ll_null (&fctr->result_list);
481 const struct extremum *max, *min;
482 const struct factor_result *result =
483 ll_data (ll, struct factor_result, ll);
485 const struct ll_list *max_list =
486 extrema_list (result->metrics[v].maxima);
488 const struct ll_list *min_list =
489 extrema_list (result->metrics[v].minima);
491 if ( ll_is_empty (max_list))
493 msg (MW, _("Not creating plot because data set is empty."));
497 max = (const struct extremum *)
498 ll_data (ll_head(max_list), struct extremum, ll);
500 min = (const struct extremum *)
501 ll_data (ll_head (min_list), struct extremum, ll);
503 y_max = MAX (y_max, max->value);
504 y_min = MIN (y_min, min->value);
507 boxplot_draw_yscale (ch, y_max, y_min);
509 if ( fctr->indep_var[0])
510 chart_write_title (ch, _("Boxplot of %s vs. %s"),
511 var_to_string (dependent_var[v]),
512 var_to_string (fctr->indep_var[0]) );
514 chart_write_title (ch, _("Boxplot of %s"),
515 var_to_string (dependent_var[v]));
517 for (ll = ll_head (&fctr->result_list);
518 ll != ll_null (&fctr->result_list);
521 const struct factor_result *result =
522 ll_data (ll, struct factor_result, ll);
525 const double box_width = (ch->data_right - ch->data_left)
526 / (ll_count (&fctr->result_list) * 2.0 ) ;
528 const double box_centre = (f++ * 2 + 1) * box_width + ch->data_left;
530 ds_init_empty (&str);
531 factor_to_string_concise (fctr, result, &str);
533 boxplot_draw_boxplot (ch,
534 box_centre, box_width,
535 (const struct box_whisker *)
536 result->metrics[v].box_whisker,
549 show_boxplot_variables (const struct variable **dependent_var,
551 const struct xfactor *fctr
557 const struct ll_list *result_list = &fctr->result_list;
559 for (ll = ll_head (result_list);
560 ll != ll_null (result_list);
565 struct chart *ch = chart_create ();
566 double y_min = DBL_MAX;
567 double y_max = -DBL_MAX;
569 const struct factor_result *result =
570 ll_data (ll, struct factor_result, ll);
572 const double box_width = (ch->data_right - ch->data_left)
573 / (n_dep_var * 2.0 ) ;
575 for (v = 0; v < n_dep_var; ++v)
577 const struct ll *max_ll =
578 ll_head (extrema_list (result->metrics[v].maxima));
579 const struct ll *min_ll =
580 ll_head (extrema_list (result->metrics[v].minima));
582 const struct extremum *max =
583 (const struct extremum *) ll_data (max_ll, struct extremum, ll);
585 const struct extremum *min =
586 (const struct extremum *) ll_data (min_ll, struct extremum, ll);
588 y_max = MAX (y_max, max->value);
589 y_min = MIN (y_min, min->value);
593 boxplot_draw_yscale (ch, y_max, y_min);
595 ds_init_empty (&title);
596 factor_to_string (fctr, result, &title);
599 ds_put_format (&title, "%s = ", var_get_name (fctr->indep_var[0]));
600 var_append_value_name (fctr->indep_var[0], result->value[0], &title);
603 chart_write_title (ch, ds_cstr (&title));
606 for (v = 0; v < n_dep_var; ++v)
609 const double box_centre = (v * 2 + 1) * box_width + ch->data_left;
611 ds_init_empty (&str);
612 ds_init_cstr (&str, var_get_name (dependent_var[v]));
614 boxplot_draw_boxplot (ch,
615 box_centre, box_width,
616 (const struct box_whisker *) result->metrics[v].box_whisker,
627 /* Show all the appropriate tables */
629 output_examine (void)
633 show_summary (dependent_vars, n_dependent_vars, &level0_factor);
635 if ( cmd.a_statistics[XMN_ST_EXTREME] )
636 show_extremes (dependent_vars, n_dependent_vars, &level0_factor);
638 if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES] )
639 show_descriptives (dependent_vars, n_dependent_vars, &level0_factor);
641 if ( cmd.sbc_percentiles)
642 show_percentiles (dependent_vars, n_dependent_vars, &level0_factor);
646 if (cmd.a_plot[XMN_PLT_BOXPLOT])
647 show_boxplot_groups (dependent_vars, n_dependent_vars, &level0_factor);
649 if (cmd.a_plot[XMN_PLT_HISTOGRAM])
650 show_histogram (dependent_vars, n_dependent_vars, &level0_factor);
652 if (cmd.a_plot[XMN_PLT_NPPLOT])
653 show_npplot (dependent_vars, n_dependent_vars, &level0_factor);
656 for (ll = ll_head (&factor_list);
657 ll != ll_null (&factor_list); ll = ll_next (ll))
659 struct xfactor *factor = ll_data (ll, struct xfactor, ll);
660 show_summary (dependent_vars, n_dependent_vars, factor);
662 if ( cmd.a_statistics[XMN_ST_EXTREME] )
663 show_extremes (dependent_vars, n_dependent_vars, factor);
665 if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES] )
666 show_descriptives (dependent_vars, n_dependent_vars, factor);
668 if ( cmd.sbc_percentiles)
669 show_percentiles (dependent_vars, n_dependent_vars, factor);
671 if (cmd.a_plot[XMN_PLT_BOXPLOT] &&
672 cmd.cmp == XMN_GROUPS)
673 show_boxplot_groups (dependent_vars, n_dependent_vars, factor);
676 if (cmd.a_plot[XMN_PLT_BOXPLOT] &&
677 cmd.cmp == XMN_VARIABLES)
678 show_boxplot_variables (dependent_vars, n_dependent_vars,
681 if (cmd.a_plot[XMN_PLT_HISTOGRAM])
682 show_histogram (dependent_vars, n_dependent_vars, factor);
684 if (cmd.a_plot[XMN_PLT_NPPLOT])
685 show_npplot (dependent_vars, n_dependent_vars, factor);
689 /* Parse the PERCENTILES subcommand */
691 xmn_custom_percentiles (struct lexer *lexer, struct dataset *ds UNUSED,
692 struct cmd_examine *p UNUSED, void *aux UNUSED)
694 lex_match (lexer, '=');
696 lex_match (lexer, '(');
698 while ( lex_is_number (lexer) )
700 subc_list_double_push (&percentile_list, lex_number (lexer));
704 lex_match (lexer, ',') ;
706 lex_match (lexer, ')');
708 lex_match (lexer, '=');
710 if ( lex_match_id (lexer, "HAVERAGE"))
711 percentile_algorithm = PC_HAVERAGE;
713 else if ( lex_match_id (lexer, "WAVERAGE"))
714 percentile_algorithm = PC_WAVERAGE;
716 else if ( lex_match_id (lexer, "ROUND"))
717 percentile_algorithm = PC_ROUND;
719 else if ( lex_match_id (lexer, "EMPIRICAL"))
720 percentile_algorithm = PC_EMPIRICAL;
722 else if ( lex_match_id (lexer, "AEMPIRICAL"))
723 percentile_algorithm = PC_AEMPIRICAL;
725 else if ( lex_match_id (lexer, "NONE"))
726 percentile_algorithm = PC_NONE;
729 if ( 0 == subc_list_double_count (&percentile_list))
731 subc_list_double_push (&percentile_list, 5);
732 subc_list_double_push (&percentile_list, 10);
733 subc_list_double_push (&percentile_list, 25);
734 subc_list_double_push (&percentile_list, 50);
735 subc_list_double_push (&percentile_list, 75);
736 subc_list_double_push (&percentile_list, 90);
737 subc_list_double_push (&percentile_list, 95);
743 /* TOTAL and NOTOTAL are simple, mutually exclusive flags */
745 xmn_custom_total (struct lexer *lexer UNUSED, struct dataset *ds UNUSED,
746 struct cmd_examine *p, void *aux UNUSED)
748 if ( p->sbc_nototal )
750 msg (SE, _("%s and %s are mutually exclusive"),"TOTAL","NOTOTAL");
758 xmn_custom_nototal (struct lexer *lexer UNUSED, struct dataset *ds UNUSED,
759 struct cmd_examine *p, void *aux UNUSED)
763 msg (SE, _("%s and %s are mutually exclusive"), "TOTAL", "NOTOTAL");
772 /* Parser for the variables sub command
773 Returns 1 on success */
775 xmn_custom_variables (struct lexer *lexer, struct dataset *ds,
776 struct cmd_examine *cmd,
779 const struct dictionary *dict = dataset_dict (ds);
780 lex_match (lexer, '=');
782 if ( (lex_token (lexer) != T_ID || dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
783 && lex_token (lexer) != T_ALL)
788 if (!parse_variables_const (lexer, dict, &dependent_vars, &n_dependent_vars,
789 PV_NO_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH) )
791 free (dependent_vars);
795 assert (n_dependent_vars);
798 if ( lex_match (lexer, T_BY))
801 success = examine_parse_independent_vars (lexer, dict, cmd);
804 free (dependent_vars);
814 /* Parse the clause specifying the factors */
816 examine_parse_independent_vars (struct lexer *lexer,
817 const struct dictionary *dict,
818 struct cmd_examine *cmd)
821 struct xfactor *sf = xmalloc (sizeof *sf);
823 ll_init (&sf->result_list);
825 if ( (lex_token (lexer) != T_ID ||
826 dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
827 && lex_token (lexer) != T_ALL)
833 sf->indep_var[0] = parse_variable (lexer, dict);
834 sf->indep_var[1] = NULL;
836 if ( lex_token (lexer) == T_BY )
838 lex_match (lexer, T_BY);
840 if ( (lex_token (lexer) != T_ID ||
841 dict_lookup_var (dict, lex_tokid (lexer)) == NULL)
842 && lex_token (lexer) != T_ALL)
848 sf->indep_var[1] = parse_variable (lexer, dict);
850 ll_push_tail (&factor_list, &sf->ll);
853 ll_push_tail (&factor_list, &sf->ll);
855 lex_match (lexer, ',');
857 if ( lex_token (lexer) == '.' || lex_token (lexer) == '/' )
860 success = examine_parse_independent_vars (lexer, dict, cmd);
869 examine_group (struct cmd_examine *cmd, struct casereader *reader, int level,
870 const struct dictionary *dict, struct xfactor *factor)
873 const struct variable *wv = dict_get_weight (dict);
876 struct factor_result *result = xzalloc (sizeof (*result));
878 result->metrics = xcalloc (n_dependent_vars, sizeof (*result->metrics));
880 if ( cmd->a_statistics[XMN_ST_EXTREME] )
881 n_extrema = cmd->st_n;
884 c = casereader_peek (reader, 0);
890 value_dup (case_data (c, factor->indep_var[0]),
891 var_get_width (factor->indep_var[0]));
895 value_dup (case_data (c, factor->indep_var[1]),
896 var_get_width (factor->indep_var[1]));
901 for (v = 0; v < n_dependent_vars; ++v)
903 struct casewriter *writer;
904 struct casereader *input = casereader_clone (reader);
906 result->metrics[v].moments = moments1_create (MOMENT_KURTOSIS);
907 result->metrics[v].minima = extrema_create (n_extrema, EXTREME_MINIMA);
908 result->metrics[v].maxima = extrema_create (n_extrema, EXTREME_MAXIMA);
909 result->metrics[v].cmin = DBL_MAX;
911 if (cmd->a_statistics[XMN_ST_DESCRIPTIVES] ||
912 cmd->a_plot[XMN_PLT_BOXPLOT] ||
913 cmd->a_plot[XMN_PLT_NPPLOT] ||
914 cmd->sbc_percentiles)
916 /* In this case, we need to sort the data, so we create a sorting
918 struct subcase up_ordering;
919 subcase_init_var (&up_ordering, dependent_vars[v], SC_ASCEND);
920 writer = sort_create_writer (&up_ordering,
921 casereader_get_value_cnt (reader));
922 subcase_destroy (&up_ordering);
926 /* but in this case, sorting is unnecessary, so an ordinary
927 casewriter is sufficient */
929 autopaging_writer_create (casereader_get_value_cnt (reader));
933 /* Sort or just iterate, whilst calculating moments etc */
934 while ((c = casereader_read (input)) != NULL)
936 const casenumber loc =
937 case_data_idx (c, casereader_get_value_cnt (reader) - 1)->f;
939 const double weight = wv ? case_data (c, wv)->f : 1.0;
940 const union value *value = case_data (c, dependent_vars[v]);
942 if (weight != SYSMIS)
943 minimize (&result->metrics[v].cmin, weight);
945 moments1_add (result->metrics[v].moments,
949 result->metrics[v].n += weight;
951 if ( ! var_is_value_missing (dependent_vars[v], value, MV_ANY) )
952 result->metrics[v].n_valid += weight;
954 extrema_add (result->metrics[v].maxima,
959 extrema_add (result->metrics[v].minima,
964 casewriter_write (writer, c);
966 casereader_destroy (input);
967 result->metrics[v].up_reader = casewriter_make_reader (writer);
970 /* If percentiles or descriptives have been requested, then a
971 second pass through the data (which has now been sorted)
973 if ( cmd->a_statistics[XMN_ST_DESCRIPTIVES] ||
974 cmd->a_plot[XMN_PLT_BOXPLOT] ||
975 cmd->a_plot[XMN_PLT_NPPLOT] ||
976 cmd->sbc_percentiles)
978 for (v = 0; v < n_dependent_vars; ++v)
982 struct order_stats **os ;
983 struct factor_metrics *metric = &result->metrics[v];
985 metric->n_ptiles = percentile_list.n_data;
987 metric->ptl = xcalloc (metric->n_ptiles,
988 sizeof (struct percentile *));
990 metric->quartiles = xcalloc (3, sizeof (*metric->quartiles));
992 for (i = 0 ; i < metric->n_ptiles; ++i)
994 metric->ptl[i] = (struct percentile *)
995 percentile_create (percentile_list.data[i] / 100.0, metric->n_valid);
997 if ( percentile_list.data[i] == 25)
998 metric->quartiles[0] = metric->ptl[i];
999 else if ( percentile_list.data[i] == 50)
1000 metric->quartiles[1] = metric->ptl[i];
1001 else if ( percentile_list.data[i] == 75)
1002 metric->quartiles[2] = metric->ptl[i];
1005 metric->tukey_hinges = tukey_hinges_create (metric->n, metric->cmin);
1006 metric->trimmed_mean = trimmed_mean_create (metric->n, 0.05);
1008 n_os = metric->n_ptiles + 2;
1010 if ( cmd->a_plot[XMN_PLT_NPPLOT] )
1012 metric->np = np_create (metric->moments);
1016 os = xcalloc (sizeof (struct order_stats *), n_os);
1018 for (i = 0 ; i < metric->n_ptiles ; ++i )
1020 os[i] = (struct order_stats *) metric->ptl[i];
1023 os[i] = (struct order_stats *) metric->tukey_hinges;
1024 os[i+1] = (struct order_stats *) metric->trimmed_mean;
1026 if (cmd->a_plot[XMN_PLT_NPPLOT])
1027 os[i+2] = metric->np;
1029 order_stats_accumulate (os, n_os,
1030 casereader_clone (metric->up_reader),
1031 wv, dependent_vars[v], MV_ANY);
1036 /* FIXME: Do this in the above loop */
1037 if ( cmd->a_plot[XMN_PLT_HISTOGRAM] )
1040 struct casereader *input = casereader_clone (reader);
1042 for (v = 0; v < n_dependent_vars; ++v)
1044 const struct extremum *max, *min;
1045 struct factor_metrics *metric = &result->metrics[v];
1047 const struct ll_list *max_list =
1048 extrema_list (result->metrics[v].maxima);
1050 const struct ll_list *min_list =
1051 extrema_list (result->metrics[v].minima);
1053 if ( ll_is_empty (max_list))
1055 msg (MW, _("Not creating plot because data set is empty."));
1059 assert (! ll_is_empty (min_list));
1061 max = (const struct extremum *)
1062 ll_data (ll_head(max_list), struct extremum, ll);
1064 min = (const struct extremum *)
1065 ll_data (ll_head (min_list), struct extremum, ll);
1067 metric->histogram = histogram_create (10, min->value, max->value);
1070 while ((c = casereader_read (input)) != NULL)
1072 const double weight = wv ? case_data (c, wv)->f : 1.0;
1074 for (v = 0; v < n_dependent_vars; ++v)
1076 struct factor_metrics *metric = &result->metrics[v];
1077 if ( metric->histogram)
1078 histogram_add ((struct histogram *) metric->histogram,
1079 case_data (c, dependent_vars[v])->f, weight);
1083 casereader_destroy (input);
1086 /* In this case, a third iteration is required */
1087 if (cmd->a_plot[XMN_PLT_BOXPLOT])
1089 for (v = 0; v < n_dependent_vars; ++v)
1091 struct factor_metrics *metric = &result->metrics[v];
1093 metric->box_whisker =
1094 box_whisker_create ((struct tukey_hinges *) metric->tukey_hinges,
1096 casereader_get_value_cnt (metric->up_reader)
1099 order_stats_accumulate ((struct order_stats **) &metric->box_whisker,
1101 casereader_clone (metric->up_reader),
1102 wv, dependent_vars[v], MV_ANY);
1106 ll_push_tail (&factor->result_list, &result->ll);
1107 casereader_destroy (reader);
1112 run_examine (struct cmd_examine *cmd, struct casereader *input,
1116 const struct dictionary *dict = dataset_dict (ds);
1118 struct casereader *level0 = casereader_clone (input);
1120 c = casereader_peek (input, 0);
1123 casereader_destroy (input);
1127 output_split_file_values (ds, c);
1130 ll_init (&level0_factor.result_list);
1132 examine_group (cmd, level0, 0, dict, &level0_factor);
1134 for (ll = ll_head (&factor_list);
1135 ll != ll_null (&factor_list);
1138 struct xfactor *factor = ll_data (ll, struct xfactor, ll);
1140 struct casereader *group = NULL;
1141 struct casereader *level1;
1142 struct casegrouper *grouper1 = NULL;
1144 level1 = casereader_clone (input);
1145 level1 = sort_execute_1var (level1, factor->indep_var[0]);
1146 grouper1 = casegrouper_create_vars (level1, &factor->indep_var[0], 1);
1148 while (casegrouper_get_next_group (grouper1, &group))
1150 struct casereader *group_copy = casereader_clone (group);
1152 if ( !factor->indep_var[1])
1153 examine_group (cmd, group_copy, 1, dict, factor);
1157 struct casereader *group2 = NULL;
1158 struct casegrouper *grouper2 = NULL;
1160 group_copy = sort_execute_1var (group_copy,
1161 factor->indep_var[1]);
1163 grouper2 = casegrouper_create_vars (group_copy,
1164 &factor->indep_var[1], 1);
1166 while (casegrouper_get_next_group (grouper2, &group2))
1168 examine_group (cmd, group2, 2, dict, factor);
1171 casegrouper_destroy (grouper2);
1174 casereader_destroy (group);
1176 casegrouper_destroy (grouper1);
1179 casereader_destroy (input);
1183 factor_destroy (&level0_factor);
1187 for (ll = ll_head (&factor_list);
1188 ll != ll_null (&factor_list);
1191 struct xfactor *f = ll_data (ll, struct xfactor, ll);
1200 show_summary (const struct variable **dependent_var, int n_dep_var,
1201 const struct xfactor *fctr)
1203 static const char *subtitle[]=
1211 int heading_columns = 1;
1213 const int heading_rows = 3;
1214 struct tab_table *tbl;
1221 if ( fctr->indep_var[0] )
1223 heading_columns = 2;
1225 if ( fctr->indep_var[1] )
1227 heading_columns = 3;
1231 n_rows *= ll_count (&fctr->result_list);
1232 n_rows += heading_rows;
1234 n_cols = heading_columns + 6;
1236 tbl = tab_create (n_cols, n_rows, 0);
1237 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1239 tab_dim (tbl, tab_natural_dimensions);
1241 /* Outline the box */
1246 n_cols - 1, n_rows - 1);
1248 /* Vertical lines for the data only */
1253 n_cols - 1, n_rows - 1);
1256 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1257 tab_hline (tbl, TAL_1, heading_columns, n_cols - 1, 1 );
1258 tab_hline (tbl, TAL_1, heading_columns, n_cols - 1, heading_rows -1 );
1260 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1263 tab_title (tbl, _("Case Processing Summary"));
1265 tab_joint_text (tbl, heading_columns, 0,
1267 TAB_CENTER | TAT_TITLE,
1270 /* Remove lines ... */
1277 for (j = 0 ; j < 3 ; ++j)
1279 tab_text (tbl, heading_columns + j * 2 , 2, TAB_CENTER | TAT_TITLE,
1282 tab_text (tbl, heading_columns + j * 2 + 1, 2, TAB_CENTER | TAT_TITLE,
1285 tab_joint_text (tbl, heading_columns + j * 2 , 1,
1286 heading_columns + j * 2 + 1, 1,
1287 TAB_CENTER | TAT_TITLE,
1290 tab_box (tbl, -1, -1,
1292 heading_columns + j * 2, 1,
1293 heading_columns + j * 2 + 1, 1);
1297 /* Titles for the independent variables */
1298 if ( fctr->indep_var[0] )
1300 tab_text (tbl, 1, heading_rows - 1, TAB_CENTER | TAT_TITLE,
1301 var_to_string (fctr->indep_var[0]));
1303 if ( fctr->indep_var[1] )
1305 tab_text (tbl, 2, heading_rows - 1, TAB_CENTER | TAT_TITLE,
1306 var_to_string (fctr->indep_var[1]));
1310 for (v = 0 ; v < n_dep_var ; ++v)
1314 union value *last_value = NULL;
1317 tab_hline (tbl, TAL_1, 0, n_cols -1 ,
1318 v * ll_count (&fctr->result_list)
1323 v * ll_count (&fctr->result_list) + heading_rows,
1324 TAB_LEFT | TAT_TITLE,
1325 var_to_string (dependent_var[v])
1329 for (ll = ll_head (&fctr->result_list);
1330 ll != ll_null (&fctr->result_list); ll = ll_next (ll))
1333 const struct factor_result *result =
1334 ll_data (ll, struct factor_result, ll);
1336 if ( fctr->indep_var[0] )
1339 if ( last_value == NULL ||
1340 compare_values_short (last_value, result->value[0],
1341 fctr->indep_var[0]))
1345 last_value = result->value[0];
1346 ds_init_empty (&str);
1348 var_append_value_name (fctr->indep_var[0], result->value[0],
1353 v * ll_count (&fctr->result_list),
1354 TAB_LEFT | TAT_TITLE,
1359 if ( fctr->indep_var[1] && j > 0)
1360 tab_hline (tbl, TAL_1, 1, n_cols - 1,
1362 v * ll_count (&fctr->result_list));
1365 if ( fctr->indep_var[1])
1369 ds_init_empty (&str);
1371 var_append_value_name (fctr->indep_var[1],
1372 result->value[1], &str);
1376 v * ll_count (&fctr->result_list),
1377 TAB_LEFT | TAT_TITLE,
1385 moments1_calculate (result->metrics[v].moments,
1386 &n, &result->metrics[v].mean,
1387 &result->metrics[v].variance,
1388 &result->metrics[v].skewness,
1389 &result->metrics[v].kurtosis);
1391 result->metrics[v].se_mean = sqrt (result->metrics[v].variance / n) ;
1394 tab_float (tbl, heading_columns,
1395 heading_rows + j + v * ll_count (&fctr->result_list),
1399 tab_text (tbl, heading_columns + 1,
1400 heading_rows + j + v * ll_count (&fctr->result_list),
1401 TAB_RIGHT | TAT_PRINTF,
1402 "%g%%", n * 100.0 / result->metrics[v].n);
1405 tab_float (tbl, heading_columns + 2,
1406 heading_rows + j + v * ll_count (&fctr->result_list),
1408 result->metrics[v].n - n,
1411 tab_text (tbl, heading_columns + 3,
1412 heading_rows + j + v * ll_count (&fctr->result_list),
1413 TAB_RIGHT | TAT_PRINTF,
1415 (result->metrics[v].n - n) * 100.0 / result->metrics[v].n
1418 /* Total Valid + Missing */
1419 tab_float (tbl, heading_columns + 4,
1420 heading_rows + j + v * ll_count (&fctr->result_list),
1422 result->metrics[v].n,
1425 tab_text (tbl, heading_columns + 5,
1426 heading_rows + j + v * ll_count (&fctr->result_list),
1427 TAB_RIGHT | TAT_PRINTF,
1429 (result->metrics[v].n) * 100.0 / result->metrics[v].n
1440 #define DESCRIPTIVE_ROWS 13
1443 show_descriptives (const struct variable **dependent_var,
1445 const struct xfactor *fctr)
1448 int heading_columns = 3;
1450 const int heading_rows = 1;
1451 struct tab_table *tbl;
1458 if ( fctr->indep_var[0] )
1460 heading_columns = 4;
1462 if ( fctr->indep_var[1] )
1464 heading_columns = 5;
1468 n_rows *= ll_count (&fctr->result_list) * DESCRIPTIVE_ROWS;
1469 n_rows += heading_rows;
1471 n_cols = heading_columns + 2;
1473 tbl = tab_create (n_cols, n_rows, 0);
1474 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1476 tab_dim (tbl, tab_natural_dimensions);
1478 /* Outline the box */
1483 n_cols - 1, n_rows - 1);
1486 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1487 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
1489 tab_vline (tbl, TAL_1, n_cols - 1, 0, n_rows - 1);
1492 if ( fctr->indep_var[0])
1493 tab_text (tbl, 1, 0, TAT_TITLE, var_to_string (fctr->indep_var[0]));
1495 if ( fctr->indep_var[1])
1496 tab_text (tbl, 2, 0, TAT_TITLE, var_to_string (fctr->indep_var[1]));
1498 for (v = 0 ; v < n_dep_var ; ++v )
1503 const int row_var_start =
1504 v * DESCRIPTIVE_ROWS * ll_count(&fctr->result_list);
1508 heading_rows + row_var_start,
1509 TAB_LEFT | TAT_TITLE,
1510 var_to_string (dependent_var[v])
1513 for (ll = ll_head (&fctr->result_list);
1514 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
1516 const struct factor_result *result =
1517 ll_data (ll, struct factor_result, ll);
1520 gsl_cdf_tdist_Qinv ((1 - cmd.n_cinterval[0] / 100.0) / 2.0,
1521 result->metrics[v].n - 1);
1523 if ( i > 0 || v > 0 )
1525 const int left_col = (i == 0) ? 0 : 1;
1526 tab_hline (tbl, TAL_1, left_col, n_cols - 1,
1527 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS);
1530 if ( fctr->indep_var[0])
1533 ds_init_empty (&vstr);
1534 var_append_value_name (fctr->indep_var[0],
1535 result->value[0], &vstr);
1538 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1547 tab_text (tbl, n_cols - 4,
1548 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1552 tab_text (tbl, n_cols - 4,
1553 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1554 TAB_LEFT | TAT_PRINTF,
1555 _("%g%% Confidence Interval for Mean"),
1556 cmd.n_cinterval[0]);
1558 tab_text (tbl, n_cols - 3,
1559 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1563 tab_text (tbl, n_cols - 3,
1564 heading_rows + row_var_start + 2 + i * DESCRIPTIVE_ROWS,
1568 tab_text (tbl, n_cols - 4,
1569 heading_rows + row_var_start + 3 + i * DESCRIPTIVE_ROWS,
1570 TAB_LEFT | TAT_PRINTF,
1571 _("5%% Trimmed Mean"));
1573 tab_text (tbl, n_cols - 4,
1574 heading_rows + row_var_start + 4 + i * DESCRIPTIVE_ROWS,
1578 tab_text (tbl, n_cols - 4,
1579 heading_rows + row_var_start + 5 + i * DESCRIPTIVE_ROWS,
1583 tab_text (tbl, n_cols - 4,
1584 heading_rows + row_var_start + 6 + i * DESCRIPTIVE_ROWS,
1586 _("Std. Deviation"));
1588 tab_text (tbl, n_cols - 4,
1589 heading_rows + row_var_start + 7 + i * DESCRIPTIVE_ROWS,
1593 tab_text (tbl, n_cols - 4,
1594 heading_rows + row_var_start + 8 + i * DESCRIPTIVE_ROWS,
1598 tab_text (tbl, n_cols - 4,
1599 heading_rows + row_var_start + 9 + i * DESCRIPTIVE_ROWS,
1603 tab_text (tbl, n_cols - 4,
1604 heading_rows + row_var_start + 10 + i * DESCRIPTIVE_ROWS,
1606 _("Interquartile Range"));
1609 tab_text (tbl, n_cols - 4,
1610 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1614 tab_text (tbl, n_cols - 4,
1615 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1620 /* Now the statistics ... */
1622 tab_float (tbl, n_cols - 2,
1623 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1625 result->metrics[v].mean,
1628 tab_float (tbl, n_cols - 1,
1629 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1631 result->metrics[v].se_mean,
1635 tab_float (tbl, n_cols - 2,
1636 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1638 result->metrics[v].mean - t *
1639 result->metrics[v].se_mean,
1642 tab_float (tbl, n_cols - 2,
1643 heading_rows + row_var_start + 2 + i * DESCRIPTIVE_ROWS,
1645 result->metrics[v].mean + t *
1646 result->metrics[v].se_mean,
1650 tab_float (tbl, n_cols - 2,
1651 heading_rows + row_var_start + 3 + i * DESCRIPTIVE_ROWS,
1653 trimmed_mean_calculate ((struct trimmed_mean *) result->metrics[v].trimmed_mean),
1657 tab_float (tbl, n_cols - 2,
1658 heading_rows + row_var_start + 4 + i * DESCRIPTIVE_ROWS,
1660 percentile_calculate (result->metrics[v].quartiles[1], percentile_algorithm),
1664 tab_float (tbl, n_cols - 2,
1665 heading_rows + row_var_start + 5 + i * DESCRIPTIVE_ROWS,
1667 result->metrics[v].variance,
1670 tab_float (tbl, n_cols - 2,
1671 heading_rows + row_var_start + 6 + i * DESCRIPTIVE_ROWS,
1673 sqrt (result->metrics[v].variance),
1676 tab_float (tbl, n_cols - 2,
1677 heading_rows + row_var_start + 10 + i * DESCRIPTIVE_ROWS,
1679 percentile_calculate (result->metrics[v].quartiles[2],
1680 percentile_algorithm) -
1681 percentile_calculate (result->metrics[v].quartiles[0],
1682 percentile_algorithm),
1686 tab_float (tbl, n_cols - 2,
1687 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1689 result->metrics[v].skewness,
1692 tab_float (tbl, n_cols - 2,
1693 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1695 result->metrics[v].kurtosis,
1698 tab_float (tbl, n_cols - 1,
1699 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1701 calc_seskew (result->metrics[v].n),
1704 tab_float (tbl, n_cols - 1,
1705 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1707 calc_sekurt (result->metrics[v].n),
1711 struct extremum *minimum, *maximum ;
1713 struct ll *max_ll = ll_head (extrema_list (result->metrics[v].maxima));
1714 struct ll *min_ll = ll_head (extrema_list (result->metrics[v].minima));
1716 maximum = ll_data (max_ll, struct extremum, ll);
1717 minimum = ll_data (min_ll, struct extremum, ll);
1719 tab_float (tbl, n_cols - 2,
1720 heading_rows + row_var_start + 7 + i * DESCRIPTIVE_ROWS,
1725 tab_float (tbl, n_cols - 2,
1726 heading_rows + row_var_start + 8 + i * DESCRIPTIVE_ROWS,
1731 tab_float (tbl, n_cols - 2,
1732 heading_rows + row_var_start + 9 + i * DESCRIPTIVE_ROWS,
1734 maximum->value - minimum->value,
1740 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1742 tab_title (tbl, _("Descriptives"));
1744 tab_text (tbl, n_cols - 2, 0, TAB_CENTER | TAT_TITLE,
1747 tab_text (tbl, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
1756 show_extremes (const struct variable **dependent_var,
1758 const struct xfactor *fctr)
1761 int heading_columns = 3;
1763 const int heading_rows = 1;
1764 struct tab_table *tbl;
1771 if ( fctr->indep_var[0] )
1773 heading_columns = 4;
1775 if ( fctr->indep_var[1] )
1777 heading_columns = 5;
1781 n_rows *= ll_count (&fctr->result_list) * cmd.st_n * 2;
1782 n_rows += heading_rows;
1784 n_cols = heading_columns + 2;
1786 tbl = tab_create (n_cols, n_rows, 0);
1787 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1789 tab_dim (tbl, tab_natural_dimensions);
1791 /* Outline the box */
1796 n_cols - 1, n_rows - 1);
1799 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1800 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
1801 tab_vline (tbl, TAL_1, n_cols - 1, 0, n_rows - 1);
1803 if ( fctr->indep_var[0])
1804 tab_text (tbl, 1, 0, TAT_TITLE, var_to_string (fctr->indep_var[0]));
1806 if ( fctr->indep_var[1])
1807 tab_text (tbl, 2, 0, TAT_TITLE, var_to_string (fctr->indep_var[1]));
1809 for (v = 0 ; v < n_dep_var ; ++v )
1813 const int row_var_start = v * cmd.st_n * 2 * ll_count(&fctr->result_list);
1817 heading_rows + row_var_start,
1818 TAB_LEFT | TAT_TITLE,
1819 var_to_string (dependent_var[v])
1822 for (ll = ll_head (&fctr->result_list);
1823 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
1828 const int row_result_start = i * cmd.st_n * 2;
1830 const struct factor_result *result =
1831 ll_data (ll, struct factor_result, ll);
1834 tab_hline (tbl, TAL_1, 1, n_cols - 1,
1835 heading_rows + row_var_start + row_result_start);
1837 tab_hline (tbl, TAL_1, heading_columns - 2, n_cols - 1,
1838 heading_rows + row_var_start + row_result_start + cmd.st_n);
1840 for ( e = 1; e <= cmd.st_n; ++e )
1842 tab_text (tbl, n_cols - 3,
1843 heading_rows + row_var_start + row_result_start + e - 1,
1844 TAB_RIGHT | TAT_PRINTF,
1847 tab_text (tbl, n_cols - 3,
1848 heading_rows + row_var_start + row_result_start + cmd.st_n + e - 1,
1849 TAB_RIGHT | TAT_PRINTF,
1854 min_ll = ll_head (extrema_list (result->metrics[v].minima));
1855 for (e = 0; e < cmd.st_n;)
1857 struct extremum *minimum = ll_data (min_ll, struct extremum, ll);
1858 double weight = minimum->weight;
1860 while (weight-- > 0 && e < cmd.st_n)
1862 tab_float (tbl, n_cols - 1,
1863 heading_rows + row_var_start + row_result_start + cmd.st_n + e,
1869 tab_float (tbl, n_cols - 2,
1870 heading_rows + row_var_start + row_result_start + cmd.st_n + e,
1877 min_ll = ll_next (min_ll);
1881 max_ll = ll_head (extrema_list (result->metrics[v].maxima));
1882 for (e = 0; e < cmd.st_n;)
1884 struct extremum *maximum = ll_data (max_ll, struct extremum, ll);
1885 double weight = maximum->weight;
1887 while (weight-- > 0 && e < cmd.st_n)
1889 tab_float (tbl, n_cols - 1,
1890 heading_rows + row_var_start + row_result_start + e,
1896 tab_float (tbl, n_cols - 2,
1897 heading_rows + row_var_start + row_result_start + e,
1904 max_ll = ll_next (max_ll);
1908 if ( fctr->indep_var[0])
1911 ds_init_empty (&vstr);
1912 var_append_value_name (fctr->indep_var[0],
1913 result->value[0], &vstr);
1916 heading_rows + row_var_start + row_result_start,
1925 tab_text (tbl, n_cols - 4,
1926 heading_rows + row_var_start + row_result_start,
1930 tab_text (tbl, n_cols - 4,
1931 heading_rows + row_var_start + row_result_start + cmd.st_n,
1937 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1940 tab_title (tbl, _("Extreme Values"));
1943 tab_text (tbl, n_cols - 2, 0, TAB_CENTER | TAT_TITLE,
1947 tab_text (tbl, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
1953 #define PERCENTILE_ROWS 2
1956 show_percentiles (const struct variable **dependent_var,
1958 const struct xfactor *fctr)
1962 int heading_columns = 2;
1964 const int n_percentiles = subc_list_double_count (&percentile_list);
1965 const int heading_rows = 2;
1966 struct tab_table *tbl;
1973 if ( fctr->indep_var[0] )
1975 heading_columns = 3;
1977 if ( fctr->indep_var[1] )
1979 heading_columns = 4;
1983 n_rows *= ll_count (&fctr->result_list) * PERCENTILE_ROWS;
1984 n_rows += heading_rows;
1986 n_cols = heading_columns + n_percentiles;
1988 tbl = tab_create (n_cols, n_rows, 0);
1989 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1991 tab_dim (tbl, tab_natural_dimensions);
1993 /* Outline the box */
1998 n_cols - 1, n_rows - 1);
2001 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
2002 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
2004 if ( fctr->indep_var[0])
2005 tab_text (tbl, 1, 1, TAT_TITLE, var_to_string (fctr->indep_var[0]));
2007 if ( fctr->indep_var[1])
2008 tab_text (tbl, 2, 1, TAT_TITLE, var_to_string (fctr->indep_var[1]));
2010 for (v = 0 ; v < n_dep_var ; ++v )
2016 const int row_var_start =
2017 v * PERCENTILE_ROWS * ll_count(&fctr->result_list);
2021 heading_rows + row_var_start,
2022 TAB_LEFT | TAT_TITLE,
2023 var_to_string (dependent_var[v])
2026 for (ll = ll_head (&fctr->result_list);
2027 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
2030 const struct factor_result *result =
2031 ll_data (ll, struct factor_result, ll);
2033 if ( i > 0 || v > 0 )
2035 const int left_col = (i == 0) ? 0 : 1;
2036 tab_hline (tbl, TAL_1, left_col, n_cols - 1,
2037 heading_rows + row_var_start + i * PERCENTILE_ROWS);
2040 if ( fctr->indep_var[0])
2043 ds_init_empty (&vstr);
2044 var_append_value_name (fctr->indep_var[0],
2045 result->value[0], &vstr);
2048 heading_rows + row_var_start + i * PERCENTILE_ROWS,
2057 tab_text (tbl, n_cols - n_percentiles - 1,
2058 heading_rows + row_var_start + i * PERCENTILE_ROWS,
2060 ptile_alg_desc [percentile_algorithm]);
2063 tab_text (tbl, n_cols - n_percentiles - 1,
2064 heading_rows + row_var_start + 1 + i * PERCENTILE_ROWS,
2066 _("Tukey's Hinges"));
2069 tab_vline (tbl, TAL_1, n_cols - n_percentiles -1, heading_rows, n_rows - 1);
2071 tukey_hinges_calculate ((struct tukey_hinges *) result->metrics[v].tukey_hinges,
2074 for (j = 0; j < n_percentiles; ++j)
2076 double hinge = SYSMIS;
2077 tab_float (tbl, n_cols - n_percentiles + j,
2078 heading_rows + row_var_start + i * PERCENTILE_ROWS,
2080 percentile_calculate (result->metrics[v].ptl[j],
2081 percentile_algorithm),
2085 if ( result->metrics[v].ptl[j]->ptile == 0.5)
2087 else if ( result->metrics[v].ptl[j]->ptile == 0.25)
2089 else if ( result->metrics[v].ptl[j]->ptile == 0.75)
2092 if ( hinge != SYSMIS)
2093 tab_float (tbl, n_cols - n_percentiles + j,
2094 heading_rows + row_var_start + 1 + i * PERCENTILE_ROWS,
2104 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
2106 tab_title (tbl, _("Percentiles"));
2109 for (i = 0 ; i < n_percentiles; ++i )
2111 tab_text (tbl, n_cols - n_percentiles + i, 1,
2112 TAB_CENTER | TAT_TITLE | TAT_PRINTF,
2114 subc_list_double_at (&percentile_list, i)
2120 tab_joint_text (tbl,
2121 n_cols - n_percentiles, 0,
2123 TAB_CENTER | TAT_TITLE,
2126 /* Vertical lines for the data only */
2130 n_cols - n_percentiles, 1,
2131 n_cols - 1, n_rows - 1);
2133 tab_hline (tbl, TAL_1, n_cols - n_percentiles, n_cols - 1, 1);
2141 factor_to_string_concise (const struct xfactor *fctr,
2142 const struct factor_result *result,
2146 if (fctr->indep_var[0])
2148 var_append_value_name (fctr->indep_var[0], result->value[0], str);
2150 if ( fctr->indep_var[1] )
2152 ds_put_cstr (str, ",");
2154 var_append_value_name (fctr->indep_var[1], result->value[1], str);
2156 ds_put_cstr (str, ")");
2163 factor_to_string (const struct xfactor *fctr,
2164 const struct factor_result *result,
2168 if (fctr->indep_var[0])
2170 ds_put_format (str, "(%s = ", var_get_name (fctr->indep_var[0]));
2172 var_append_value_name (fctr->indep_var[0], result->value[0], str);
2174 if ( fctr->indep_var[1] )
2176 ds_put_cstr (str, ",");
2177 ds_put_format (str, "%s = ", var_get_name (fctr->indep_var[1]));
2179 var_append_value_name (fctr->indep_var[1], result->value[1], str);
2181 ds_put_cstr (str, ")");