1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004, 2008, 2009, 2010 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>
24 #include <math/sort.h>
25 #include <math/order-stats.h>
26 #include <math/percentiles.h>
27 #include <math/tukey-hinges.h>
28 #include <math/box-whisker.h>
29 #include <math/trimmed-mean.h>
30 #include <math/extrema.h>
32 #include <data/case.h>
33 #include <data/casegrouper.h>
34 #include <data/casereader.h>
35 #include <data/casewriter.h>
36 #include <data/dictionary.h>
37 #include <data/procedure.h>
38 #include <data/subcase.h>
39 #include <data/value-labels.h>
40 #include <data/variable.h>
41 #include <language/command.h>
42 #include <language/dictionary/split-file.h>
43 #include <language/lexer/lexer.h>
44 #include <libpspp/compiler.h>
45 #include <libpspp/message.h>
46 #include <libpspp/misc.h>
47 #include <libpspp/str.h>
48 #include <math/moments.h>
49 #include <output/chart-item.h>
50 #include <output/charts/boxplot.h>
51 #include <output/charts/np-plot.h>
52 #include <output/tab.h>
58 #define _(msgid) gettext (msgid)
59 #define N_(msgid) msgid
62 #include <output/charts/plot-hist.h>
63 #include <math/histogram.h>
70 missing=miss:pairwise/!listwise,
72 incl:include/!exclude;
73 +compare=cmp:variables/!groups;
76 +plot[plt_]=stemleaf,boxplot,npplot,:spreadlevel(*d:n),histogram,all,none;
78 +statistics[st_]=descriptives,:extreme(*d:n),all,none.
86 static struct cmd_examine cmd;
88 static const struct variable **dependent_vars;
89 static size_t n_dependent_vars;
93 static subc_list_double percentile_list;
94 static enum pc_alg percentile_algorithm;
98 struct moments1 *moments;
100 struct percentile **ptl;
103 struct tukey_hinges *tukey_hinges;
104 struct box_whisker *box_whisker;
105 struct trimmed_mean *trimmed_mean;
106 struct histogram *histogram;
109 /* Three quartiles indexing into PTL */
110 struct percentile **quartiles;
112 /* A reader sorted in ASCENDING order */
113 struct casereader *up_reader;
115 /* The minimum value of all the weights */
118 /* Sum of all weights, including those for missing values */
121 /* Sum of weights of non_missing values */
134 struct extrema *minima;
135 struct extrema *maxima;
142 union value value[2];
144 /* An array of factor metrics, one for each variable */
145 struct factor_metrics *metrics;
150 /* We need to make a list of this structure */
153 /* The independent variable */
154 const struct variable const* indep_var[2];
156 /* A list of results for this factor */
157 struct ll_list result_list ;
162 factor_destroy (struct xfactor *fctr)
164 struct ll *ll = ll_head (&fctr->result_list);
165 while (ll != ll_null (&fctr->result_list))
168 struct factor_result *result =
169 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->parent.parent);
179 statistic_destroy (&result->metrics[v].tukey_hinges->parent.parent);
180 statistic_destroy (&result->metrics[v].box_whisker->parent.parent);
181 statistic_destroy (&result->metrics[v].histogram->parent);
182 for (i = 0 ; i < result->metrics[v].n_ptiles; ++i)
183 statistic_destroy (&result->metrics[v].ptl[i]->parent.parent);
184 free (result->metrics[v].ptl);
185 free (result->metrics[v].quartiles);
186 casereader_destroy (result->metrics[v].up_reader);
189 for (i = 0; i < 2; i++)
190 if (fctr->indep_var[i])
191 value_destroy (&result->value[i],
192 var_get_width (fctr->indep_var[i]));
193 free (result->metrics);
199 static struct xfactor level0_factor;
200 static struct ll_list factor_list;
202 /* Parse the clause specifying the factors */
203 static int examine_parse_independent_vars (struct lexer *lexer,
204 const struct dictionary *dict,
205 struct cmd_examine *cmd);
207 /* Output functions */
208 static void show_summary (const struct variable **dependent_var, int n_dep_var,
209 const struct dictionary *dict,
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 (const struct dictionary *dict);
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;
322 show_npplot (const struct variable **dependent_var,
324 const struct xfactor *fctr)
328 for (v = 0; v < n_dep_var; ++v)
331 for (ll = ll_head (&fctr->result_list);
332 ll != ll_null (&fctr->result_list);
336 const struct factor_result *result =
337 ll_data (ll, struct factor_result, ll);
338 struct chart_item *npp, *dnpp;
339 struct casereader *reader;
342 ds_init_empty (&label);
343 ds_put_format (&label, "%s ", var_get_name (dependent_var[v]));
344 factor_to_string (fctr, result, &label);
346 np = result->metrics[v].np;
347 reader = casewriter_make_reader (np->writer);
348 npp = np_plot_create (np, reader, ds_cstr (&label));
349 dnpp = dnp_plot_create (np, reader, ds_cstr (&label));
353 if (npp == NULL || dnpp == NULL)
355 msg (MW, _("Not creating NP plot because data set is empty."));
356 chart_item_unref (npp);
357 chart_item_unref (dnpp);
361 chart_item_submit (npp);
362 chart_item_submit (dnpp);
365 statistic_destroy (&np->parent.parent);
366 casereader_destroy (reader);
373 show_histogram (const struct variable **dependent_var,
375 const struct xfactor *fctr)
379 for (v = 0; v < n_dep_var; ++v)
382 for (ll = ll_head (&fctr->result_list);
383 ll != ll_null (&fctr->result_list);
387 const struct factor_result *result =
388 ll_data (ll, struct factor_result, ll);
389 struct histogram *histogram;
392 histogram = result->metrics[v].histogram;
393 if (histogram == NULL)
395 /* Probably all values are SYSMIS. */
399 ds_init_empty (&str);
400 ds_put_format (&str, "%s ", var_get_name (dependent_var[v]));
402 factor_to_string (fctr, result, &str);
404 moments1_calculate (result->metrics[v].moments,
405 &n, &mean, &var, NULL, NULL);
406 chart_item_submit (histogram_chart_create (histogram->gsl_hist,
407 ds_cstr (&str), n, mean,
418 show_boxplot_groups (const struct variable **dependent_var,
420 const struct xfactor *fctr)
424 for (v = 0; v < n_dep_var; ++v)
426 const struct factor_result *result;
427 struct boxplot *boxplot;
428 double y_min = DBL_MAX;
429 double y_max = -DBL_MAX;
432 ll_for_each (result, struct factor_result, ll, &fctr->result_list)
434 struct factor_metrics *metrics = &result->metrics[v];
435 const struct ll_list *max_list = extrema_list (metrics->maxima);
436 const struct ll_list *min_list = extrema_list (metrics->minima);
437 const struct extremum *max, *min;
439 if ( ll_is_empty (max_list))
441 msg (MW, _("Not creating plot because data set is empty."));
445 max = ll_data (ll_head(max_list), struct extremum, ll);
446 min = ll_data (ll_head (min_list), struct extremum, ll);
448 y_max = MAX (y_max, max->value);
449 y_min = MIN (y_min, min->value);
452 if (fctr->indep_var[0])
453 title = xasprintf (_("Boxplot of %s vs. %s"),
454 var_to_string (dependent_var[v]),
455 var_to_string (fctr->indep_var[0]));
457 title = xasprintf (_("Boxplot of %s"),
458 var_to_string (dependent_var[v]));
459 boxplot = boxplot_create (y_min, y_max, title);
462 ll_for_each (result, struct factor_result, ll, &fctr->result_list)
464 struct factor_metrics *metrics = &result->metrics[v];
465 struct string str = DS_EMPTY_INITIALIZER;
466 factor_to_string_concise (fctr, result, &str);
467 boxplot_add_box (boxplot, metrics->box_whisker, ds_cstr (&str));
468 metrics->box_whisker = NULL;
472 boxplot_submit (boxplot);
479 show_boxplot_variables (const struct variable **dependent_var,
481 const struct xfactor *fctr
485 const struct factor_result *result;
488 ll_for_each (result, struct factor_result, ll, &fctr->result_list)
491 double y_min = DBL_MAX;
492 double y_max = -DBL_MAX;
493 struct boxplot *boxplot;
495 for (v = 0; v < n_dep_var; ++v)
497 const struct factor_metrics *metrics = &result->metrics[v];
498 const struct ll *max_ll = ll_head (extrema_list (metrics->maxima));
499 const struct ll *min_ll = ll_head (extrema_list (metrics->minima));
500 const struct extremum *max = ll_data (max_ll, struct extremum, ll);
501 const struct extremum *min = ll_data (min_ll, struct extremum, ll);
503 y_max = MAX (y_max, max->value);
504 y_min = MIN (y_min, min->value);
507 ds_init_empty (&title);
508 factor_to_string (fctr, result, &title);
509 boxplot = boxplot_create (y_min, y_max, ds_cstr (&title));
512 for (v = 0; v < n_dep_var; ++v)
514 struct factor_metrics *metrics = &result->metrics[v];
515 boxplot_add_box (boxplot, metrics->box_whisker,
516 var_get_name (dependent_var[v]));
517 metrics->box_whisker = NULL;
520 boxplot_submit (boxplot);
525 /* Show all the appropriate tables */
527 output_examine (const struct dictionary *dict)
531 show_summary (dependent_vars, n_dependent_vars, dict, &level0_factor);
533 if ( cmd.a_statistics[XMN_ST_EXTREME] )
534 show_extremes (dependent_vars, n_dependent_vars, &level0_factor);
536 if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES] )
537 show_descriptives (dependent_vars, n_dependent_vars, &level0_factor);
539 if ( cmd.sbc_percentiles)
540 show_percentiles (dependent_vars, n_dependent_vars, &level0_factor);
544 if (cmd.a_plot[XMN_PLT_BOXPLOT])
545 show_boxplot_groups (dependent_vars, n_dependent_vars, &level0_factor);
547 if (cmd.a_plot[XMN_PLT_HISTOGRAM])
548 show_histogram (dependent_vars, n_dependent_vars, &level0_factor);
550 if (cmd.a_plot[XMN_PLT_NPPLOT])
551 show_npplot (dependent_vars, n_dependent_vars, &level0_factor);
554 for (ll = ll_head (&factor_list);
555 ll != ll_null (&factor_list); ll = ll_next (ll))
557 struct xfactor *factor = ll_data (ll, struct xfactor, ll);
558 show_summary (dependent_vars, n_dependent_vars, dict, factor);
560 if ( cmd.a_statistics[XMN_ST_EXTREME] )
561 show_extremes (dependent_vars, n_dependent_vars, factor);
563 if ( cmd.a_statistics[XMN_ST_DESCRIPTIVES] )
564 show_descriptives (dependent_vars, n_dependent_vars, factor);
566 if ( cmd.sbc_percentiles)
567 show_percentiles (dependent_vars, n_dependent_vars, factor);
569 if (cmd.a_plot[XMN_PLT_BOXPLOT])
571 if (cmd.cmp == XMN_GROUPS)
572 show_boxplot_groups (dependent_vars, n_dependent_vars, factor);
573 else if (cmd.cmp == XMN_VARIABLES)
574 show_boxplot_variables (dependent_vars, n_dependent_vars, factor);
577 if (cmd.a_plot[XMN_PLT_HISTOGRAM])
578 show_histogram (dependent_vars, n_dependent_vars, factor);
580 if (cmd.a_plot[XMN_PLT_NPPLOT])
581 show_npplot (dependent_vars, n_dependent_vars, factor);
585 /* Parse the PERCENTILES subcommand */
587 xmn_custom_percentiles (struct lexer *lexer, struct dataset *ds UNUSED,
588 struct cmd_examine *p UNUSED, void *aux UNUSED)
590 lex_match (lexer, T_EQUALS);
592 lex_match (lexer, T_LPAREN);
594 while ( lex_is_number (lexer) )
596 subc_list_double_push (&percentile_list, lex_number (lexer));
600 lex_match (lexer, T_COMMA) ;
602 lex_match (lexer, T_RPAREN);
604 lex_match (lexer, T_EQUALS);
606 if ( lex_match_id (lexer, "HAVERAGE"))
607 percentile_algorithm = PC_HAVERAGE;
609 else if ( lex_match_id (lexer, "WAVERAGE"))
610 percentile_algorithm = PC_WAVERAGE;
612 else if ( lex_match_id (lexer, "ROUND"))
613 percentile_algorithm = PC_ROUND;
615 else if ( lex_match_id (lexer, "EMPIRICAL"))
616 percentile_algorithm = PC_EMPIRICAL;
618 else if ( lex_match_id (lexer, "AEMPIRICAL"))
619 percentile_algorithm = PC_AEMPIRICAL;
621 else if ( lex_match_id (lexer, "NONE"))
622 percentile_algorithm = PC_NONE;
625 if ( 0 == subc_list_double_count (&percentile_list))
627 subc_list_double_push (&percentile_list, 5);
628 subc_list_double_push (&percentile_list, 10);
629 subc_list_double_push (&percentile_list, 25);
630 subc_list_double_push (&percentile_list, 50);
631 subc_list_double_push (&percentile_list, 75);
632 subc_list_double_push (&percentile_list, 90);
633 subc_list_double_push (&percentile_list, 95);
639 /* TOTAL and NOTOTAL are simple, mutually exclusive flags */
641 xmn_custom_total (struct lexer *lexer UNUSED, struct dataset *ds UNUSED,
642 struct cmd_examine *p, void *aux UNUSED)
644 if ( p->sbc_nototal )
646 msg (SE, _("%s and %s are mutually exclusive"),"TOTAL","NOTOTAL");
654 xmn_custom_nototal (struct lexer *lexer UNUSED, struct dataset *ds UNUSED,
655 struct cmd_examine *p, void *aux UNUSED)
659 msg (SE, _("%s and %s are mutually exclusive"), "TOTAL", "NOTOTAL");
668 /* Parser for the variables sub command
669 Returns 1 on success */
671 xmn_custom_variables (struct lexer *lexer, struct dataset *ds,
672 struct cmd_examine *cmd,
675 const struct dictionary *dict = dataset_dict (ds);
676 lex_match (lexer, T_EQUALS);
678 if ( (lex_token (lexer) != T_ID || dict_lookup_var (dict, lex_tokcstr (lexer)) == NULL)
679 && lex_token (lexer) != T_ALL)
684 if (!parse_variables_const (lexer, dict, &dependent_vars, &n_dependent_vars,
685 PV_NO_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH) )
687 free (dependent_vars);
691 assert (n_dependent_vars);
694 if ( lex_match (lexer, T_BY))
697 success = examine_parse_independent_vars (lexer, dict, cmd);
700 free (dependent_vars);
710 /* Parse the clause specifying the factors */
712 examine_parse_independent_vars (struct lexer *lexer,
713 const struct dictionary *dict,
714 struct cmd_examine *cmd)
717 struct xfactor *sf = xmalloc (sizeof *sf);
719 ll_init (&sf->result_list);
721 if ( (lex_token (lexer) != T_ID ||
722 dict_lookup_var (dict, lex_tokcstr (lexer)) == NULL)
723 && lex_token (lexer) != T_ALL)
729 sf->indep_var[0] = parse_variable (lexer, dict);
730 sf->indep_var[1] = NULL;
732 if ( lex_token (lexer) == T_BY )
734 lex_match (lexer, T_BY);
736 if ( (lex_token (lexer) != T_ID ||
737 dict_lookup_var (dict, lex_tokcstr (lexer)) == NULL)
738 && lex_token (lexer) != T_ALL)
744 sf->indep_var[1] = parse_variable (lexer, dict);
746 ll_push_tail (&factor_list, &sf->ll);
749 ll_push_tail (&factor_list, &sf->ll);
751 lex_match (lexer, T_COMMA);
753 if ( lex_token (lexer) == T_ENDCMD || lex_token (lexer) == T_SLASH )
756 success = examine_parse_independent_vars (lexer, dict, cmd);
765 examine_group (struct cmd_examine *cmd, struct casereader *reader, int level,
766 const struct dictionary *dict, struct xfactor *factor)
769 const struct variable *wv = dict_get_weight (dict);
772 struct factor_result *result = xzalloc (sizeof (*result));
775 for (i = 0; i < 2; i++)
776 if (factor->indep_var[i])
777 value_init (&result->value[i], var_get_width (factor->indep_var[i]));
779 result->metrics = xcalloc (n_dependent_vars, sizeof (*result->metrics));
781 if ( cmd->a_statistics[XMN_ST_EXTREME] )
782 n_extrema = cmd->st_n;
785 c = casereader_peek (reader, 0);
789 for (i = 0; i < 2; i++)
790 if (factor->indep_var[i])
791 value_copy (&result->value[i], case_data (c, factor->indep_var[i]),
792 var_get_width (factor->indep_var[i]));
796 for (v = 0; v < n_dependent_vars; ++v)
798 struct casewriter *writer;
799 struct casereader *input = casereader_clone (reader);
801 result->metrics[v].moments = moments1_create (MOMENT_KURTOSIS);
802 result->metrics[v].minima = extrema_create (n_extrema, EXTREME_MINIMA);
803 result->metrics[v].maxima = extrema_create (n_extrema, EXTREME_MAXIMA);
804 result->metrics[v].cmin = DBL_MAX;
806 if (cmd->a_statistics[XMN_ST_DESCRIPTIVES] ||
807 cmd->a_plot[XMN_PLT_BOXPLOT] ||
808 cmd->a_plot[XMN_PLT_NPPLOT] ||
809 cmd->sbc_percentiles)
811 /* In this case, we need to sort the data, so we create a sorting
813 struct subcase up_ordering;
814 subcase_init_var (&up_ordering, dependent_vars[v], SC_ASCEND);
815 writer = sort_create_writer (&up_ordering,
816 casereader_get_proto (reader));
817 subcase_destroy (&up_ordering);
821 /* but in this case, sorting is unnecessary, so an ordinary
822 casewriter is sufficient */
824 autopaging_writer_create (casereader_get_proto (reader));
828 /* Sort or just iterate, whilst calculating moments etc */
829 while ((c = casereader_read (input)) != NULL)
831 int n_vals = caseproto_get_n_widths (casereader_get_proto (reader));
832 const casenumber loc = case_data_idx (c, n_vals - 1)->f;
834 const double weight = wv ? case_data (c, wv)->f : 1.0;
835 const union value *value = case_data (c, dependent_vars[v]);
837 if (weight != SYSMIS)
838 minimize (&result->metrics[v].cmin, weight);
840 moments1_add (result->metrics[v].moments,
844 result->metrics[v].n += weight;
846 if ( ! var_is_value_missing (dependent_vars[v], value, MV_ANY) )
847 result->metrics[v].n_valid += weight;
849 extrema_add (result->metrics[v].maxima,
854 extrema_add (result->metrics[v].minima,
859 casewriter_write (writer, c);
861 casereader_destroy (input);
862 result->metrics[v].up_reader = casewriter_make_reader (writer);
865 /* If percentiles or descriptives have been requested, then a
866 second pass through the data (which has now been sorted)
868 if ( cmd->a_statistics[XMN_ST_DESCRIPTIVES] ||
869 cmd->a_plot[XMN_PLT_BOXPLOT] ||
870 cmd->a_plot[XMN_PLT_NPPLOT] ||
871 cmd->sbc_percentiles)
873 for (v = 0; v < n_dependent_vars; ++v)
877 struct order_stats **os ;
878 struct factor_metrics *metric = &result->metrics[v];
880 metric->n_ptiles = percentile_list.n_data;
882 metric->ptl = xcalloc (metric->n_ptiles, sizeof *metric->ptl);
884 metric->quartiles = xcalloc (3, sizeof (*metric->quartiles));
886 for (i = 0 ; i < metric->n_ptiles; ++i)
888 metric->ptl[i] = percentile_create (percentile_list.data[i] / 100.0, metric->n_valid);
890 if ( percentile_list.data[i] == 25)
891 metric->quartiles[0] = metric->ptl[i];
892 else if ( percentile_list.data[i] == 50)
893 metric->quartiles[1] = metric->ptl[i];
894 else if ( percentile_list.data[i] == 75)
895 metric->quartiles[2] = metric->ptl[i];
898 metric->tukey_hinges = tukey_hinges_create (metric->n_valid, metric->cmin);
899 metric->trimmed_mean = trimmed_mean_create (metric->n_valid, 0.05);
901 n_os = metric->n_ptiles + 2;
903 if ( cmd->a_plot[XMN_PLT_NPPLOT] )
905 metric->np = np_create (metric->moments);
909 os = xcalloc (n_os, sizeof *os);
911 for (i = 0 ; i < metric->n_ptiles ; ++i )
913 os[i] = &metric->ptl[i]->parent;
916 os[i] = &metric->tukey_hinges->parent;
917 os[i+1] = &metric->trimmed_mean->parent;
919 if (cmd->a_plot[XMN_PLT_NPPLOT])
920 os[i+2] = &metric->np->parent;
922 order_stats_accumulate (os, n_os,
923 casereader_clone (metric->up_reader),
924 wv, dependent_vars[v], MV_ANY);
929 /* FIXME: Do this in the above loop */
930 if ( cmd->a_plot[XMN_PLT_HISTOGRAM] )
933 struct casereader *input = casereader_clone (reader);
935 for (v = 0; v < n_dependent_vars; ++v)
937 const struct extremum *max, *min;
938 struct factor_metrics *metric = &result->metrics[v];
940 const struct ll_list *max_list =
941 extrema_list (result->metrics[v].maxima);
943 const struct ll_list *min_list =
944 extrema_list (result->metrics[v].minima);
946 if ( ll_is_empty (max_list))
948 msg (MW, _("Not creating plot because data set is empty."));
952 assert (! ll_is_empty (min_list));
954 max = (const struct extremum *)
955 ll_data (ll_head(max_list), struct extremum, ll);
957 min = (const struct extremum *)
958 ll_data (ll_head (min_list), struct extremum, ll);
960 metric->histogram = histogram_create (10, min->value, max->value);
963 while ((c = casereader_read (input)) != NULL)
965 const double weight = wv ? case_data (c, wv)->f : 1.0;
967 for (v = 0; v < n_dependent_vars; ++v)
969 struct factor_metrics *metric = &result->metrics[v];
970 if ( metric->histogram)
971 histogram_add (metric->histogram,
972 case_data (c, dependent_vars[v])->f, weight);
976 casereader_destroy (input);
979 /* In this case, a third iteration is required */
980 if (cmd->a_plot[XMN_PLT_BOXPLOT])
982 for (v = 0; v < n_dependent_vars; ++v)
984 struct factor_metrics *metric = &result->metrics[v];
985 int n_vals = caseproto_get_n_widths (casereader_get_proto (
987 struct order_stats *os;
989 metric->box_whisker =
990 box_whisker_create ( metric->tukey_hinges, cmd->v_id, n_vals - 1);
992 os = &metric->box_whisker->parent;
993 order_stats_accumulate ( &os, 1,
994 casereader_clone (metric->up_reader),
995 wv, dependent_vars[v], MV_ANY);
999 ll_push_tail (&factor->result_list, &result->ll);
1000 casereader_destroy (reader);
1005 run_examine (struct cmd_examine *cmd, struct casereader *input,
1009 const struct dictionary *dict = dataset_dict (ds);
1011 struct casereader *level0 = casereader_clone (input);
1013 c = casereader_peek (input, 0);
1016 casereader_destroy (input);
1020 output_split_file_values (ds, c);
1023 ll_init (&level0_factor.result_list);
1025 examine_group (cmd, level0, 0, dict, &level0_factor);
1027 for (ll = ll_head (&factor_list);
1028 ll != ll_null (&factor_list);
1031 struct xfactor *factor = ll_data (ll, struct xfactor, ll);
1033 struct casereader *group = NULL;
1034 struct casereader *level1;
1035 struct casegrouper *grouper1 = NULL;
1037 level1 = casereader_clone (input);
1038 level1 = sort_execute_1var (level1, factor->indep_var[0]);
1039 grouper1 = casegrouper_create_vars (level1, &factor->indep_var[0], 1);
1041 while (casegrouper_get_next_group (grouper1, &group))
1043 struct casereader *group_copy = casereader_clone (group);
1045 if ( !factor->indep_var[1])
1046 examine_group (cmd, group_copy, 1, dict, factor);
1050 struct casereader *group2 = NULL;
1051 struct casegrouper *grouper2 = NULL;
1053 group_copy = sort_execute_1var (group_copy,
1054 factor->indep_var[1]);
1056 grouper2 = casegrouper_create_vars (group_copy,
1057 &factor->indep_var[1], 1);
1059 while (casegrouper_get_next_group (grouper2, &group2))
1061 examine_group (cmd, group2, 2, dict, factor);
1064 casegrouper_destroy (grouper2);
1067 casereader_destroy (group);
1069 casegrouper_destroy (grouper1);
1072 casereader_destroy (input);
1074 output_examine (dict);
1076 factor_destroy (&level0_factor);
1080 for (ll = ll_head (&factor_list);
1081 ll != ll_null (&factor_list);
1084 struct xfactor *f = ll_data (ll, struct xfactor, ll);
1093 show_summary (const struct variable **dependent_var, int n_dep_var,
1094 const struct dictionary *dict,
1095 const struct xfactor *fctr)
1097 const struct variable *wv = dict_get_weight (dict);
1098 const struct fmt_spec *wfmt = wv ? var_get_print_format (wv) : & F_8_0;
1100 static const char *subtitle[]=
1108 int heading_columns = 1;
1110 const int heading_rows = 3;
1111 struct tab_table *tbl;
1118 if ( fctr->indep_var[0] )
1120 heading_columns = 2;
1122 if ( fctr->indep_var[1] )
1124 heading_columns = 3;
1128 n_rows *= ll_count (&fctr->result_list);
1129 n_rows += heading_rows;
1131 n_cols = heading_columns + 6;
1133 tbl = tab_create (n_cols, n_rows);
1134 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1136 /* Outline the box */
1141 n_cols - 1, n_rows - 1);
1143 /* Vertical lines for the data only */
1148 n_cols - 1, n_rows - 1);
1151 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1152 tab_hline (tbl, TAL_1, heading_columns, n_cols - 1, 1 );
1153 tab_hline (tbl, TAL_1, heading_columns, n_cols - 1, heading_rows -1 );
1155 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1158 tab_title (tbl, _("Case Processing Summary"));
1160 tab_joint_text (tbl, heading_columns, 0,
1162 TAB_CENTER | TAT_TITLE,
1165 /* Remove lines ... */
1172 for (j = 0 ; j < 3 ; ++j)
1174 tab_text (tbl, heading_columns + j * 2 , 2, TAB_CENTER | TAT_TITLE,
1177 tab_text (tbl, heading_columns + j * 2 + 1, 2, TAB_CENTER | TAT_TITLE,
1180 tab_joint_text (tbl, heading_columns + j * 2 , 1,
1181 heading_columns + j * 2 + 1, 1,
1182 TAB_CENTER | TAT_TITLE,
1185 tab_box (tbl, -1, -1,
1187 heading_columns + j * 2, 1,
1188 heading_columns + j * 2 + 1, 1);
1192 /* Titles for the independent variables */
1193 if ( fctr->indep_var[0] )
1195 tab_text (tbl, 1, heading_rows - 1, TAB_CENTER | TAT_TITLE,
1196 var_to_string (fctr->indep_var[0]));
1198 if ( fctr->indep_var[1] )
1200 tab_text (tbl, 2, heading_rows - 1, TAB_CENTER | TAT_TITLE,
1201 var_to_string (fctr->indep_var[1]));
1205 for (v = 0 ; v < n_dep_var ; ++v)
1209 const union value *last_value = NULL;
1212 tab_hline (tbl, TAL_1, 0, n_cols -1 ,
1213 v * ll_count (&fctr->result_list)
1218 v * ll_count (&fctr->result_list) + heading_rows,
1219 TAB_LEFT | TAT_TITLE,
1220 var_to_string (dependent_var[v])
1224 for (ll = ll_head (&fctr->result_list);
1225 ll != ll_null (&fctr->result_list); ll = ll_next (ll))
1228 const struct factor_result *result =
1229 ll_data (ll, struct factor_result, ll);
1231 if ( fctr->indep_var[0] )
1234 if ( last_value == NULL ||
1235 !value_equal (last_value, &result->value[0],
1236 var_get_width (fctr->indep_var[0])))
1240 last_value = &result->value[0];
1241 ds_init_empty (&str);
1243 var_append_value_name (fctr->indep_var[0], &result->value[0],
1248 v * ll_count (&fctr->result_list),
1249 TAB_LEFT | TAT_TITLE,
1254 if ( fctr->indep_var[1] && j > 0)
1255 tab_hline (tbl, TAL_1, 1, n_cols - 1,
1257 v * ll_count (&fctr->result_list));
1260 if ( fctr->indep_var[1])
1264 ds_init_empty (&str);
1266 var_append_value_name (fctr->indep_var[1],
1267 &result->value[1], &str);
1271 v * ll_count (&fctr->result_list),
1272 TAB_LEFT | TAT_TITLE,
1280 moments1_calculate (result->metrics[v].moments,
1281 &n, &result->metrics[v].mean,
1282 &result->metrics[v].variance,
1283 &result->metrics[v].skewness,
1284 &result->metrics[v].kurtosis);
1286 result->metrics[v].se_mean = sqrt (result->metrics[v].variance / n) ;
1289 tab_double (tbl, heading_columns,
1290 heading_rows + j + v * ll_count (&fctr->result_list),
1294 tab_text_format (tbl, heading_columns + 1,
1295 heading_rows + j + v * ll_count (&fctr->result_list),
1297 "%g%%", n * 100.0 / result->metrics[v].n);
1300 tab_double (tbl, heading_columns + 2,
1301 heading_rows + j + v * ll_count (&fctr->result_list),
1303 result->metrics[v].n - n,
1306 tab_text_format (tbl, heading_columns + 3,
1307 heading_rows + j + v * ll_count (&fctr->result_list),
1310 (result->metrics[v].n - n) * 100.0 / result->metrics[v].n
1313 /* Total Valid + Missing */
1314 tab_double (tbl, heading_columns + 4,
1315 heading_rows + j + v * ll_count (&fctr->result_list),
1317 result->metrics[v].n,
1320 tab_text_format (tbl, heading_columns + 5,
1321 heading_rows + j + v * ll_count (&fctr->result_list),
1324 ((result->metrics[v].n) * 100.0
1325 / result->metrics[v].n));
1335 #define DESCRIPTIVE_ROWS 13
1338 show_descriptives (const struct variable **dependent_var,
1340 const struct xfactor *fctr)
1343 int heading_columns = 3;
1345 const int heading_rows = 1;
1346 struct tab_table *tbl;
1353 if ( fctr->indep_var[0] )
1355 heading_columns = 4;
1357 if ( fctr->indep_var[1] )
1359 heading_columns = 5;
1363 n_rows *= ll_count (&fctr->result_list) * DESCRIPTIVE_ROWS;
1364 n_rows += heading_rows;
1366 n_cols = heading_columns + 2;
1368 tbl = tab_create (n_cols, n_rows);
1369 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1371 /* Outline the box */
1376 n_cols - 1, n_rows - 1);
1379 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1380 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
1382 tab_vline (tbl, TAL_1, n_cols - 1, 0, n_rows - 1);
1385 if ( fctr->indep_var[0])
1386 tab_text (tbl, 1, 0, TAT_TITLE, var_to_string (fctr->indep_var[0]));
1388 if ( fctr->indep_var[1])
1389 tab_text (tbl, 2, 0, TAT_TITLE, var_to_string (fctr->indep_var[1]));
1391 for (v = 0 ; v < n_dep_var ; ++v )
1396 const int row_var_start =
1397 v * DESCRIPTIVE_ROWS * ll_count(&fctr->result_list);
1401 heading_rows + row_var_start,
1402 TAB_LEFT | TAT_TITLE,
1403 var_to_string (dependent_var[v])
1406 for (ll = ll_head (&fctr->result_list);
1407 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
1409 const struct factor_result *result =
1410 ll_data (ll, struct factor_result, ll);
1413 gsl_cdf_tdist_Qinv ((1 - cmd.n_cinterval[0] / 100.0) / 2.0,
1414 result->metrics[v].n - 1);
1416 if ( i > 0 || v > 0 )
1418 const int left_col = (i == 0) ? 0 : 1;
1419 tab_hline (tbl, TAL_1, left_col, n_cols - 1,
1420 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS);
1423 if ( fctr->indep_var[0])
1426 ds_init_empty (&vstr);
1427 var_append_value_name (fctr->indep_var[0],
1428 &result->value[0], &vstr);
1431 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1440 tab_text (tbl, n_cols - 4,
1441 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1445 tab_text_format (tbl, n_cols - 4,
1446 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1448 _("%g%% Confidence Interval for Mean"),
1449 cmd.n_cinterval[0]);
1451 tab_text (tbl, n_cols - 3,
1452 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1456 tab_text (tbl, n_cols - 3,
1457 heading_rows + row_var_start + 2 + i * DESCRIPTIVE_ROWS,
1461 tab_text (tbl, n_cols - 4,
1462 heading_rows + row_var_start + 3 + i * DESCRIPTIVE_ROWS,
1463 TAB_LEFT, _("5% Trimmed Mean"));
1465 tab_text (tbl, n_cols - 4,
1466 heading_rows + row_var_start + 4 + i * DESCRIPTIVE_ROWS,
1470 tab_text (tbl, n_cols - 4,
1471 heading_rows + row_var_start + 5 + i * DESCRIPTIVE_ROWS,
1475 tab_text (tbl, n_cols - 4,
1476 heading_rows + row_var_start + 6 + i * DESCRIPTIVE_ROWS,
1478 _("Std. Deviation"));
1480 tab_text (tbl, n_cols - 4,
1481 heading_rows + row_var_start + 7 + i * DESCRIPTIVE_ROWS,
1485 tab_text (tbl, n_cols - 4,
1486 heading_rows + row_var_start + 8 + i * DESCRIPTIVE_ROWS,
1490 tab_text (tbl, n_cols - 4,
1491 heading_rows + row_var_start + 9 + i * DESCRIPTIVE_ROWS,
1495 tab_text (tbl, n_cols - 4,
1496 heading_rows + row_var_start + 10 + i * DESCRIPTIVE_ROWS,
1498 _("Interquartile Range"));
1501 tab_text (tbl, n_cols - 4,
1502 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1506 tab_text (tbl, n_cols - 4,
1507 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1512 /* Now the statistics ... */
1514 tab_double (tbl, n_cols - 2,
1515 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1517 result->metrics[v].mean,
1520 tab_double (tbl, n_cols - 1,
1521 heading_rows + row_var_start + i * DESCRIPTIVE_ROWS,
1523 result->metrics[v].se_mean,
1527 tab_double (tbl, n_cols - 2,
1528 heading_rows + row_var_start + 1 + i * DESCRIPTIVE_ROWS,
1530 result->metrics[v].mean - t *
1531 result->metrics[v].se_mean,
1534 tab_double (tbl, n_cols - 2,
1535 heading_rows + row_var_start + 2 + i * DESCRIPTIVE_ROWS,
1537 result->metrics[v].mean + t *
1538 result->metrics[v].se_mean,
1542 tab_double (tbl, n_cols - 2,
1543 heading_rows + row_var_start + 3 + i * DESCRIPTIVE_ROWS,
1545 trimmed_mean_calculate (result->metrics[v].trimmed_mean),
1549 tab_double (tbl, n_cols - 2,
1550 heading_rows + row_var_start + 4 + i * DESCRIPTIVE_ROWS,
1552 percentile_calculate (result->metrics[v].quartiles[1], percentile_algorithm),
1556 tab_double (tbl, n_cols - 2,
1557 heading_rows + row_var_start + 5 + i * DESCRIPTIVE_ROWS,
1559 result->metrics[v].variance,
1562 tab_double (tbl, n_cols - 2,
1563 heading_rows + row_var_start + 6 + i * DESCRIPTIVE_ROWS,
1565 sqrt (result->metrics[v].variance),
1568 tab_double (tbl, n_cols - 2,
1569 heading_rows + row_var_start + 10 + i * DESCRIPTIVE_ROWS,
1571 percentile_calculate (result->metrics[v].quartiles[2],
1572 percentile_algorithm) -
1573 percentile_calculate (result->metrics[v].quartiles[0],
1574 percentile_algorithm),
1578 tab_double (tbl, n_cols - 2,
1579 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1581 result->metrics[v].skewness,
1584 tab_double (tbl, n_cols - 2,
1585 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1587 result->metrics[v].kurtosis,
1590 tab_double (tbl, n_cols - 1,
1591 heading_rows + row_var_start + 11 + i * DESCRIPTIVE_ROWS,
1593 calc_seskew (result->metrics[v].n),
1596 tab_double (tbl, n_cols - 1,
1597 heading_rows + row_var_start + 12 + i * DESCRIPTIVE_ROWS,
1599 calc_sekurt (result->metrics[v].n),
1603 struct extremum *minimum, *maximum ;
1605 struct ll *max_ll = ll_head (extrema_list (result->metrics[v].maxima));
1606 struct ll *min_ll = ll_head (extrema_list (result->metrics[v].minima));
1608 maximum = ll_data (max_ll, struct extremum, ll);
1609 minimum = ll_data (min_ll, struct extremum, ll);
1611 tab_double (tbl, n_cols - 2,
1612 heading_rows + row_var_start + 7 + i * DESCRIPTIVE_ROWS,
1617 tab_double (tbl, n_cols - 2,
1618 heading_rows + row_var_start + 8 + i * DESCRIPTIVE_ROWS,
1623 tab_double (tbl, n_cols - 2,
1624 heading_rows + row_var_start + 9 + i * DESCRIPTIVE_ROWS,
1626 maximum->value - minimum->value,
1632 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1634 tab_title (tbl, _("Descriptives"));
1636 tab_text (tbl, n_cols - 2, 0, TAB_CENTER | TAT_TITLE,
1639 tab_text (tbl, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
1648 show_extremes (const struct variable **dependent_var,
1650 const struct xfactor *fctr)
1653 int heading_columns = 3;
1655 const int heading_rows = 1;
1656 struct tab_table *tbl;
1663 if ( fctr->indep_var[0] )
1665 heading_columns = 4;
1667 if ( fctr->indep_var[1] )
1669 heading_columns = 5;
1673 n_rows *= ll_count (&fctr->result_list) * cmd.st_n * 2;
1674 n_rows += heading_rows;
1676 n_cols = heading_columns + 2;
1678 tbl = tab_create (n_cols, n_rows);
1679 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1681 /* Outline the box */
1686 n_cols - 1, n_rows - 1);
1689 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1690 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
1691 tab_vline (tbl, TAL_1, n_cols - 1, 0, n_rows - 1);
1693 if ( fctr->indep_var[0])
1694 tab_text (tbl, 1, 0, TAT_TITLE, var_to_string (fctr->indep_var[0]));
1696 if ( fctr->indep_var[1])
1697 tab_text (tbl, 2, 0, TAT_TITLE, var_to_string (fctr->indep_var[1]));
1699 for (v = 0 ; v < n_dep_var ; ++v )
1703 const int row_var_start = v * cmd.st_n * 2 * ll_count(&fctr->result_list);
1707 heading_rows + row_var_start,
1708 TAB_LEFT | TAT_TITLE,
1709 var_to_string (dependent_var[v])
1712 for (ll = ll_head (&fctr->result_list);
1713 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
1718 const int row_result_start = i * cmd.st_n * 2;
1720 const struct factor_result *result =
1721 ll_data (ll, struct factor_result, ll);
1724 tab_hline (tbl, TAL_1, 1, n_cols - 1,
1725 heading_rows + row_var_start + row_result_start);
1727 tab_hline (tbl, TAL_1, heading_columns - 2, n_cols - 1,
1728 heading_rows + row_var_start + row_result_start + cmd.st_n);
1730 for ( e = 1; e <= cmd.st_n; ++e )
1732 tab_text_format (tbl, n_cols - 3,
1733 heading_rows + row_var_start + row_result_start + e - 1,
1737 tab_text_format (tbl, n_cols - 3,
1738 heading_rows + row_var_start + row_result_start + cmd.st_n + e - 1,
1744 min_ll = ll_head (extrema_list (result->metrics[v].minima));
1745 for (e = 0; e < cmd.st_n;)
1747 struct extremum *minimum = ll_data (min_ll, struct extremum, ll);
1748 double weight = minimum->weight;
1750 while (weight-- > 0 && e < cmd.st_n)
1752 tab_double (tbl, n_cols - 1,
1753 heading_rows + row_var_start + row_result_start + cmd.st_n + e,
1759 tab_fixed (tbl, n_cols - 2,
1760 heading_rows + row_var_start +
1761 row_result_start + cmd.st_n + e,
1768 min_ll = ll_next (min_ll);
1771 max_ll = ll_head (extrema_list (result->metrics[v].maxima));
1772 for (e = 0; e < cmd.st_n;)
1774 struct extremum *maximum = ll_data (max_ll, struct extremum, ll);
1775 double weight = maximum->weight;
1777 while (weight-- > 0 && e < cmd.st_n)
1779 tab_double (tbl, n_cols - 1,
1780 heading_rows + row_var_start +
1781 row_result_start + e,
1787 tab_fixed (tbl, n_cols - 2,
1788 heading_rows + row_var_start +
1789 row_result_start + e,
1796 max_ll = ll_next (max_ll);
1800 if ( fctr->indep_var[0])
1803 ds_init_empty (&vstr);
1804 var_append_value_name (fctr->indep_var[0],
1805 &result->value[0], &vstr);
1808 heading_rows + row_var_start + row_result_start,
1817 tab_text (tbl, n_cols - 4,
1818 heading_rows + row_var_start + row_result_start,
1822 tab_text (tbl, n_cols - 4,
1823 heading_rows + row_var_start + row_result_start + cmd.st_n,
1829 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1832 tab_title (tbl, _("Extreme Values"));
1835 tab_text (tbl, n_cols - 2, 0, TAB_CENTER | TAT_TITLE,
1839 tab_text (tbl, n_cols - 1, 0, TAB_CENTER | TAT_TITLE,
1845 #define PERCENTILE_ROWS 2
1848 show_percentiles (const struct variable **dependent_var,
1850 const struct xfactor *fctr)
1854 int heading_columns = 2;
1856 const int n_percentiles = subc_list_double_count (&percentile_list);
1857 const int heading_rows = 2;
1858 struct tab_table *tbl;
1865 if ( fctr->indep_var[0] )
1867 heading_columns = 3;
1869 if ( fctr->indep_var[1] )
1871 heading_columns = 4;
1875 n_rows *= ll_count (&fctr->result_list) * PERCENTILE_ROWS;
1876 n_rows += heading_rows;
1878 n_cols = heading_columns + n_percentiles;
1880 tbl = tab_create (n_cols, n_rows);
1881 tab_headers (tbl, heading_columns, 0, heading_rows, 0);
1883 /* Outline the box */
1888 n_cols - 1, n_rows - 1);
1891 tab_hline (tbl, TAL_2, 0, n_cols - 1, heading_rows );
1892 tab_hline (tbl, TAL_2, 1, n_cols - 1, heading_rows );
1894 if ( fctr->indep_var[0])
1895 tab_text (tbl, 1, 1, TAT_TITLE, var_to_string (fctr->indep_var[0]));
1897 if ( fctr->indep_var[1])
1898 tab_text (tbl, 2, 1, TAT_TITLE, var_to_string (fctr->indep_var[1]));
1900 for (v = 0 ; v < n_dep_var ; ++v )
1906 const int row_var_start =
1907 v * PERCENTILE_ROWS * ll_count(&fctr->result_list);
1911 heading_rows + row_var_start,
1912 TAB_LEFT | TAT_TITLE,
1913 var_to_string (dependent_var[v])
1916 for (ll = ll_head (&fctr->result_list);
1917 ll != ll_null (&fctr->result_list); i++, ll = ll_next (ll))
1920 const struct factor_result *result =
1921 ll_data (ll, struct factor_result, ll);
1923 if ( i > 0 || v > 0 )
1925 const int left_col = (i == 0) ? 0 : 1;
1926 tab_hline (tbl, TAL_1, left_col, n_cols - 1,
1927 heading_rows + row_var_start + i * PERCENTILE_ROWS);
1930 if ( fctr->indep_var[0])
1933 ds_init_empty (&vstr);
1934 var_append_value_name (fctr->indep_var[0],
1935 &result->value[0], &vstr);
1938 heading_rows + row_var_start + i * PERCENTILE_ROWS,
1947 tab_text (tbl, n_cols - n_percentiles - 1,
1948 heading_rows + row_var_start + i * PERCENTILE_ROWS,
1950 ptile_alg_desc [percentile_algorithm]);
1953 tab_text (tbl, n_cols - n_percentiles - 1,
1954 heading_rows + row_var_start + 1 + i * PERCENTILE_ROWS,
1956 _("Tukey's Hinges"));
1959 tab_vline (tbl, TAL_1, n_cols - n_percentiles -1, heading_rows, n_rows - 1);
1961 tukey_hinges_calculate (result->metrics[v].tukey_hinges, hinges);
1963 for (j = 0; j < n_percentiles; ++j)
1965 double hinge = SYSMIS;
1966 tab_double (tbl, n_cols - n_percentiles + j,
1967 heading_rows + row_var_start + i * PERCENTILE_ROWS,
1969 percentile_calculate (result->metrics[v].ptl[j],
1970 percentile_algorithm),
1974 if ( result->metrics[v].ptl[j]->ptile == 0.5)
1976 else if ( result->metrics[v].ptl[j]->ptile == 0.25)
1978 else if ( result->metrics[v].ptl[j]->ptile == 0.75)
1981 if ( hinge != SYSMIS)
1982 tab_double (tbl, n_cols - n_percentiles + j,
1983 heading_rows + row_var_start + 1 + i * PERCENTILE_ROWS,
1993 tab_vline (tbl, TAL_2, heading_columns, 0, n_rows - 1);
1995 tab_title (tbl, _("Percentiles"));
1998 for (i = 0 ; i < n_percentiles; ++i )
2000 tab_text_format (tbl, n_cols - n_percentiles + i, 1,
2001 TAB_CENTER | TAT_TITLE,
2003 subc_list_double_at (&percentile_list, i));
2008 tab_joint_text (tbl,
2009 n_cols - n_percentiles, 0,
2011 TAB_CENTER | TAT_TITLE,
2014 /* Vertical lines for the data only */
2018 n_cols - n_percentiles, 1,
2019 n_cols - 1, n_rows - 1);
2021 tab_hline (tbl, TAL_1, n_cols - n_percentiles, n_cols - 1, 1);
2029 factor_to_string_concise (const struct xfactor *fctr,
2030 const struct factor_result *result,
2034 if (fctr->indep_var[0])
2036 var_append_value_name (fctr->indep_var[0], &result->value[0], str);
2038 if ( fctr->indep_var[1] )
2040 ds_put_cstr (str, ",");
2042 var_append_value_name (fctr->indep_var[1], &result->value[1], str);
2044 ds_put_cstr (str, ")");
2051 factor_to_string (const struct xfactor *fctr,
2052 const struct factor_result *result,
2056 if (fctr->indep_var[0])
2058 ds_put_format (str, "(%s = ", var_get_name (fctr->indep_var[0]));
2060 var_append_value_name (fctr->indep_var[0], &result->value[0], str);
2062 if ( fctr->indep_var[1] )
2064 ds_put_cstr (str, ",");
2065 ds_put_format (str, "%s = ", var_get_name (fctr->indep_var[1]));
2067 var_append_value_name (fctr->indep_var[1], &result->value[1], str);
2069 ds_put_cstr (str, ")");