2 PSPP - a program for statistical analysis.
3 Copyright (C) 2012 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/plot-hist.h"
57 #include "language/command.h"
58 #include "language/lexer/lexer.h"
59 #include "language/lexer/value-parser.h"
60 #include "language/lexer/variable-parser.h"
62 #include "output/tab.h"
65 #define _(msgid) gettext (msgid)
66 #define N_(msgid) msgid
75 /* Indices for the ex_proto member (below) */
88 /* A caseproto used to contain the data subsets under examination,
90 struct caseproto *ex_proto;
93 const struct variable **dep_vars;
96 struct interaction **iacts;
98 enum mv_class exclude;
100 const struct dictionary *dict;
102 struct categoricals *cats;
104 /* how many extremities to display */
113 /* The case index of the ID value (or -1) if not applicable */
119 size_t n_percentiles;
125 enum bp_mode boxplot_mode;
127 const struct variable *id_var;
129 const struct variable *wv;
134 /* The value of this extremity */
137 /* Either the casenumber or the value of the variable specified
138 by the /ID subcommand which corresponds to this extremity */
139 union value identity;
142 struct exploratory_stats
149 /* Most operations need a sorted reader/writer */
150 struct casewriter *sorted_writer;
151 struct casereader *sorted_reader;
153 struct extremity *minima;
154 struct extremity *maxima;
157 Minimum should alway equal mimima[0].val.
158 Likewise, maximum should alway equal maxima[0].val.
159 This redundancy exists as an optimisation effort.
160 Some statistics (eg histogram) require early calculation
166 struct trimmed_mean *trimmed_mean;
167 struct percentile *quartiles[3];
168 struct percentile **percentiles;
170 struct tukey_hinges *hinges;
172 /* The data for the NP Plots */
175 struct histogram *histogram;
177 /* The data for the box plots */
178 struct box_whisker *box_whisker;
183 /* The minimum weight */
188 /* Returns an array of (iact->n_vars) pointers to union value initialised to NULL.
189 The caller must free this array when no longer required. */
190 static const union value **
191 previous_value_alloc (const struct interaction *iact)
195 const union value **prev_val = xcalloc (iact->n_vars, sizeof (*prev_val));
197 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
198 prev_val[ivar_idx] = NULL;
203 /* Set the contents of PREV_VAL to the values of C indexed by the variables of IACT */
205 previous_value_record (const struct interaction *iact, const struct ccase *c, const union value **prev_val)
210 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
212 const struct variable *ivar = iact->vars[ivar_idx];
213 const int width = var_get_width (ivar);
214 const union value *val = case_data (c, ivar);
216 if (prev_val[ivar_idx])
217 if (! value_equal (prev_val[ivar_idx], val, width))
224 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
226 const struct variable *ivar = iact->vars[ivar_idx];
227 const union value *val = case_data (c, ivar);
229 prev_val[ivar_idx] = val;
236 show_boxplot_grouped (const struct examine *cmd, int iact_idx)
240 const struct interaction *iact = cmd->iacts[iact_idx];
241 const size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
243 for (v = 0; v < cmd->n_dep_vars; ++v)
245 double y_min = DBL_MAX;
246 double y_max = -DBL_MAX;
248 struct boxplot *boxplot;
250 ds_init_empty (&title);
252 if (iact->n_vars > 0)
255 ds_init_empty (&istr);
256 interaction_to_string (iact, &istr);
257 ds_put_format (&title, _("Boxplot of %s vs. %s"),
258 var_to_string (cmd->dep_vars[v]),
263 ds_put_format (&title, _("Boxplot of %s"), var_to_string (cmd->dep_vars[v]));
265 for (grp = 0; grp < n_cats; ++grp)
267 const struct exploratory_stats *es =
268 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
270 if ( y_min > es[v].minimum)
271 y_min = es[v].minimum;
273 if ( y_max < es[v].maximum)
274 y_max = es[v].maximum;
277 boxplot = boxplot_create (y_min, y_max, ds_cstr (&title));
281 for (grp = 0; grp < n_cats; ++grp)
286 const struct ccase *c =
287 categoricals_get_case_by_category_real (cmd->cats, iact_idx, grp);
289 const struct exploratory_stats *es =
290 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
292 ds_init_empty (&label);
293 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
295 const struct variable *ivar = iact->vars[ivar_idx];
296 const union value *val = case_data (c, ivar);
298 ds_put_cstr (&label, var_to_string (ivar));
299 ds_put_cstr (&label, " = ");
300 var_append_value_name (ivar, val, &label);
301 ds_put_cstr (&label, "; ");
304 boxplot_add_box (boxplot, es[v].box_whisker, ds_cstr (&label));
309 boxplot_submit (boxplot);
314 show_boxplot_variabled (const struct examine *cmd, int iact_idx)
317 const struct interaction *iact = cmd->iacts[iact_idx];
318 const size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
320 for (grp = 0; grp < n_cats; ++grp)
322 struct boxplot *boxplot;
324 double y_min = DBL_MAX;
325 double y_max = -DBL_MAX;
327 const struct ccase *c =
328 categoricals_get_case_by_category_real (cmd->cats, iact_idx, grp);
331 ds_init_empty (&title);
333 for (v = 0; v < cmd->n_dep_vars; ++v)
335 const struct exploratory_stats *es =
336 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
338 if ( y_min > es[v].minimum)
339 y_min = es[v].minimum;
341 if ( y_max < es[v].maximum)
342 y_max = es[v].maximum;
345 if ( iact->n_vars == 0)
346 ds_put_format (&title, _("Boxplot"));
351 ds_init_empty (&label);
352 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
354 const struct variable *ivar = iact->vars[ivar_idx];
355 const union value *val = case_data (c, ivar);
357 ds_put_cstr (&label, var_to_string (ivar));
358 ds_put_cstr (&label, " = ");
359 var_append_value_name (ivar, val, &label);
360 ds_put_cstr (&label, "; ");
363 ds_put_format (&title, _("Boxplot of %s"),
369 boxplot = boxplot_create (y_min, y_max, ds_cstr (&title));
373 for (v = 0; v < cmd->n_dep_vars; ++v)
375 const struct exploratory_stats *es =
376 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
378 boxplot_add_box (boxplot, es[v].box_whisker,
379 var_to_string (cmd->dep_vars[v]));
382 boxplot_submit (boxplot);
388 show_npplot (const struct examine *cmd, int iact_idx)
390 const struct interaction *iact = cmd->iacts[iact_idx];
391 const size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
395 for (v = 0; v < cmd->n_dep_vars; ++v)
398 for (grp = 0; grp < n_cats; ++grp)
400 struct chart_item *npp, *dnpp;
401 struct casereader *reader;
405 const struct ccase *c =
406 categoricals_get_case_by_category_real (cmd->cats,
409 const struct exploratory_stats *es =
410 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
413 ds_init_cstr (&label,
414 var_to_string (cmd->dep_vars[v]));
416 if ( iact->n_vars > 0)
418 ds_put_cstr (&label, " (");
419 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
421 const struct variable *ivar = iact->vars[ivar_idx];
422 const union value *val = case_data (c, ivar);
424 ds_put_cstr (&label, var_to_string (ivar));
425 ds_put_cstr (&label, " = ");
426 var_append_value_name (ivar, val, &label);
427 ds_put_cstr (&label, "; ");
430 ds_put_cstr (&label, ")");
434 reader = casewriter_make_reader (np->writer);
437 npp = np_plot_create (np, reader, ds_cstr (&label));
438 dnpp = dnp_plot_create (np, reader, ds_cstr (&label));
440 if (npp == NULL || dnpp == NULL)
442 msg (MW, _("Not creating NP plot because data set is empty."));
443 chart_item_unref (npp);
444 chart_item_unref (dnpp);
448 chart_item_submit (npp);
449 chart_item_submit (dnpp);
451 casereader_destroy (reader);
460 show_histogram (const struct examine *cmd, int iact_idx)
462 const struct interaction *iact = cmd->iacts[iact_idx];
463 const size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
467 for (v = 0; v < cmd->n_dep_vars; ++v)
470 for (grp = 0; grp < n_cats; ++grp)
474 const struct ccase *c =
475 categoricals_get_case_by_category_real (cmd->cats,
478 const struct exploratory_stats *es =
479 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, grp);
482 ds_init_cstr (&label,
483 var_to_string (cmd->dep_vars[v]));
485 if ( iact->n_vars > 0)
487 ds_put_cstr (&label, " (");
488 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
490 const struct variable *ivar = iact->vars[ivar_idx];
491 const union value *val = case_data (c, ivar);
493 ds_put_cstr (&label, var_to_string (ivar));
494 ds_put_cstr (&label, " = ");
495 var_append_value_name (ivar, val, &label);
496 ds_put_cstr (&label, "; ");
499 ds_put_cstr (&label, ")");
503 moments_calculate (es[v].mom, &n, &mean, &var, NULL, NULL);
506 ( histogram_chart_create (es[v].histogram->gsl_hist,
507 ds_cstr (&label), n, mean,
517 percentiles_report (const struct examine *cmd, int iact_idx)
519 const struct interaction *iact = cmd->iacts[iact_idx];
521 const int heading_columns = 1 + iact->n_vars + 1;
522 const int heading_rows = 2;
525 const size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
527 const int rows_per_cat = 2;
528 const int rows_per_var = n_cats * rows_per_cat;
530 const int nr = heading_rows + cmd->n_dep_vars * rows_per_var;
531 const int nc = heading_columns + cmd->n_percentiles;
533 t = tab_create (nc, nr);
534 tab_title (t, _("Percentiles"));
536 tab_headers (t, heading_columns, 0, heading_rows, 0);
538 /* Internal Vertical lines */
539 tab_box (t, -1, -1, -1, TAL_1,
540 heading_columns, 0, nc - 1, nr - 1);
543 tab_box (t, TAL_2, TAL_2, -1, -1,
544 0, 0, nc - 1, nr - 1);
546 tab_hline (t, TAL_2, 0, nc - 1, heading_rows);
547 tab_vline (t, TAL_2, heading_columns, 0, nr - 1);
549 tab_joint_text (t, heading_columns, 0,
551 TAT_TITLE | TAB_CENTER,
555 tab_hline (t, TAL_1, heading_columns, nc - 1, 1);
558 for (i = 0; i < cmd->n_percentiles; ++i)
560 tab_text_format (t, heading_columns + i, 1,
561 TAT_TITLE | TAB_CENTER,
562 _("%g"), cmd->ptiles[i]);
565 for (i = 0; i < iact->n_vars; ++i)
570 var_to_string (iact->vars[i])
578 tab_vline (t, TAL_1, heading_columns - 1, heading_rows, nr - 1);
580 for (v = 0; v < cmd->n_dep_vars; ++v)
582 const union value **prev_vals = previous_value_alloc (iact);
586 tab_hline (t, TAL_1, 0, nc - 1, heading_rows + v * rows_per_var);
589 0, heading_rows + v * rows_per_var,
590 TAT_TITLE | TAB_LEFT,
591 var_to_string (cmd->dep_vars[v])
594 for (i = 0; i < n_cats; ++i)
596 const struct ccase *c =
597 categoricals_get_case_by_category_real (cmd->cats,
600 const struct exploratory_stats *ess =
601 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, i);
603 const struct exploratory_stats *es = ess + v;
605 int diff_idx = previous_value_record (iact, c, prev_vals);
610 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
612 const struct variable *ivar = iact->vars[ivar_idx];
613 const union value *val = case_data (c, ivar);
615 if (( diff_idx != -1 && diff_idx <= ivar_idx)
619 ds_init_empty (&str);
620 var_append_value_name (ivar, val, &str);
624 heading_rows + v * rows_per_var + i * rows_per_cat,
625 TAT_TITLE | TAB_LEFT,
633 if ( diff_idx != -1 && diff_idx < iact->n_vars)
635 tab_hline (t, TAL_1, 1 + diff_idx, nc - 1,
636 heading_rows + v * rows_per_var + i * rows_per_cat
640 tab_text (t, heading_columns - 1,
641 heading_rows + v * rows_per_var + i * rows_per_cat,
642 TAT_TITLE | TAB_LEFT,
643 gettext (ptile_alg_desc [cmd->pc_alg]));
645 tukey_hinges_calculate (es->hinges, hinges);
647 for (p = 0; p < cmd->n_percentiles; ++p)
649 tab_double (t, heading_columns + p,
650 heading_rows + v * rows_per_var + i * rows_per_cat,
652 percentile_calculate (es->percentiles[p], cmd->pc_alg),
655 if (cmd->ptiles[p] == 25.0)
657 tab_double (t, heading_columns + p,
658 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
663 else if (cmd->ptiles[p] == 50.0)
665 tab_double (t, heading_columns + p,
666 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
671 else if (cmd->ptiles[p] == 75.0)
673 tab_double (t, heading_columns + p,
674 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
682 tab_text (t, heading_columns - 1,
683 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
684 TAT_TITLE | TAB_LEFT,
685 _("Tukey's Hinges"));
696 descriptives_report (const struct examine *cmd, int iact_idx)
698 const struct interaction *iact = cmd->iacts[iact_idx];
700 const int heading_columns = 1 + iact->n_vars + 2;
701 const int heading_rows = 1;
704 size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
706 const int rows_per_cat = 13;
707 const int rows_per_var = n_cats * rows_per_cat;
709 const int nr = heading_rows + cmd->n_dep_vars * rows_per_var;
710 const int nc = 2 + heading_columns;
712 t = tab_create (nc, nr);
713 tab_title (t, _("Descriptives"));
715 tab_headers (t, heading_columns, 0, heading_rows, 0);
717 /* Internal Vertical lines */
718 tab_box (t, -1, -1, -1, TAL_1,
719 heading_columns, 0, nc - 1, nr - 1);
722 tab_box (t, TAL_2, TAL_2, -1, -1,
723 0, 0, nc - 1, nr - 1);
725 tab_hline (t, TAL_2, 0, nc - 1, heading_rows);
726 tab_vline (t, TAL_2, heading_columns, 0, nr - 1);
729 tab_text (t, heading_columns, 0, TAB_CENTER | TAT_TITLE,
732 tab_text (t, heading_columns + 1, 0, TAB_CENTER | TAT_TITLE,
735 for (i = 0; i < iact->n_vars; ++i)
740 var_to_string (iact->vars[i])
744 for (v = 0; v < cmd->n_dep_vars; ++v)
746 const union value **prev_val = previous_value_alloc (iact);
750 tab_hline (t, TAL_1, 0, nc - 1, heading_rows + v * rows_per_var);
753 0, heading_rows + v * rows_per_var,
754 TAT_TITLE | TAB_LEFT,
755 var_to_string (cmd->dep_vars[v])
758 for (i = 0; i < n_cats; ++i)
760 const struct ccase *c =
761 categoricals_get_case_by_category_real (cmd->cats,
764 const struct exploratory_stats *ess =
765 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, i);
767 const struct exploratory_stats *es = ess + v;
769 const int diff_idx = previous_value_record (iact, c, prev_val);
771 double m0, m1, m2, m3, m4;
774 moments_calculate (es->mom, &m0, &m1, &m2, &m3, &m4);
776 tval = gsl_cdf_tdist_Qinv ((1.0 - cmd->conf) / 2.0, m0 - 1.0);
778 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
780 const struct variable *ivar = iact->vars[ivar_idx];
781 const union value *val = case_data (c, ivar);
783 if (( diff_idx != -1 && diff_idx <= ivar_idx)
787 ds_init_empty (&str);
788 var_append_value_name (ivar, val, &str);
792 heading_rows + v * rows_per_var + i * rows_per_cat,
793 TAT_TITLE | TAB_LEFT,
801 if ( diff_idx != -1 && diff_idx < iact->n_vars)
803 tab_hline (t, TAL_1, 1 + diff_idx, nc - 1,
804 heading_rows + v * rows_per_var + i * rows_per_cat
810 heading_rows + v * rows_per_var + i * rows_per_cat,
816 1 + iact->n_vars + 2,
817 heading_rows + v * rows_per_var + i * rows_per_cat,
821 1 + iact->n_vars + 3,
822 heading_rows + v * rows_per_var + i * rows_per_cat,
823 0, calc_semean (m2, m0), 0);
827 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
829 _("%g%% Confidence Interval for Mean"),
834 1 + iact->n_vars + 1,
835 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
841 1 + iact->n_vars + 2,
842 heading_rows + v * rows_per_var + i * rows_per_cat + 1,
843 0, m1 - tval * calc_semean (m2, m0), 0);
847 1 + iact->n_vars + 1,
848 heading_rows + v * rows_per_var + i * rows_per_cat + 2,
854 1 + iact->n_vars + 2,
855 heading_rows + v * rows_per_var + i * rows_per_cat + 2,
856 0, m1 + tval * calc_semean (m2, m0), 0);
861 heading_rows + v * rows_per_var + i * rows_per_cat + 3,
867 1 + iact->n_vars + 2,
868 heading_rows + v * rows_per_var + i * rows_per_cat + 3,
870 trimmed_mean_calculate (es->trimmed_mean),
875 heading_rows + v * rows_per_var + i * rows_per_cat + 4,
881 1 + iact->n_vars + 2,
882 heading_rows + v * rows_per_var + i * rows_per_cat + 4,
884 percentile_calculate (es->quartiles[1], cmd->pc_alg),
890 heading_rows + v * rows_per_var + i * rows_per_cat + 5,
896 1 + iact->n_vars + 2,
897 heading_rows + v * rows_per_var + i * rows_per_cat + 5,
902 heading_rows + v * rows_per_var + i * rows_per_cat + 6,
908 1 + iact->n_vars + 2,
909 heading_rows + v * rows_per_var + i * rows_per_cat + 6,
914 heading_rows + v * rows_per_var + i * rows_per_cat + 7,
920 1 + iact->n_vars + 2,
921 heading_rows + v * rows_per_var + i * rows_per_cat + 7,
928 heading_rows + v * rows_per_var + i * rows_per_cat + 8,
934 1 + iact->n_vars + 2,
935 heading_rows + v * rows_per_var + i * rows_per_cat + 8,
942 heading_rows + v * rows_per_var + i * rows_per_cat + 9,
948 1 + iact->n_vars + 2,
949 heading_rows + v * rows_per_var + i * rows_per_cat + 9,
951 es->maxima[0].val - es->minima[0].val,
956 heading_rows + v * rows_per_var + i * rows_per_cat + 10,
958 _("Interquartile Range")
963 1 + iact->n_vars + 2,
964 heading_rows + v * rows_per_var + i * rows_per_cat + 10,
966 percentile_calculate (es->quartiles[2], cmd->pc_alg) -
967 percentile_calculate (es->quartiles[0], cmd->pc_alg),
975 heading_rows + v * rows_per_var + i * rows_per_cat + 11,
981 1 + iact->n_vars + 2,
982 heading_rows + v * rows_per_var + i * rows_per_cat + 11,
986 1 + iact->n_vars + 3,
987 heading_rows + v * rows_per_var + i * rows_per_cat + 11,
988 0, calc_seskew (m0), 0);
992 heading_rows + v * rows_per_var + i * rows_per_cat + 12,
998 1 + iact->n_vars + 2,
999 heading_rows + v * rows_per_var + i * rows_per_cat + 12,
1003 1 + iact->n_vars + 3,
1004 heading_rows + v * rows_per_var + i * rows_per_cat + 12,
1005 0, calc_sekurt (m0), 0);
1015 extremes_report (const struct examine *cmd, int iact_idx)
1017 const struct interaction *iact = cmd->iacts[iact_idx];
1019 const int heading_columns = 1 + iact->n_vars + 2;
1020 const int heading_rows = 1;
1021 struct tab_table *t;
1023 size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
1025 const int rows_per_cat = 2 * cmd->disp_extremes;
1026 const int rows_per_var = n_cats * rows_per_cat;
1028 const int nr = heading_rows + cmd->n_dep_vars * rows_per_var;
1029 const int nc = 2 + heading_columns;
1031 t = tab_create (nc, nr);
1032 tab_title (t, _("Extreme Values"));
1034 tab_headers (t, heading_columns, 0, heading_rows, 0);
1036 /* Internal Vertical lines */
1037 tab_box (t, -1, -1, -1, TAL_1,
1038 heading_columns, 0, nc - 1, nr - 1);
1040 /* External Frame */
1041 tab_box (t, TAL_2, TAL_2, -1, -1,
1042 0, 0, nc - 1, nr - 1);
1044 tab_hline (t, TAL_2, 0, nc - 1, heading_rows);
1045 tab_vline (t, TAL_2, heading_columns, 0, nr - 1);
1049 tab_text (t, heading_columns, 0, TAB_CENTER | TAT_TITLE,
1050 var_to_string (cmd->id_var));
1052 tab_text (t, heading_columns, 0, TAB_CENTER | TAT_TITLE,
1055 tab_text (t, heading_columns + 1, 0, TAB_CENTER | TAT_TITLE,
1058 for (i = 0; i < iact->n_vars; ++i)
1063 var_to_string (iact->vars[i])
1067 for (v = 0; v < cmd->n_dep_vars; ++v)
1069 const union value **prev_val = previous_value_alloc (iact);
1073 tab_hline (t, TAL_1, 0, nc - 1, heading_rows + v * rows_per_var);
1076 0, heading_rows + v * rows_per_var,
1078 var_to_string (cmd->dep_vars[v])
1081 for (i = 0; i < n_cats; ++i)
1084 const struct ccase *c =
1085 categoricals_get_case_by_category_real (cmd->cats, iact_idx, i);
1087 const struct exploratory_stats *ess =
1088 categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, i);
1090 const struct exploratory_stats *es = ess + v;
1092 int diff_idx = previous_value_record (iact, c, prev_val);
1094 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
1096 const struct variable *ivar = iact->vars[ivar_idx];
1097 const union value *val = case_data (c, ivar);
1099 if (( diff_idx != -1 && diff_idx <= ivar_idx)
1103 ds_init_empty (&str);
1104 var_append_value_name (ivar, val, &str);
1108 heading_rows + v * rows_per_var + i * rows_per_cat,
1109 TAT_TITLE | TAB_LEFT,
1117 if ( diff_idx != -1 && diff_idx < iact->n_vars)
1119 tab_hline (t, TAL_1, 1 + diff_idx, nc - 1,
1120 heading_rows + v * rows_per_var + i * rows_per_cat
1125 heading_columns - 2,
1126 heading_rows + v * rows_per_var + i * rows_per_cat,
1131 tab_hline (t, TAL_1, heading_columns - 2, nc - 1,
1132 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes
1136 heading_columns - 2,
1137 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes,
1141 for (e = 0 ; e < cmd->disp_extremes; ++e)
1144 heading_columns - 1,
1145 heading_rows + v * rows_per_var + i * rows_per_cat + e,
1150 /* The casenumber */
1154 heading_rows + v * rows_per_var + i * rows_per_cat + e,
1156 &es->maxima[e].identity,
1162 heading_rows + v * rows_per_var + i * rows_per_cat + e,
1164 es->maxima[e].identity.f,
1168 heading_columns + 1,
1169 heading_rows + v * rows_per_var + i * rows_per_cat + e,
1177 heading_columns - 1,
1178 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes + e,
1183 /* The casenumber */
1187 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes + e,
1189 &es->minima[e].identity,
1195 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes + e,
1197 es->minima[e].identity.f,
1201 heading_columns + 1,
1202 heading_rows + v * rows_per_var + i * rows_per_cat + cmd->disp_extremes + e,
1216 summary_report (const struct examine *cmd, int iact_idx)
1218 const struct interaction *iact = cmd->iacts[iact_idx];
1220 const int heading_columns = 1 + iact->n_vars;
1221 const int heading_rows = 3;
1222 struct tab_table *t;
1224 const struct fmt_spec *wfmt = cmd->wv ? var_get_print_format (cmd->wv) : &F_8_0;
1226 size_t n_cats = categoricals_n_count (cmd->cats, iact_idx);
1228 const int nr = heading_rows + n_cats * cmd->n_dep_vars;
1229 const int nc = 6 + heading_columns;
1231 t = tab_create (nc, nr);
1232 tab_title (t, _("Case Processing Summary"));
1234 tab_headers (t, heading_columns, 0, heading_rows, 0);
1236 /* Internal Vertical lines */
1237 tab_box (t, -1, -1, -1, TAL_1,
1238 heading_columns, 0, nc - 1, nr - 1);
1240 /* External Frame */
1241 tab_box (t, TAL_2, TAL_2, -1, -1,
1242 0, 0, nc - 1, nr - 1);
1244 tab_hline (t, TAL_2, 0, nc - 1, heading_rows);
1245 tab_vline (t, TAL_2, heading_columns, 0, nr - 1);
1247 tab_joint_text (t, heading_columns, 0,
1248 nc - 1, 0, TAB_CENTER | TAT_TITLE, _("Cases"));
1251 heading_columns + 1, 1,
1252 TAB_CENTER | TAT_TITLE, _("Valid"));
1255 heading_columns + 2, 1,
1256 heading_columns + 3, 1,
1257 TAB_CENTER | TAT_TITLE, _("Missing"));
1260 heading_columns + 4, 1,
1261 heading_columns + 5, 1,
1262 TAB_CENTER | TAT_TITLE, _("Total"));
1264 for (i = 0; i < 3; ++i)
1266 tab_text (t, heading_columns + i * 2, 2, TAB_CENTER | TAT_TITLE,
1268 tab_text (t, heading_columns + i * 2 + 1, 2, TAB_CENTER | TAT_TITLE,
1272 for (i = 0; i < iact->n_vars; ++i)
1277 var_to_string (iact->vars[i])
1282 for (v = 0; v < cmd->n_dep_vars; ++v)
1285 const union value **prev_values = previous_value_alloc (iact);
1288 tab_hline (t, TAL_1, 0, nc - 1, heading_rows + v * n_cats);
1291 0, heading_rows + n_cats * v,
1293 var_to_string (cmd->dep_vars[v])
1297 for (i = 0; i < n_cats; ++i)
1300 const struct exploratory_stats *es;
1302 const struct ccase *c =
1303 categoricals_get_case_by_category_real (cmd->cats,
1307 int diff_idx = previous_value_record (iact, c, prev_values);
1309 if ( diff_idx != -1 && diff_idx < iact->n_vars - 1)
1310 tab_hline (t, TAL_1, 1 + diff_idx, nc - 1,
1311 heading_rows + n_cats * v + i );
1313 for (ivar_idx = 0; ivar_idx < iact->n_vars; ++ivar_idx)
1315 const struct variable *ivar = iact->vars[ivar_idx];
1316 const union value *val = case_data (c, ivar);
1318 if (( diff_idx != -1 && diff_idx <= ivar_idx)
1322 ds_init_empty (&str);
1323 var_append_value_name (ivar, val, &str);
1326 1 + ivar_idx, heading_rows + n_cats * v + i,
1327 TAT_TITLE | TAB_LEFT,
1337 es = categoricals_get_user_data_by_category_real (cmd->cats, iact_idx, i);
1340 total = es[v].missing + es[v].non_missing;
1342 heading_columns + 0,
1343 heading_rows + n_cats * v + i,
1350 heading_columns + 1,
1351 heading_rows + n_cats * v + i,
1354 100.0 * es[v].non_missing / total
1359 heading_columns + 2,
1360 heading_rows + n_cats * v + i,
1366 heading_columns + 3,
1367 heading_rows + n_cats * v + i,
1370 100.0 * es[v].missing / total
1373 heading_columns + 4,
1374 heading_rows + n_cats * v + i,
1379 /* This can only be 100% can't it? */
1381 heading_columns + 5,
1382 heading_rows + n_cats * v + i,
1385 100.0 * (es[v].missing + es[v].non_missing)/ total
1391 tab_hline (t, TAL_1, heading_columns, nc - 1, 1);
1392 tab_hline (t, TAL_1, heading_columns, nc - 1, 2);
1398 /* Match a variable.
1399 If the match succeeds, the variable will be placed in VAR.
1400 Returns true if successful */
1402 lex_match_variable (struct lexer *lexer,
1403 const struct dictionary *dict, const struct variable **var)
1405 if (lex_token (lexer) != T_ID)
1409 *var = parse_variable_const (lexer, dict);
1416 /* Attempt to parse an interaction from LEXER */
1417 static struct interaction *
1418 parse_interaction (struct lexer *lexer, struct examine *ex)
1420 const struct variable *v = NULL;
1421 struct interaction *iact = NULL;
1423 if ( lex_match_variable (lexer, ex->dict, &v))
1425 iact = interaction_create (v);
1427 while (lex_match (lexer, T_BY))
1429 if (!lex_match_variable (lexer, ex->dict, &v))
1431 interaction_destroy (iact);
1434 interaction_add_variable (iact, v);
1436 lex_match (lexer, T_COMMA);
1444 create_n (const void *aux1, void *aux2 UNUSED)
1448 const struct examine *examine = aux1;
1449 struct exploratory_stats *es = pool_calloc (examine->pool, examine->n_dep_vars, sizeof (*es));
1450 struct subcase ordering;
1451 subcase_init (&ordering, 0, 0, SC_ASCEND);
1453 for (v = 0; v < examine->n_dep_vars; v++)
1455 es[v].sorted_writer = sort_create_writer (&ordering, examine->ex_proto);
1456 es[v].sorted_reader = NULL;
1458 es[v].mom = moments_create (MOMENT_KURTOSIS);
1459 es[v].cmin = DBL_MAX;
1461 es[v].maximum = -DBL_MAX;
1462 es[v].minimum = DBL_MAX;
1465 subcase_destroy (&ordering);
1470 update_n (const void *aux1, void *aux2 UNUSED, void *user_data,
1471 const struct ccase *c, double weight)
1474 const struct examine *examine = aux1;
1475 struct exploratory_stats *es = user_data;
1477 for (v = 0; v < examine->n_dep_vars; v++)
1479 struct ccase *outcase ;
1480 const struct variable *var = examine->dep_vars[v];
1481 const double x = case_data (c, var)->f;
1483 if (var_is_value_missing (var, case_data (c, var), examine->exclude))
1485 es[v].missing += weight;
1489 outcase = case_create (examine->ex_proto);
1491 if (x > es[v].maximum)
1494 if (x < es[v].minimum)
1497 es[v].non_missing += weight;
1499 moments_pass_one (es[v].mom, x, weight);
1501 /* Save the value and the ID to the writer */
1502 assert (examine->id_idx != -1);
1503 case_data_rw_idx (outcase, EX_VAL)->f = x;
1504 value_copy (case_data_rw_idx (outcase, EX_ID),
1505 case_data_idx (c, examine->id_idx), examine->id_width);
1507 case_data_rw_idx (outcase, EX_WT)->f = weight;
1511 if (es[v].cmin > weight)
1512 es[v].cmin = weight;
1514 casewriter_write (es[v].sorted_writer, outcase);
1519 calculate_n (const void *aux1, void *aux2 UNUSED, void *user_data)
1522 const struct examine *examine = aux1;
1523 struct exploratory_stats *es = user_data;
1525 for (v = 0; v < examine->n_dep_vars; v++)
1528 casenumber imin = 0;
1529 double imax = es[v].cc;
1530 struct casereader *reader;
1532 casenumber total_cases;
1534 if (examine->histogram)
1537 double bin_width = abs (es[v].minimum - es[v].maximum)
1538 / (1 + log2 (es[v].cc))
1541 bin_width = chart_rounded_tick (bin_width);
1544 histogram_create (bin_width, es[v].minimum, es[v].maximum);
1547 es[v].sorted_reader = casewriter_make_reader (es[v].sorted_writer);
1548 total_cases = casereader_count_cases (es[v].sorted_reader);
1549 es[v].sorted_writer = NULL;
1551 es[v].maxima = pool_calloc (examine->pool, examine->calc_extremes, sizeof (*es[v].maxima));
1552 es[v].minima = pool_calloc (examine->pool, examine->calc_extremes, sizeof (*es[v].minima));
1553 for (i = 0; i < examine->calc_extremes; ++i)
1555 value_init_pool (examine->pool, &es[v].maxima[i].identity, examine->id_width) ;
1556 value_init_pool (examine->pool, &es[v].minima[i].identity, examine->id_width) ;
1559 for (reader = casereader_clone (es[v].sorted_reader);
1560 (c = casereader_read (reader)) != NULL; case_unref (c))
1562 const double val = case_data_idx (c, EX_VAL)->f;
1563 const double wt = case_data_idx (c, EX_WT)->f; /* FIXME: What about fractional weights ??? */
1565 moments_pass_two (es[v].mom, val, wt);
1567 if (es[v].histogram)
1568 histogram_add (es[v].histogram, val, wt);
1570 if (imin < examine->calc_extremes)
1573 for (x = imin; x < examine->calc_extremes; ++x)
1575 struct extremity *min = &es[v].minima[x];
1577 value_copy (&min->identity, case_data_idx (c, EX_ID), examine->id_width);
1583 if (imax < examine->calc_extremes)
1587 for (x = imax; x < imax + wt; ++x)
1589 struct extremity *max;
1591 if (x >= examine->calc_extremes)
1594 max = &es[v].maxima[x];
1596 value_copy (&max->identity, case_data_idx (c, EX_ID), examine->id_width);
1600 casereader_destroy (reader);
1602 if (examine->calc_extremes > 0)
1604 assert (es[v].minima[0].val == es[v].minimum);
1605 assert (es[v].maxima[0].val == es[v].maximum);
1609 const int n_os = 5 + examine->n_percentiles;
1610 struct order_stats **os ;
1611 es[v].percentiles = pool_calloc (examine->pool, examine->n_percentiles, sizeof (*es[v].percentiles));
1613 es[v].trimmed_mean = trimmed_mean_create (es[v].cc, 0.05);
1615 os = xcalloc (n_os, sizeof *os);
1616 os[0] = &es[v].trimmed_mean->parent;
1618 es[v].quartiles[0] = percentile_create (0.25, es[v].cc);
1619 es[v].quartiles[1] = percentile_create (0.5, es[v].cc);
1620 es[v].quartiles[2] = percentile_create (0.75, es[v].cc);
1622 os[1] = &es[v].quartiles[0]->parent;
1623 os[2] = &es[v].quartiles[1]->parent;
1624 os[3] = &es[v].quartiles[2]->parent;
1626 es[v].hinges = tukey_hinges_create (es[v].cc, es[v].cmin);
1627 os[4] = &es[v].hinges->parent;
1629 for (i = 0; i < examine->n_percentiles; ++i)
1631 es[v].percentiles[i] = percentile_create (examine->ptiles[i] / 100.00, es[v].cc);
1632 os[5 + i] = &es[v].percentiles[i]->parent;
1635 order_stats_accumulate_idx (os, n_os,
1636 casereader_clone (es[v].sorted_reader),
1642 if (examine->boxplot)
1644 struct order_stats *os;
1646 es[v].box_whisker = box_whisker_create (es[v].hinges,
1647 EX_ID, examine->id_var);
1649 os = &es[v].box_whisker->parent;
1650 order_stats_accumulate_idx (&os, 1,
1651 casereader_clone (es[v].sorted_reader),
1655 if (examine->npplot)
1657 double n, mean, var;
1658 struct order_stats *os;
1660 moments_calculate (es[v].mom, &n, &mean, &var, NULL, NULL);
1662 es[v].np = np_create (n, mean, var);
1664 os = &es[v].np->parent;
1666 order_stats_accumulate_idx (&os, 1,
1667 casereader_clone (es[v].sorted_reader),
1675 cleanup_exploratory_stats (struct examine *cmd)
1678 for (i = 0; i < cmd->n_iacts; ++i)
1681 const size_t n_cats = categoricals_n_count (cmd->cats, i);
1683 for (v = 0; v < cmd->n_dep_vars; ++v)
1686 for (grp = 0; grp < n_cats; ++grp)
1689 const struct exploratory_stats *es =
1690 categoricals_get_user_data_by_category_real (cmd->cats, i, grp);
1692 struct order_stats *os = &es[v].hinges->parent;
1693 struct statistic *stat = &os->parent;
1694 stat->destroy (stat);
1696 for (q = 0; q < 3 ; q++)
1698 os = &es[v].quartiles[q]->parent;
1700 stat->destroy (stat);
1703 for (q = 0; q < cmd->n_percentiles ; q++)
1705 os = &es[v].percentiles[q]->parent;
1707 stat->destroy (stat);
1710 os = &es[v].trimmed_mean->parent;
1712 stat->destroy (stat);
1714 os = &es[v].np->parent;
1718 stat->destroy (stat);
1721 statistic_destroy (&es[v].histogram->parent);
1722 moments_destroy (es[v].mom);
1724 casereader_destroy (es[v].sorted_reader);
1732 run_examine (struct examine *cmd, struct casereader *input)
1736 struct casereader *reader;
1738 struct payload payload;
1739 payload.create = create_n;
1740 payload.update = update_n;
1741 payload.destroy = calculate_n;
1743 cmd->wv = dict_get_weight (cmd->dict);
1746 = categoricals_create (cmd->iacts, cmd->n_iacts,
1747 cmd->wv, cmd->exclude);
1749 categoricals_set_payload (cmd->cats, &payload, cmd, NULL);
1751 if (cmd->id_idx == -1)
1753 struct ccase *c = casereader_peek (input, 0);
1755 assert (cmd->id_var == NULL);
1757 cmd->id_idx = case_get_value_cnt (c);
1758 input = casereader_create_arithmetic_sequence (input, 1.0, 1.0);
1763 /* FIXME: Filter out missing factor variables */
1765 /* Remove cases on a listwise basis if requested */
1766 if ( cmd->missing_pw == false)
1767 input = casereader_create_filter_missing (input,
1774 for (reader = input;
1775 (c = casereader_read (reader)) != NULL; case_unref (c))
1777 categoricals_update (cmd->cats, c);
1779 casereader_destroy (reader);
1780 categoricals_done (cmd->cats);
1782 for (i = 0; i < cmd->n_iacts; ++i)
1784 summary_report (cmd, i);
1786 if (cmd->disp_extremes > 0)
1787 extremes_report (cmd, i);
1789 if (cmd->n_percentiles > 0)
1790 percentiles_report (cmd, i);
1794 switch (cmd->boxplot_mode)
1797 show_boxplot_grouped (cmd, i);
1800 show_boxplot_variabled (cmd, i);
1809 show_histogram (cmd, i);
1812 show_npplot (cmd, i);
1814 if (cmd->descriptives)
1815 descriptives_report (cmd, i);
1818 cleanup_exploratory_stats (cmd);
1819 categoricals_destroy (cmd->cats);
1824 cmd_examine (struct lexer *lexer, struct dataset *ds)
1827 bool nototals_seen = false;
1828 bool totals_seen = false;
1830 struct interaction **iacts_mem = NULL;
1831 struct examine examine;
1832 bool percentiles_seen = false;
1834 examine.missing_pw = false;
1835 examine.disp_extremes = 0;
1836 examine.calc_extremes = 0;
1837 examine.descriptives = false;
1838 examine.conf = 0.95;
1839 examine.pc_alg = PC_HAVERAGE;
1840 examine.ptiles = NULL;
1841 examine.n_percentiles = 0;
1842 examine.id_idx = -1;
1843 examine.id_width = 0;
1844 examine.id_var = NULL;
1845 examine.boxplot_mode = BP_GROUPS;
1847 examine.ex_proto = caseproto_create ();
1849 examine.pool = pool_create ();
1851 /* Allocate space for the first interaction.
1852 This is interaction is an empty one (for the totals).
1853 If no totals are requested, we will simply ignore this
1856 examine.n_iacts = 1;
1857 examine.iacts = iacts_mem = pool_zalloc (examine.pool, sizeof (struct interaction *));
1858 examine.iacts[0] = interaction_create (NULL);
1860 examine.exclude = MV_ANY;
1861 examine.histogram = false;
1862 examine.npplot = false;
1863 examine.boxplot = false;
1865 examine.dict = dataset_dict (ds);
1867 /* Accept an optional, completely pointless "/VARIABLES=" */
1868 lex_match (lexer, T_SLASH);
1869 if (lex_match_id (lexer, "VARIABLES"))
1871 if (! lex_force_match (lexer, T_EQUALS) )
1875 if (!parse_variables_const (lexer, examine.dict,
1876 &examine.dep_vars, &examine.n_dep_vars,
1877 PV_NO_DUPLICATE | PV_NUMERIC))
1880 if (lex_match (lexer, T_BY))
1882 struct interaction *iact = NULL;
1885 iact = parse_interaction (lexer, &examine);
1890 pool_nrealloc (examine.pool, iacts_mem,
1892 sizeof (*iacts_mem));
1894 iacts_mem[examine.n_iacts - 1] = iact;
1901 while (lex_token (lexer) != T_ENDCMD)
1903 lex_match (lexer, T_SLASH);
1905 if (lex_match_id (lexer, "STATISTICS"))
1907 lex_match (lexer, T_EQUALS);
1909 while (lex_token (lexer) != T_ENDCMD
1910 && lex_token (lexer) != T_SLASH)
1912 if (lex_match_id (lexer, "DESCRIPTIVES"))
1914 examine.descriptives = true;
1916 else if (lex_match_id (lexer, "EXTREME"))
1919 if (lex_match (lexer, T_LPAREN))
1921 extr = lex_integer (lexer);
1925 msg (MW, _("%s may not be negative. Using default value (%g)."), "EXTREME", 5.0);
1930 if (! lex_force_match (lexer, T_RPAREN))
1933 examine.disp_extremes = extr;
1935 else if (lex_match_id (lexer, "NONE"))
1938 else if (lex_match (lexer, T_ALL))
1940 if (examine.disp_extremes == 0)
1941 examine.disp_extremes = 5;
1945 lex_error (lexer, NULL);
1950 else if (lex_match_id (lexer, "PERCENTILES"))
1952 percentiles_seen = true;
1953 if (lex_match (lexer, T_LPAREN))
1955 while (lex_is_number (lexer))
1957 double p = lex_number (lexer);
1959 if ( p <= 0 || p >= 100.0)
1962 _("Percentiles must lie in the range (0, 100)"));
1966 examine.n_percentiles++;
1968 xrealloc (examine.ptiles,
1969 sizeof (*examine.ptiles) *
1970 examine.n_percentiles);
1972 examine.ptiles[examine.n_percentiles - 1] = p;
1975 lex_match (lexer, T_COMMA);
1977 if (!lex_force_match (lexer, T_RPAREN))
1981 lex_match (lexer, T_EQUALS);
1983 while (lex_token (lexer) != T_ENDCMD
1984 && lex_token (lexer) != T_SLASH)
1986 if (lex_match_id (lexer, "HAVERAGE"))
1988 examine.pc_alg = PC_HAVERAGE;
1990 else if (lex_match_id (lexer, "WAVERAGE"))
1992 examine.pc_alg = PC_WAVERAGE;
1994 else if (lex_match_id (lexer, "ROUND"))
1996 examine.pc_alg = PC_ROUND;
1998 else if (lex_match_id (lexer, "EMPIRICAL"))
2000 examine.pc_alg = PC_EMPIRICAL;
2002 else if (lex_match_id (lexer, "AEMPIRICAL"))
2004 examine.pc_alg = PC_AEMPIRICAL;
2006 else if (lex_match_id (lexer, "NONE"))
2008 examine.pc_alg = PC_NONE;
2012 lex_error (lexer, NULL);
2017 else if (lex_match_id (lexer, "TOTAL"))
2021 else if (lex_match_id (lexer, "NOTOTAL"))
2023 nototals_seen = true;
2025 else if (lex_match_id (lexer, "MISSING"))
2027 lex_match (lexer, T_EQUALS);
2029 while (lex_token (lexer) != T_ENDCMD
2030 && lex_token (lexer) != T_SLASH)
2032 if (lex_match_id (lexer, "LISTWISE"))
2034 examine.missing_pw = false;
2036 else if (lex_match_id (lexer, "PAIRWISE"))
2038 examine.missing_pw = true;
2040 else if (lex_match_id (lexer, "EXCLUDE"))
2042 examine.exclude = MV_ANY;
2044 else if (lex_match_id (lexer, "INCLUDE"))
2046 examine.exclude = MV_SYSTEM;
2050 lex_error (lexer, NULL);
2055 else if (lex_match_id (lexer, "COMPARE"))
2057 lex_match (lexer, T_EQUALS);
2058 if (lex_match_id (lexer, "VARIABLES"))
2060 examine.boxplot_mode = BP_VARIABLES;
2062 else if (lex_match_id (lexer, "GROUPS"))
2064 examine.boxplot_mode = BP_GROUPS;
2068 lex_error (lexer, NULL);
2072 else if (lex_match_id (lexer, "PLOT"))
2074 lex_match (lexer, T_EQUALS);
2076 while (lex_token (lexer) != T_ENDCMD
2077 && lex_token (lexer) != T_SLASH)
2079 if (lex_match_id (lexer, "BOXPLOT"))
2081 examine.boxplot = true;
2083 else if (lex_match_id (lexer, "NPPLOT"))
2085 examine.npplot = true;
2087 else if (lex_match_id (lexer, "HISTOGRAM"))
2089 examine.histogram = true;
2091 else if (lex_match_id (lexer, "NONE"))
2093 examine.histogram = false;
2094 examine.npplot = false;
2095 examine.boxplot = false;
2097 else if (lex_match (lexer, T_ALL))
2099 examine.histogram = true;
2100 examine.npplot = true;
2101 examine.boxplot = true;
2105 lex_error (lexer, NULL);
2108 lex_match (lexer, T_COMMA);
2111 else if (lex_match_id (lexer, "CINTERVAL"))
2113 if ( !lex_force_num (lexer))
2116 examine.conf = lex_number (lexer);
2119 else if (lex_match_id (lexer, "ID"))
2121 lex_match (lexer, T_EQUALS);
2123 examine.id_var = parse_variable_const (lexer, examine.dict);
2127 lex_error (lexer, NULL);
2133 if ( totals_seen && nototals_seen)
2135 msg (SE, _("%s and %s are mutually exclusive"),"TOTAL","NOTOTAL");
2139 /* If totals have been requested or if there are no factors
2140 in this analysis, then the totals need to be included. */
2141 if ( !nototals_seen || examine.n_iacts == 1)
2143 examine.iacts = &iacts_mem[0];
2148 examine.iacts = &iacts_mem[1];
2152 if ( examine.id_var )
2154 examine.id_idx = var_get_case_index (examine.id_var);
2155 examine.id_width = var_get_width (examine.id_var);
2158 examine.ex_proto = caseproto_add_width (examine.ex_proto, 0); /* value */
2159 examine.ex_proto = caseproto_add_width (examine.ex_proto, examine.id_width); /* id */
2160 examine.ex_proto = caseproto_add_width (examine.ex_proto, 0); /* weight */
2163 if (examine.disp_extremes > 0)
2165 examine.calc_extremes = examine.disp_extremes;
2168 if (examine.descriptives && examine.calc_extremes == 0)
2170 /* Descriptives always displays the max and min */
2171 examine.calc_extremes = 1;
2174 if (percentiles_seen && examine.n_percentiles == 0)
2176 examine.n_percentiles = 7;
2177 examine.ptiles = xcalloc (examine.n_percentiles,
2178 sizeof (*examine.ptiles));
2180 examine.ptiles[0] = 5;
2181 examine.ptiles[1] = 10;
2182 examine.ptiles[2] = 25;
2183 examine.ptiles[3] = 50;
2184 examine.ptiles[4] = 75;
2185 examine.ptiles[5] = 90;
2186 examine.ptiles[6] = 95;
2189 assert (examine.calc_extremes >= examine.disp_extremes);
2191 struct casegrouper *grouper;
2192 struct casereader *group;
2195 grouper = casegrouper_create_splits (proc_open (ds), examine.dict);
2196 while (casegrouper_get_next_group (grouper, &group))
2197 run_examine (&examine, group);
2198 ok = casegrouper_destroy (grouper);
2199 ok = proc_commit (ds) && ok;
2202 caseproto_unref (examine.ex_proto);
2204 for (i = 0; i < examine.n_iacts; ++i)
2205 interaction_destroy (examine.iacts[i]);
2207 free (examine.ptiles);
2208 free (examine.dep_vars);
2209 pool_destroy (examine.pool);
2214 caseproto_unref (examine.ex_proto);
2215 for (i = 0; i < examine.n_iacts; ++i)
2216 interaction_destroy (examine.iacts[i]);
2217 free (examine.dep_vars);
2218 free (examine.ptiles);
2219 pool_destroy (examine.pool);