2 PSPP - a program for statistical analysis.
3 Copyright (C) 2012, 2013 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include <gsl/gsl_cdf.h>
24 #include "libpspp/assertion.h"
25 #include "libpspp/message.h"
26 #include "libpspp/pool.h"
29 #include "data/dataset.h"
30 #include "data/dictionary.h"
31 #include "data/casegrouper.h"
32 #include "data/casereader.h"
33 #include "data/casewriter.h"
34 #include "data/caseproto.h"
35 #include "data/subcase.h"
38 #include "data/format.h"
40 #include "math/interaction.h"
41 #include "math/box-whisker.h"
42 #include "math/categoricals.h"
43 #include "math/chart-geometry.h"
44 #include "math/histogram.h"
45 #include "math/moments.h"
47 #include "math/sort.h"
48 #include "math/order-stats.h"
49 #include "math/percentiles.h"
50 #include "math/tukey-hinges.h"
51 #include "math/trimmed-mean.h"
53 #include "output/charts/boxplot.h"
54 #include "output/charts/np-plot.h"
55 #include "output/charts/spreadlevel-plot.h"
56 #include "output/charts/plot-hist.h"
58 #include "language/command.h"
59 #include "language/lexer/lexer.h"
60 #include "language/lexer/value-parser.h"
61 #include "language/lexer/variable-parser.h"
63 #include "output/tab.h"
66 #define _(msgid) gettext (msgid)
67 #define N_(msgid) msgid
70 append_value_name (const struct variable *var, const union value *val, struct string *str)
72 var_append_value_name (var, val, str);
73 if ( var_is_value_missing (var, val, MV_ANY))
74 ds_put_cstr (str, _(" (missing)"));
84 /* Indices for the ex_proto member (below) */
97 /* A caseproto used to contain the data subsets under examination,
99 struct caseproto *ex_proto;
102 const struct variable **dep_vars;
105 struct interaction **iacts;
107 enum mv_class dep_excl;
108 enum mv_class fctr_excl;
110 const struct dictionary *dict;
112 struct categoricals *cats;
114 /* how many extremities to display */
123 /* The case index of the ID value (or -1) if not applicable */
129 size_t n_percentiles;
134 bool spreadlevelplot;
137 enum bp_mode boxplot_mode;
139 const struct variable *id_var;
141 const struct variable *wv;
146 /* The value of this extremity */
149 /* Either the casenumber or the value of the variable specified
150 by the /ID subcommand which corresponds to this extremity */
151 union value identity;
154 struct exploratory_stats
161 /* Most operations need a sorted reader/writer */
162 struct casewriter *sorted_writer;
163 struct casereader *sorted_reader;
165 struct extremity *minima;
166 struct extremity *maxima;
169 Minimum should alway equal mimima[0].val.
170 Likewise, maximum should alway equal maxima[0].val.
171 This redundancy exists as an optimisation effort.
172 Some statistics (eg histogram) require early calculation
178 struct trimmed_mean *trimmed_mean;
179 struct percentile *quartiles[3];
180 struct percentile **percentiles;
182 struct tukey_hinges *hinges;
184 /* The data for the NP Plots */
187 struct histogram *histogram;
189 /* The data for the box plots */
190 struct box_whisker *box_whisker;
195 /* The minimum weight */
200 /* Returns an array of (iact->n_vars) pointers to union value initialised to NULL.
201 The caller must free this array when no longer required. */
202 static const union value **
203 previous_value_alloc (const struct interaction *iact)
207 const union value **prev_val = xcalloc (iact->n_vars, sizeof (*prev_val));
209 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
210 prev_val[ivar_idx] = NULL;
215 /* Set the contents of PREV_VAL to the values of C indexed by the variables of IACT */
217 previous_value_record (const struct interaction *iact, const struct ccase *c, const union value **prev_val)
222 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
224 const struct variable *ivar = iact->vars[ivar_idx];
225 const int width = var_get_width (ivar);
226 const union value *val = case_data (c, ivar);
228 if (prev_val[ivar_idx])
229 if (! value_equal (prev_val[ivar_idx], val, width))
236 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
238 const struct variable *ivar = iact->vars[ivar_idx];
239 const union value *val = case_data (c, ivar);
241 prev_val[ivar_idx] = val;
248 show_boxplot_grouped (const struct examine *cmd, int iact_idx)
252 const struct interaction *iact = cmd->iacts[iact_idx];
253 const size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
255 for (v = 0; v < cmd->n_dep_vars; ++v)
257 double y_min = DBL_MAX;
258 double y_max = -DBL_MAX;
260 struct boxplot *boxplot;
262 ds_init_empty (&title);
264 if (iact->n_vars > 0)
267 ds_init_empty (&istr);
268 interaction_to_string (iact, &istr);
269 ds_put_format (&title, _("Boxplot of %s vs. %s"),
270 var_to_string (cmd->dep_vars[v]),
275 ds_put_format (&title, _("Boxplot of %s"), var_to_string (cmd->dep_vars[v]));
277 for (grp = 0; grp < n_cats; ++grp)
279 const struct exploratory_stats *es =
280 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
282 if ( y_min > es[v].minimum)
283 y_min = es[v].minimum;
285 if ( y_max < es[v].maximum)
286 y_max = es[v].maximum;
289 boxplot = boxplot_create (y_min, y_max, ds_cstr (&title));
293 for (grp = 0; grp < n_cats; ++grp)
298 const struct ccase *c =
299 categoricals_get_case_by_category_real (cmd->cats, iact_idx, grp);
301 const struct exploratory_stats *es =
302 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
304 ds_init_empty (&label);
305 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
308 const struct variable *ivar = iact->vars[ivar_idx];
309 const union value *val = case_data (c, ivar);
312 append_value_name (ivar, val, &l);
313 ds_ltrim (&l, ss_cstr (" "));
315 ds_put_substring (&label, l.ss);
316 if (ivar_idx < iact->n_vars - 1)
317 ds_put_cstr (&label, "; ");
322 boxplot_add_box (boxplot, es[v].box_whisker, ds_cstr (&label));
327 boxplot_submit (boxplot);
332 show_boxplot_variabled (const struct examine *cmd, int iact_idx)
335 const struct interaction *iact = cmd->iacts[iact_idx];
336 const size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
338 for (grp = 0; grp < n_cats; ++grp)
340 struct boxplot *boxplot;
342 double y_min = DBL_MAX;
343 double y_max = -DBL_MAX;
345 const struct ccase *c =
346 categoricals_get_case_by_category_real (cmd->cats, iact_idx, grp);
349 ds_init_empty (&title);
351 for (v = 0; v < cmd->n_dep_vars; ++v)
353 const struct exploratory_stats *es =
354 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
356 if ( y_min > es[v].minimum)
357 y_min = es[v].minimum;
359 if ( y_max < es[v].maximum)
360 y_max = es[v].maximum;
363 if ( iact->n_vars == 0)
364 ds_put_format (&title, _("Boxplot"));
369 ds_init_empty (&label);
370 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
372 const struct variable *ivar = iact->vars[ivar_idx];
373 const union value *val = case_data (c, ivar);
375 ds_put_cstr (&label, var_to_string (ivar));
376 ds_put_cstr (&label, " = ");
377 append_value_name (ivar, val, &label);
378 ds_put_cstr (&label, "; ");
381 ds_put_format (&title, _("Boxplot of %s"),
387 boxplot = boxplot_create (y_min, y_max, ds_cstr (&title));
391 for (v = 0; v < cmd->n_dep_vars; ++v)
393 const struct exploratory_stats *es =
394 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
396 boxplot_add_box (boxplot, es[v].box_whisker,
397 var_to_string (cmd->dep_vars[v]));
400 boxplot_submit (boxplot);
406 show_npplot (const struct examine *cmd, int iact_idx)
408 const struct interaction *iact = cmd->iacts[iact_idx];
409 const size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
413 for (v = 0; v < cmd->n_dep_vars; ++v)
416 for (grp = 0; grp < n_cats; ++grp)
418 struct chart_item *npp, *dnpp;
419 struct casereader *reader;
423 const struct ccase *c =
424 categoricals_get_case_by_category_real (cmd->cats,
427 const struct exploratory_stats *es =
428 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
431 ds_init_cstr (&label,
432 var_to_string (cmd->dep_vars[v]));
434 if ( iact->n_vars > 0)
436 ds_put_cstr (&label, " (");
437 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
439 const struct variable *ivar = iact->vars[ivar_idx];
440 const union value *val = case_data (c, ivar);
442 ds_put_cstr (&label, var_to_string (ivar));
443 ds_put_cstr (&label, " = ");
444 append_value_name (ivar, val, &label);
445 ds_put_cstr (&label, "; ");
448 ds_put_cstr (&label, ")");
452 reader = casewriter_make_reader (np->writer);
455 npp = np_plot_create (np, reader, ds_cstr (&label));
456 dnpp = dnp_plot_create (np, reader, ds_cstr (&label));
458 if (npp == NULL || dnpp == NULL)
460 msg (MW, _("Not creating NP plot because data set is empty."));
461 chart_item_unref (npp);
462 chart_item_unref (dnpp);
466 chart_item_submit (npp);
467 chart_item_submit (dnpp);
469 casereader_destroy (reader);
477 show_spreadlevel (const struct examine *cmd, int iact_idx)
479 const struct interaction *iact = cmd->iacts[iact_idx];
480 const size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
484 /* Spreadlevel when there are no levels is not useful */
485 if (iact->n_vars == 0)
488 for (v = 0; v < cmd->n_dep_vars; ++v)
491 struct chart_item *sl;
494 ds_init_cstr (&label,
495 var_to_string (cmd->dep_vars[v]));
497 if (iact->n_vars > 0)
499 ds_put_cstr (&label, " (");
500 interaction_to_string (iact, &label);
501 ds_put_cstr (&label, ")");
504 sl = spreadlevel_plot_create (ds_cstr (&label), cmd->sl_power);
506 for (grp = 0; grp < n_cats; ++grp)
508 const struct exploratory_stats *es =
509 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
511 double median = percentile_calculate (es[v].quartiles[1], cmd->pc_alg);
513 double iqr = percentile_calculate (es[v].quartiles[2], cmd->pc_alg) -
514 percentile_calculate (es[v].quartiles[0], cmd->pc_alg);
516 spreadlevel_plot_add (sl, iqr, median);
520 msg (MW, _("Not creating spreadlevel chart for %s"), ds_cstr (&label));
522 chart_item_submit (sl);
530 show_histogram (const struct examine *cmd, int iact_idx)
532 const struct interaction *iact = cmd->iacts[iact_idx];
533 const size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
537 for (v = 0; v < cmd->n_dep_vars; ++v)
540 for (grp = 0; grp < n_cats; ++grp)
544 const struct ccase *c =
545 categoricals_get_case_by_category_real (cmd->cats,
548 const struct exploratory_stats *es =
549 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
553 if (es[v].histogram == NULL)
556 ds_init_cstr (&label,
557 var_to_string (cmd->dep_vars[v]));
559 if ( iact->n_vars > 0)
561 ds_put_cstr (&label, " (");
562 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
564 const struct variable *ivar = iact->vars[ivar_idx];
565 const union value *val = case_data (c, ivar);
567 ds_put_cstr (&label, var_to_string (ivar));
568 ds_put_cstr (&label, " = ");
569 append_value_name (ivar, val, &label);
570 ds_put_cstr (&label, "; ");
573 ds_put_cstr (&label, ")");
577 moments_calculate (es[v].mom, &n, &mean, &var, NULL, NULL);
580 ( histogram_chart_create (es[v].histogram->gsl_hist,
581 ds_cstr (&label), n, mean,
591 percentiles_report (const struct examine *cmd, int iact_idx)
593 const struct interaction *iact = cmd->iacts[iact_idx];
595 const int heading_columns = 1 + iact->n_vars + 1;
596 const int heading_rows = 2;
599 const size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
601 const int rows_per_cat = 2;
602 const int rows_per_var = n_cats * rows_per_cat;
604 const int nr = heading_rows + cmd->n_dep_vars * rows_per_var;
605 const int nc = heading_columns + cmd->n_percentiles;
607 t = tab_create (nc, nr);
609 tab_title (t, _("Percentiles"));
611 tab_headers (t, heading_columns, 0, heading_rows, 0);
613 /* Internal Vertical lines */
614 tab_box (t, -1, -1, -1, TAL_1,
615 heading_columns, 0, nc - 1, nr - 1);
618 tab_box (t, TAL_2, TAL_2, -1, -1,
619 0, 0, nc - 1, nr - 1);
621 tab_hline (t, TAL_2, 0, nc - 1, heading_rows);
622 tab_vline (t, TAL_2, heading_columns, 0, nr - 1);
624 tab_joint_text (t, heading_columns, 0,
626 TAT_TITLE | TAB_CENTER,
630 tab_hline (t, TAL_1, heading_columns, nc - 1, 1);
633 for (i = 0; i < cmd->n_percentiles; ++i)
635 tab_text_format (t, heading_columns + i, 1,
636 TAT_TITLE | TAB_CENTER,
637 _("%g"), cmd->ptiles[i]);
640 for (i = 0; i < iact->n_vars; ++i)
645 var_to_string (iact->vars[i])
653 tab_vline (t, TAL_1, heading_columns - 1, heading_rows, nr - 1);
655 for (v = 0; v < cmd->n_dep_vars; ++v)
657 const union value **prev_vals = previous_value_alloc (iact);
661 tab_hline (t, TAL_1, 0, nc - 1, heading_rows + v * rows_per_var);
664 0, heading_rows + v * rows_per_var,
665 TAT_TITLE | TAB_LEFT,
666 var_to_string (cmd->dep_vars[v])
669 for (i = 0; i < n_cats; ++i)
671 const struct ccase *c =
672 categoricals_get_case_by_category_real (cmd->cats,
675 const struct exploratory_stats *ess =
676 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, i);
678 const struct exploratory_stats *es = ess + v;
680 int diff_idx = previous_value_record (iact, c, prev_vals);
685 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
687 const struct variable *ivar = iact->vars[ivar_idx];
688 const union value *val = case_data (c, ivar);
690 if (( diff_idx != -1 && diff_idx <= ivar_idx)
694 ds_init_empty (&str);
695 append_value_name (ivar, val, &str);
699 heading_rows + v * rows_per_var + i * rows_per_cat,
700 TAT_TITLE | TAB_LEFT,
708 if ( diff_idx != -1 && diff_idx < iact->n_vars)
710 tab_hline (t, TAL_1, 1 + diff_idx, nc - 1,
711 heading_rows + v * rows_per_var + i * rows_per_cat
715 tab_text (t, heading_columns - 1,
716 heading_rows + v * rows_per_var + i * rows_per_cat,
717 TAT_TITLE | TAB_LEFT,
718 gettext (ptile_alg_desc [cmd->pc_alg]));
720 tukey_hinges_calculate (es->hinges, hinges);
722 for (p = 0; p < cmd->n_percentiles; ++p)
724 tab_double (t, heading_columns + p,
725 heading_rows + v * rows_per_var + i * rows_per_cat,
727 percentile_calculate (es->percentiles[p], cmd->pc_alg),
730 if (cmd->ptiles[p] == 25.0)
732 tab_double (t, heading_columns + p,
733 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
738 else if (cmd->ptiles[p] == 50.0)
740 tab_double (t, heading_columns + p,
741 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
746 else if (cmd->ptiles[p] == 75.0)
748 tab_double (t, heading_columns + p,
749 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
757 tab_text (t, heading_columns - 1,
758 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
759 TAT_TITLE | TAB_LEFT,
760 _("Tukey's Hinges"));
771 descriptives_report (const struct examine *cmd, int iact_idx)
773 const struct interaction *iact = cmd->iacts[iact_idx];
775 const int heading_columns = 1 + iact->n_vars + 2;
776 const int heading_rows = 1;
779 size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
781 const int rows_per_cat = 13;
782 const int rows_per_var = n_cats * rows_per_cat;
784 const int nr = heading_rows + cmd->n_dep_vars * rows_per_var;
785 const int nc = 2 + heading_columns;
787 t = tab_create (nc, nr);
789 tab_title (t, _("Descriptives"));
791 tab_headers (t, heading_columns, 0, heading_rows, 0);
793 /* Internal Vertical lines */
794 tab_box (t, -1, -1, -1, TAL_1,
795 heading_columns, 0, nc - 1, nr - 1);
798 tab_box (t, TAL_2, TAL_2, -1, -1,
799 0, 0, nc - 1, nr - 1);
801 tab_hline (t, TAL_2, 0, nc - 1, heading_rows);
802 tab_vline (t, TAL_2, heading_columns, 0, nr - 1);
805 tab_text (t, heading_columns, 0, TAB_CENTER | TAT_TITLE,
808 tab_text (t, heading_columns + 1, 0, TAB_CENTER | TAT_TITLE,
811 for (i = 0; i < iact->n_vars; ++i)
816 var_to_string (iact->vars[i])
820 for (v = 0; v < cmd->n_dep_vars; ++v)
822 const union value **prev_val = previous_value_alloc (iact);
826 tab_hline (t, TAL_1, 0, nc - 1, heading_rows + v * rows_per_var);
829 0, heading_rows + v * rows_per_var,
830 TAT_TITLE | TAB_LEFT,
831 var_to_string (cmd->dep_vars[v])
834 for (i = 0; i < n_cats; ++i)
836 const struct ccase *c =
837 categoricals_get_case_by_category_real (cmd->cats,
840 const struct exploratory_stats *ess =
841 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, i);
843 const struct exploratory_stats *es = ess + v;
845 const int diff_idx = previous_value_record (iact, c, prev_val);
847 double m0, m1, m2, m3, m4;
850 moments_calculate (es->mom, &m0, &m1, &m2, &m3, &m4);
852 tval = gsl_cdf_tdist_Qinv ((1.0 - cmd->conf) / 2.0, m0 - 1.0);
854 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
856 const struct variable *ivar = iact->vars[ivar_idx];
857 const union value *val = case_data (c, ivar);
859 if (( diff_idx != -1 && diff_idx <= ivar_idx)
863 ds_init_empty (&str);
864 append_value_name (ivar, val, &str);
868 heading_rows + v * rows_per_var + i * rows_per_cat,
869 TAT_TITLE | TAB_LEFT,
877 if ( diff_idx != -1 && diff_idx < iact->n_vars)
879 tab_hline (t, TAL_1, 1 + diff_idx, nc - 1,
880 heading_rows + v * rows_per_var + i * rows_per_cat
886 heading_rows + v * rows_per_var + i * rows_per_cat,
892 1 + iact->n_vars + 2,
893 heading_rows + v * rows_per_var + i * rows_per_cat,
894 0, m1, NULL, RC_OTHER);
897 1 + iact->n_vars + 3,
898 heading_rows + v * rows_per_var + i * rows_per_cat,
899 0, calc_semean (m2, m0), NULL, RC_OTHER);
903 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
905 _("%g%% Confidence Interval for Mean"),
910 1 + iact->n_vars + 1,
911 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
917 1 + iact->n_vars + 2,
918 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
919 0, m1 - tval * calc_semean (m2, m0), NULL, RC_OTHER);
923 1 + iact->n_vars + 1,
924 heading_rows + v * rows_per_var + i * rows_per_cat + 2,
930 1 + iact->n_vars + 2,
931 heading_rows + v * rows_per_var + i * rows_per_cat + 2,
932 0, m1 + tval * calc_semean (m2, m0), NULL, RC_OTHER);
937 heading_rows + v * rows_per_var + i * rows_per_cat + 3,
943 1 + iact->n_vars + 2,
944 heading_rows + v * rows_per_var + i * rows_per_cat + 3,
946 trimmed_mean_calculate (es->trimmed_mean),
951 heading_rows + v * rows_per_var + i * rows_per_cat + 4,
957 1 + iact->n_vars + 2,
958 heading_rows + v * rows_per_var + i * rows_per_cat + 4,
960 percentile_calculate (es->quartiles[1], cmd->pc_alg),
966 heading_rows + v * rows_per_var + i * rows_per_cat + 5,
972 1 + iact->n_vars + 2,
973 heading_rows + v * rows_per_var + i * rows_per_cat + 5,
974 0, m2, NULL, RC_OTHER);
978 heading_rows + v * rows_per_var + i * rows_per_cat + 6,
984 1 + iact->n_vars + 2,
985 heading_rows + v * rows_per_var + i * rows_per_cat + 6,
986 0, sqrt (m2), NULL, RC_OTHER);
990 heading_rows + v * rows_per_var + i * rows_per_cat + 7,
996 1 + iact->n_vars + 2,
997 heading_rows + v * rows_per_var + i * rows_per_cat + 7,
1004 heading_rows + v * rows_per_var + i * rows_per_cat + 8,
1010 1 + iact->n_vars + 2,
1011 heading_rows + v * rows_per_var + i * rows_per_cat + 8,
1018 heading_rows + v * rows_per_var + i * rows_per_cat + 9,
1024 1 + iact->n_vars + 2,
1025 heading_rows + v * rows_per_var + i * rows_per_cat + 9,
1027 es->maxima[0].val - es->minima[0].val,
1032 heading_rows + v * rows_per_var + i * rows_per_cat + 10,
1034 _("Interquartile Range")
1039 1 + iact->n_vars + 2,
1040 heading_rows + v * rows_per_var + i * rows_per_cat + 10,
1042 percentile_calculate (es->quartiles[2], cmd->pc_alg) -
1043 percentile_calculate (es->quartiles[0], cmd->pc_alg),
1051 heading_rows + v * rows_per_var + i * rows_per_cat + 11,
1057 1 + iact->n_vars + 2,
1058 heading_rows + v * rows_per_var + i * rows_per_cat + 11,
1059 0, m3, NULL, RC_OTHER);
1062 1 + iact->n_vars + 3,
1063 heading_rows + v * rows_per_var + i * rows_per_cat + 11,
1064 0, calc_seskew (m0), NULL, RC_OTHER);
1068 heading_rows + v * rows_per_var + i * rows_per_cat + 12,
1074 1 + iact->n_vars + 2,
1075 heading_rows + v * rows_per_var + i * rows_per_cat + 12,
1076 0, m4, NULL, RC_OTHER);
1079 1 + iact->n_vars + 3,
1080 heading_rows + v * rows_per_var + i * rows_per_cat + 12,
1081 0, calc_sekurt (m0), NULL, RC_OTHER);
1091 extremes_report (const struct examine *cmd, int iact_idx)
1093 const struct interaction *iact = cmd->iacts[iact_idx];
1095 const int heading_columns = 1 + iact->n_vars + 2;
1096 const int heading_rows = 1;
1097 struct tab_table *t;
1099 size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
1101 const int rows_per_cat = 2 * cmd->disp_extremes;
1102 const int rows_per_var = n_cats * rows_per_cat;
1104 const int nr = heading_rows + cmd->n_dep_vars * rows_per_var;
1105 const int nc = 2 + heading_columns;
1107 t = tab_create (nc, nr);
1109 tab_title (t, _("Extreme Values"));
1111 tab_headers (t, heading_columns, 0, heading_rows, 0);
1113 /* Internal Vertical lines */
1114 tab_box (t, -1, -1, -1, TAL_1,
1115 heading_columns, 0, nc - 1, nr - 1);
1117 /* External Frame */
1118 tab_box (t, TAL_2, TAL_2, -1, -1,
1119 0, 0, nc - 1, nr - 1);
1121 tab_hline (t, TAL_2, 0, nc - 1, heading_rows);
1122 tab_vline (t, TAL_2, heading_columns, 0, nr - 1);
1126 tab_text (t, heading_columns, 0, TAB_CENTER | TAT_TITLE,
1127 var_to_string (cmd->id_var));
1129 tab_text (t, heading_columns, 0, TAB_CENTER | TAT_TITLE,
1132 tab_text (t, heading_columns + 1, 0, TAB_CENTER | TAT_TITLE,
1135 for (i = 0; i < iact->n_vars; ++i)
1140 var_to_string (iact->vars[i])
1144 for (v = 0; v < cmd->n_dep_vars; ++v)
1146 const union value **prev_val = previous_value_alloc (iact);
1150 tab_hline (t, TAL_1, 0, nc - 1, heading_rows + v * rows_per_var);
1153 0, heading_rows + v * rows_per_var,
1155 var_to_string (cmd->dep_vars[v])
1158 for (i = 0; i < n_cats; ++i)
1161 const struct ccase *c =
1162 categoricals_get_case_by_category_real (cmd->cats, iact_idx, i);
1164 const struct exploratory_stats *ess =
1165 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, i);
1167 const struct exploratory_stats *es = ess + v;
1169 int diff_idx = previous_value_record (iact, c, prev_val);
1171 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
1173 const struct variable *ivar = iact->vars[ivar_idx];
1174 const union value *val = case_data (c, ivar);
1176 if (( diff_idx != -1 && diff_idx <= ivar_idx)
1180 ds_init_empty (&str);
1181 append_value_name (ivar, val, &str);
1185 heading_rows + v * rows_per_var + i * rows_per_cat,
1186 TAT_TITLE | TAB_LEFT,
1194 if ( diff_idx != -1 && diff_idx < iact->n_vars)
1196 tab_hline (t, TAL_1, 1 + diff_idx, nc - 1,
1197 heading_rows + v * rows_per_var + i * rows_per_cat
1202 heading_columns - 2,
1203 heading_rows + v * rows_per_var + i * rows_per_cat,
1208 tab_hline (t, TAL_1, heading_columns - 2, nc - 1,
1209 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes
1213 heading_columns - 2,
1214 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes,
1218 for (e = 0 ; e < cmd->disp_extremes; ++e)
1221 heading_columns - 1,
1222 heading_rows + v * rows_per_var + i * rows_per_cat + e,
1227 /* The casenumber */
1231 heading_rows + v * rows_per_var + i * rows_per_cat + e,
1233 &es->maxima[e].identity,
1239 heading_rows + v * rows_per_var + i * rows_per_cat + e,
1241 es->maxima[e].identity.f,
1245 heading_columns + 1,
1246 heading_rows + v * rows_per_var + i * rows_per_cat + e,
1249 var_get_print_format (cmd->dep_vars[v]), RC_OTHER);
1253 heading_columns - 1,
1254 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes + e,
1259 /* The casenumber */
1263 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes + e,
1265 &es->minima[e].identity,
1271 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes + e,
1273 es->minima[e].identity.f,
1277 heading_columns + 1,
1278 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes + e,
1281 var_get_print_format (cmd->dep_vars[v]), RC_OTHER);
1292 summary_report (const struct examine *cmd, int iact_idx)
1294 const struct interaction *iact = cmd->iacts[iact_idx];
1296 const int heading_columns = 1 + iact->n_vars;
1297 const int heading_rows = 3;
1298 struct tab_table *t;
1300 const struct fmt_spec *wfmt = cmd->wv ? var_get_print_format (cmd->wv) : &F_8_0;
1302 size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
1304 const int nr = heading_rows + n_cats * cmd->n_dep_vars;
1305 const int nc = 6 + heading_columns;
1307 t = tab_create (nc, nr);
1308 tab_set_format (t, RC_WEIGHT, wfmt);
1309 tab_title (t, _("Case Processing Summary"));
1311 tab_headers (t, heading_columns, 0, heading_rows, 0);
1313 /* Internal Vertical lines */
1314 tab_box (t, -1, -1, -1, TAL_1,
1315 heading_columns, 0, nc - 1, nr - 1);
1317 /* External Frame */
1318 tab_box (t, TAL_2, TAL_2, -1, -1,
1319 0, 0, nc - 1, nr - 1);
1321 tab_hline (t, TAL_2, 0, nc - 1, heading_rows);
1322 tab_vline (t, TAL_2, heading_columns, 0, nr - 1);
1324 tab_joint_text (t, heading_columns, 0,
1325 nc - 1, 0, TAB_CENTER | TAT_TITLE, _("Cases"));
1328 heading_columns + 1, 1,
1329 TAB_CENTER | TAT_TITLE, _("Valid"));
1332 heading_columns + 2, 1,
1333 heading_columns + 3, 1,
1334 TAB_CENTER | TAT_TITLE, _("Missing"));
1337 heading_columns + 4, 1,
1338 heading_columns + 5, 1,
1339 TAB_CENTER | TAT_TITLE, _("Total"));
1341 for (i = 0; i < 3; ++i)
1343 tab_text (t, heading_columns + i * 2, 2, TAB_CENTER | TAT_TITLE,
1345 tab_text (t, heading_columns + i * 2 + 1, 2, TAB_CENTER | TAT_TITLE,
1349 for (i = 0; i < iact->n_vars; ++i)
1354 var_to_string (iact->vars[i])
1359 for (v = 0; v < cmd->n_dep_vars; ++v)
1362 const union value **prev_values = previous_value_alloc (iact);
1365 tab_hline (t, TAL_1, 0, nc - 1, heading_rows + v * n_cats);
1368 0, heading_rows + n_cats * v,
1370 var_to_string (cmd->dep_vars[v])
1374 for (i = 0; i < n_cats; ++i)
1377 const struct exploratory_stats *es;
1379 const struct ccase *c =
1380 categoricals_get_case_by_category_real (cmd->cats,
1384 int diff_idx = previous_value_record (iact, c, prev_values);
1386 if ( diff_idx != -1 && diff_idx < iact->n_vars - 1)
1387 tab_hline (t, TAL_1, 1 + diff_idx, nc - 1,
1388 heading_rows + n_cats * v + i );
1390 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
1392 const struct variable *ivar = iact->vars[ivar_idx];
1393 const union value *val = case_data (c, ivar);
1395 if (( diff_idx != -1 && diff_idx <= ivar_idx)
1399 ds_init_empty (&str);
1400 append_value_name (ivar, val, &str);
1403 1 + ivar_idx, heading_rows + n_cats * v + i,
1404 TAT_TITLE | TAB_LEFT,
1414 es = categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, i);
1417 total = es[v].missing + es[v].non_missing;
1419 heading_columns + 0,
1420 heading_rows + n_cats * v + i,
1427 heading_columns + 1,
1428 heading_rows + n_cats * v + i,
1431 100.0 * es[v].non_missing / total
1436 heading_columns + 2,
1437 heading_rows + n_cats * v + i,
1443 heading_columns + 3,
1444 heading_rows + n_cats * v + i,
1447 100.0 * es[v].missing / total
1450 heading_columns + 4,
1451 heading_rows + n_cats * v + i,
1456 /* This can only be 100% can't it? */
1458 heading_columns + 5,
1459 heading_rows + n_cats * v + i,
1462 100.0 * (es[v].missing + es[v].non_missing)/ total
1468 tab_hline (t, TAL_1, heading_columns, nc - 1, 1);
1469 tab_hline (t, TAL_1, heading_columns, nc - 1, 2);
1474 /* Attempt to parse an interaction from LEXER */
1475 static struct interaction *
1476 parse_interaction (struct lexer *lexer, struct examine *ex)
1478 const struct variable *v = NULL;
1479 struct interaction *iact = NULL;
1481 if ( lex_match_variable (lexer, ex->dict, &v))
1483 iact = interaction_create (v);
1485 while (lex_match (lexer, T_BY))
1487 if (!lex_match_variable (lexer, ex->dict, &v))
1489 interaction_destroy (iact);
1492 interaction_add_variable (iact, v);
1494 lex_match (lexer, T_COMMA);
1502 create_n (const void *aux1, void *aux2 UNUSED)
1506 const struct examine *examine = aux1;
1507 struct exploratory_stats *es = pool_calloc (examine->pool, examine->n_dep_vars, sizeof (*es));
1508 struct subcase ordering;
1509 subcase_init (&ordering, 0, 0, SC_ASCEND);
1511 for (v = 0; v < examine->n_dep_vars; v++)
1513 es[v].sorted_writer = sort_create_writer (&ordering, examine->ex_proto);
1514 es[v].sorted_reader = NULL;
1516 es[v].mom = moments_create (MOMENT_KURTOSIS);
1517 es[v].cmin = DBL_MAX;
1519 es[v].maximum = -DBL_MAX;
1520 es[v].minimum = DBL_MAX;
1523 subcase_destroy (&ordering);
1528 update_n (const void *aux1, void *aux2 UNUSED, void *user_data,
1529 const struct ccase *c, double weight)
1532 const struct examine *examine = aux1;
1533 struct exploratory_stats *es = user_data;
1535 bool this_case_is_missing = false;
1536 /* LISTWISE missing must be dealt with here */
1537 if (!examine->missing_pw)
1539 for (v = 0; v < examine->n_dep_vars; v++)
1541 const struct variable *var = examine->dep_vars[v];
1543 if (var_is_value_missing (var, case_data (c, var), examine->dep_excl))
1545 es[v].missing += weight;
1546 this_case_is_missing = true;
1551 if (this_case_is_missing)
1554 for (v = 0; v < examine->n_dep_vars; v++)
1556 struct ccase *outcase ;
1557 const struct variable *var = examine->dep_vars[v];
1558 const double x = case_data (c, var)->f;
1560 if (var_is_value_missing (var, case_data (c, var), examine->dep_excl))
1562 es[v].missing += weight;
1566 outcase = case_create (examine->ex_proto);
1568 if (x > es[v].maximum)
1571 if (x < es[v].minimum)
1574 es[v].non_missing += weight;
1576 moments_pass_one (es[v].mom, x, weight);
1578 /* Save the value and the ID to the writer */
1579 assert (examine->id_idx != -1);
1580 case_data_rw_idx (outcase, EX_VAL)->f = x;
1581 value_copy (case_data_rw_idx (outcase, EX_ID),
1582 case_data_idx (c, examine->id_idx), examine->id_width);
1584 case_data_rw_idx (outcase, EX_WT)->f = weight;
1588 if (es[v].cmin > weight)
1589 es[v].cmin = weight;
1591 casewriter_write (es[v].sorted_writer, outcase);
1596 calculate_n (const void *aux1, void *aux2 UNUSED, void *user_data)
1599 const struct examine *examine = aux1;
1600 struct exploratory_stats *es = user_data;
1602 for (v = 0; v < examine->n_dep_vars; v++)
1605 casenumber imin = 0;
1607 struct casereader *reader;
1610 if (examine->histogramplot && es[v].non_missing > 0)
1613 double bin_width = fabs (es[v].minimum - es[v].maximum)
1614 / (1 + log2 (es[v].cc))
1618 histogram_create (bin_width, es[v].minimum, es[v].maximum);
1621 es[v].sorted_reader = casewriter_make_reader (es[v].sorted_writer);
1622 es[v].sorted_writer = NULL;
1624 imax = casereader_get_case_cnt (es[v].sorted_reader);
1626 es[v].maxima = pool_calloc (examine->pool, examine->calc_extremes, sizeof (*es[v].maxima));
1627 es[v].minima = pool_calloc (examine->pool, examine->calc_extremes, sizeof (*es[v].minima));
1628 for (i = 0; i < examine->calc_extremes; ++i)
1630 value_init_pool (examine->pool, &es[v].maxima[i].identity, examine->id_width) ;
1631 value_init_pool (examine->pool, &es[v].minima[i].identity, examine->id_width) ;
1634 for (reader = casereader_clone (es[v].sorted_reader);
1635 (c = casereader_read (reader)) != NULL; case_unref (c))
1637 const double val = case_data_idx (c, EX_VAL)->f;
1638 const double wt = case_data_idx (c, EX_WT)->f;
1640 moments_pass_two (es[v].mom, val, wt);
1642 if (es[v].histogram)
1643 histogram_add (es[v].histogram, val, wt);
1645 if (imin < examine->calc_extremes)
1648 for (x = imin; x < examine->calc_extremes; ++x)
1650 struct extremity *min = &es[v].minima[x];
1652 value_copy (&min->identity, case_data_idx (c, EX_ID), examine->id_width);
1658 if (imax < examine->calc_extremes)
1662 for (x = imax; x < imax + 1; ++x)
1664 struct extremity *max;
1666 if (x >= examine->calc_extremes)
1669 max = &es[v].maxima[x];
1671 value_copy (&max->identity, case_data_idx (c, EX_ID), examine->id_width);
1675 casereader_destroy (reader);
1677 if (examine->calc_extremes > 0 && es[v].non_missing > 0)
1679 assert (es[v].minima[0].val == es[v].minimum);
1680 assert (es[v].maxima[0].val == es[v].maximum);
1684 const int n_os = 5 + examine->n_percentiles;
1685 struct order_stats **os ;
1686 es[v].percentiles = pool_calloc (examine->pool, examine->n_percentiles, sizeof (*es[v].percentiles));
1688 es[v].trimmed_mean = trimmed_mean_create (es[v].cc, 0.05);
1690 os = xcalloc (n_os, sizeof *os);
1691 os[0] = &es[v].trimmed_mean->parent;
1693 es[v].quartiles[0] = percentile_create (0.25, es[v].cc);
1694 es[v].quartiles[1] = percentile_create (0.5, es[v].cc);
1695 es[v].quartiles[2] = percentile_create (0.75, es[v].cc);
1697 os[1] = &es[v].quartiles[0]->parent;
1698 os[2] = &es[v].quartiles[1]->parent;
1699 os[3] = &es[v].quartiles[2]->parent;
1701 es[v].hinges = tukey_hinges_create (es[v].cc, es[v].cmin);
1702 os[4] = &es[v].hinges->parent;
1704 for (i = 0; i < examine->n_percentiles; ++i)
1706 es[v].percentiles[i] = percentile_create (examine->ptiles[i] / 100.00, es[v].cc);
1707 os[5 + i] = &es[v].percentiles[i]->parent;
1710 order_stats_accumulate_idx (os, n_os,
1711 casereader_clone (es[v].sorted_reader),
1717 if (examine->boxplot)
1719 struct order_stats *os;
1721 es[v].box_whisker = box_whisker_create (es[v].hinges,
1722 EX_ID, examine->id_var);
1724 os = &es[v].box_whisker->parent;
1725 order_stats_accumulate_idx (&os, 1,
1726 casereader_clone (es[v].sorted_reader),
1730 if (examine->npplot)
1732 double n, mean, var;
1733 struct order_stats *os;
1735 moments_calculate (es[v].mom, &n, &mean, &var, NULL, NULL);
1737 es[v].np = np_create (n, mean, var);
1739 os = &es[v].np->parent;
1741 order_stats_accumulate_idx (&os, 1,
1742 casereader_clone (es[v].sorted_reader),
1750 cleanup_exploratory_stats (struct examine *cmd)
1753 for (i = 0; i < cmd->n_iacts; ++i)
1756 const size_t n_cats = categoricals_n_count (cmd->cats, i);
1758 for (v = 0; v < cmd->n_dep_vars; ++v)
1761 for (grp = 0; grp < n_cats; ++grp)
1764 const struct exploratory_stats *es =
1765 categoricals_get_user_data_by_category_real (cmd->cats, i, grp);
1767 struct order_stats *os = &es[v].hinges->parent;
1768 struct statistic *stat = &os->parent;
1769 stat->destroy (stat);
1771 for (q = 0; q < 3 ; q++)
1773 os = &es[v].quartiles[q]->parent;
1775 stat->destroy (stat);
1778 for (q = 0; q < cmd->n_percentiles ; q++)
1780 os = &es[v].percentiles[q]->parent;
1782 stat->destroy (stat);
1785 os = &es[v].trimmed_mean->parent;
1787 stat->destroy (stat);
1789 os = &es[v].np->parent;
1793 stat->destroy (stat);
1796 statistic_destroy (&es[v].histogram->parent);
1797 moments_destroy (es[v].mom);
1799 casereader_destroy (es[v].sorted_reader);
1807 run_examine (struct examine *cmd, struct casereader *input)
1811 struct casereader *reader;
1813 struct payload payload;
1814 payload.create = create_n;
1815 payload.update = update_n;
1816 payload.calculate = calculate_n;
1817 payload.destroy = NULL;
1819 cmd->wv = dict_get_weight (cmd->dict);
1822 = categoricals_create (cmd->iacts, cmd->n_iacts,
1823 cmd->wv, cmd->dep_excl, cmd->fctr_excl);
1825 categoricals_set_payload (cmd->cats, &payload, cmd, NULL);
1827 if (cmd->id_var == NULL)
1829 struct ccase *c = casereader_peek (input, 0);
1831 cmd->id_idx = case_get_value_cnt (c);
1832 input = casereader_create_arithmetic_sequence (input, 1.0, 1.0);
1837 for (reader = input;
1838 (c = casereader_read (reader)) != NULL; case_unref (c))
1840 categoricals_update (cmd->cats, c);
1842 casereader_destroy (reader);
1843 categoricals_done (cmd->cats);
1845 for (i = 0; i < cmd->n_iacts; ++i)
1847 summary_report (cmd, i);
1849 const size_t n_cats = categoricals_n_count (cmd->cats, i);
1853 if (cmd->disp_extremes > 0)
1854 extremes_report (cmd, i);
1856 if (cmd->n_percentiles > 0)
1857 percentiles_report (cmd, i);
1861 switch (cmd->boxplot_mode)
1864 show_boxplot_grouped (cmd, i);
1867 show_boxplot_variabled (cmd, i);
1875 if (cmd->histogramplot)
1876 show_histogram (cmd, i);
1879 show_npplot (cmd, i);
1881 if (cmd->spreadlevelplot)
1882 show_spreadlevel (cmd, i);
1884 if (cmd->descriptives)
1885 descriptives_report (cmd, i);
1888 cleanup_exploratory_stats (cmd);
1889 categoricals_destroy (cmd->cats);
1894 cmd_examine (struct lexer *lexer, struct dataset *ds)
1897 bool nototals_seen = false;
1898 bool totals_seen = false;
1900 struct interaction **iacts_mem = NULL;
1901 struct examine examine;
1902 bool percentiles_seen = false;
1904 examine.missing_pw = false;
1905 examine.disp_extremes = 0;
1906 examine.calc_extremes = 0;
1907 examine.descriptives = false;
1908 examine.conf = 0.95;
1909 examine.pc_alg = PC_HAVERAGE;
1910 examine.ptiles = NULL;
1911 examine.n_percentiles = 0;
1912 examine.id_idx = -1;
1913 examine.id_width = 0;
1914 examine.id_var = NULL;
1915 examine.boxplot_mode = BP_GROUPS;
1917 examine.ex_proto = caseproto_create ();
1919 examine.pool = pool_create ();
1921 /* Allocate space for the first interaction.
1922 This is interaction is an empty one (for the totals).
1923 If no totals are requested, we will simply ignore this
1926 examine.n_iacts = 1;
1927 examine.iacts = iacts_mem = pool_zalloc (examine.pool, sizeof (struct interaction *));
1928 examine.iacts[0] = interaction_create (NULL);
1930 examine.dep_excl = MV_ANY;
1931 examine.fctr_excl = MV_ANY;
1932 examine.histogramplot = false;
1933 examine.npplot = false;
1934 examine.boxplot = false;
1935 examine.spreadlevelplot = false;
1936 examine.sl_power = 0;
1938 examine.dict = dataset_dict (ds);
1940 /* Accept an optional, completely pointless "/VARIABLES=" */
1941 lex_match (lexer, T_SLASH);
1942 if (lex_match_id (lexer, "VARIABLES"))
1944 if (! lex_force_match (lexer, T_EQUALS) )
1948 if (!parse_variables_const (lexer, examine.dict,
1949 &examine.dep_vars, &examine.n_dep_vars,
1950 PV_NO_DUPLICATE | PV_NUMERIC))
1953 if (lex_match (lexer, T_BY))
1955 struct interaction *iact = NULL;
1958 iact = parse_interaction (lexer, &examine);
1963 pool_nrealloc (examine.pool, iacts_mem,
1965 sizeof (*iacts_mem));
1967 iacts_mem[examine.n_iacts - 1] = iact;
1974 while (lex_token (lexer) != T_ENDCMD)
1976 lex_match (lexer, T_SLASH);
1978 if (lex_match_id (lexer, "STATISTICS"))
1980 lex_match (lexer, T_EQUALS);
1982 while (lex_token (lexer) != T_ENDCMD
1983 && lex_token (lexer) != T_SLASH)
1985 if (lex_match_id (lexer, "DESCRIPTIVES"))
1987 examine.descriptives = true;
1989 else if (lex_match_id (lexer, "EXTREME"))
1992 if (lex_match (lexer, T_LPAREN))
1994 extr = lex_integer (lexer);
1998 msg (MW, _("%s may not be negative. Using default value (%g)."), "EXTREME", 5.0);
2003 if (! lex_force_match (lexer, T_RPAREN))
2006 examine.disp_extremes = extr;
2008 else if (lex_match_id (lexer, "NONE"))
2011 else if (lex_match (lexer, T_ALL))
2013 if (examine.disp_extremes == 0)
2014 examine.disp_extremes = 5;
2018 lex_error (lexer, NULL);
2023 else if (lex_match_id (lexer, "PERCENTILES"))
2025 percentiles_seen = true;
2026 if (lex_match (lexer, T_LPAREN))
2028 while (lex_is_number (lexer))
2030 double p = lex_number (lexer);
2032 if ( p <= 0 || p >= 100.0)
2035 _("Percentiles must lie in the range (0, 100)"));
2039 examine.n_percentiles++;
2041 xrealloc (examine.ptiles,
2042 sizeof (*examine.ptiles) *
2043 examine.n_percentiles);
2045 examine.ptiles[examine.n_percentiles - 1] = p;
2048 lex_match (lexer, T_COMMA);
2050 if (!lex_force_match (lexer, T_RPAREN))
2054 lex_match (lexer, T_EQUALS);
2056 while (lex_token (lexer) != T_ENDCMD
2057 && lex_token (lexer) != T_SLASH)
2059 if (lex_match_id (lexer, "HAVERAGE"))
2061 examine.pc_alg = PC_HAVERAGE;
2063 else if (lex_match_id (lexer, "WAVERAGE"))
2065 examine.pc_alg = PC_WAVERAGE;
2067 else if (lex_match_id (lexer, "ROUND"))
2069 examine.pc_alg = PC_ROUND;
2071 else if (lex_match_id (lexer, "EMPIRICAL"))
2073 examine.pc_alg = PC_EMPIRICAL;
2075 else if (lex_match_id (lexer, "AEMPIRICAL"))
2077 examine.pc_alg = PC_AEMPIRICAL;
2079 else if (lex_match_id (lexer, "NONE"))
2081 examine.pc_alg = PC_NONE;
2085 lex_error (lexer, NULL);
2090 else if (lex_match_id (lexer, "TOTAL"))
2094 else if (lex_match_id (lexer, "NOTOTAL"))
2096 nototals_seen = true;
2098 else if (lex_match_id (lexer, "MISSING"))
2100 lex_match (lexer, T_EQUALS);
2102 while (lex_token (lexer) != T_ENDCMD
2103 && lex_token (lexer) != T_SLASH)
2105 if (lex_match_id (lexer, "LISTWISE"))
2107 examine.missing_pw = false;
2109 else if (lex_match_id (lexer, "PAIRWISE"))
2111 examine.missing_pw = true;
2113 else if (lex_match_id (lexer, "EXCLUDE"))
2115 examine.dep_excl = MV_ANY;
2117 else if (lex_match_id (lexer, "INCLUDE"))
2119 examine.dep_excl = MV_SYSTEM;
2121 else if (lex_match_id (lexer, "REPORT"))
2123 examine.fctr_excl = MV_NEVER;
2125 else if (lex_match_id (lexer, "NOREPORT"))
2127 examine.fctr_excl = MV_ANY;
2131 lex_error (lexer, NULL);
2136 else if (lex_match_id (lexer, "COMPARE"))
2138 lex_match (lexer, T_EQUALS);
2139 if (lex_match_id (lexer, "VARIABLES"))
2141 examine.boxplot_mode = BP_VARIABLES;
2143 else if (lex_match_id (lexer, "GROUPS"))
2145 examine.boxplot_mode = BP_GROUPS;
2149 lex_error (lexer, NULL);
2153 else if (lex_match_id (lexer, "PLOT"))
2155 lex_match (lexer, T_EQUALS);
2157 while (lex_token (lexer) != T_ENDCMD
2158 && lex_token (lexer) != T_SLASH)
2160 if (lex_match_id (lexer, "BOXPLOT"))
2162 examine.boxplot = true;
2164 else if (lex_match_id (lexer, "NPPLOT"))
2166 examine.npplot = true;
2168 else if (lex_match_id (lexer, "HISTOGRAM"))
2170 examine.histogramplot = true;
2172 else if (lex_match_id (lexer, "SPREADLEVEL"))
2174 examine.spreadlevelplot = true;
2175 examine.sl_power = 0;
2176 if (lex_match (lexer, T_LPAREN) && lex_force_int (lexer))
2178 examine.sl_power = lex_integer (lexer);
2181 if (! lex_force_match (lexer, T_RPAREN))
2185 else if (lex_match_id (lexer, "NONE"))
2187 examine.histogramplot = false;
2188 examine.npplot = false;
2189 examine.boxplot = false;
2191 else if (lex_match (lexer, T_ALL))
2193 examine.histogramplot = true;
2194 examine.npplot = true;
2195 examine.boxplot = true;
2199 lex_error (lexer, NULL);
2202 lex_match (lexer, T_COMMA);
2205 else if (lex_match_id (lexer, "CINTERVAL"))
2207 if ( !lex_force_num (lexer))
2210 examine.conf = lex_number (lexer);
2213 else if (lex_match_id (lexer, "ID"))
2215 lex_match (lexer, T_EQUALS);
2217 examine.id_var = parse_variable_const (lexer, examine.dict);
2221 lex_error (lexer, NULL);
2227 if ( totals_seen && nototals_seen)
2229 msg (SE, _("%s and %s are mutually exclusive"),"TOTAL","NOTOTAL");
2233 /* If totals have been requested or if there are no factors
2234 in this analysis, then the totals need to be included. */
2235 if ( !nototals_seen || examine.n_iacts == 1)
2237 examine.iacts = &iacts_mem[0];
2242 examine.iacts = &iacts_mem[1];
2243 interaction_destroy (iacts_mem[0]);
2247 if ( examine.id_var )
2249 examine.id_idx = var_get_case_index (examine.id_var);
2250 examine.id_width = var_get_width (examine.id_var);
2253 examine.ex_proto = caseproto_add_width (examine.ex_proto, 0); /* value */
2254 examine.ex_proto = caseproto_add_width (examine.ex_proto, examine.id_width); /* id */
2255 examine.ex_proto = caseproto_add_width (examine.ex_proto, 0); /* weight */
2258 if (examine.disp_extremes > 0)
2260 examine.calc_extremes = examine.disp_extremes;
2263 if (examine.descriptives && examine.calc_extremes == 0)
2265 /* Descriptives always displays the max and min */
2266 examine.calc_extremes = 1;
2269 if (percentiles_seen && examine.n_percentiles == 0)
2271 examine.n_percentiles = 7;
2272 examine.ptiles = xcalloc (examine.n_percentiles,
2273 sizeof (*examine.ptiles));
2275 examine.ptiles[0] = 5;
2276 examine.ptiles[1] = 10;
2277 examine.ptiles[2] = 25;
2278 examine.ptiles[3] = 50;
2279 examine.ptiles[4] = 75;
2280 examine.ptiles[5] = 90;
2281 examine.ptiles[6] = 95;
2284 assert (examine.calc_extremes >= examine.disp_extremes);
2286 struct casegrouper *grouper;
2287 struct casereader *group;
2290 grouper = casegrouper_create_splits (proc_open (ds), examine.dict);
2291 while (casegrouper_get_next_group (grouper, &group))
2292 run_examine (&examine, group);
2293 ok = casegrouper_destroy (grouper);
2294 ok = proc_commit (ds) && ok;
2297 caseproto_unref (examine.ex_proto);
2299 for (i = 0; i < examine.n_iacts; ++i)
2300 interaction_destroy (examine.iacts[i]);
2301 free (examine.ptiles);
2302 free (examine.dep_vars);
2303 pool_destroy (examine.pool);
2308 caseproto_unref (examine.ex_proto);
2309 examine.iacts = iacts_mem;
2310 for (i = 0; i < examine.n_iacts; ++i)
2311 interaction_destroy (examine.iacts[i]);
2312 free (examine.dep_vars);
2313 free (examine.ptiles);
2314 pool_destroy (examine.pool);