+ pivot_table_submit (table);
+}
+
+static void
+create_classification_dimension (const struct lr_spec *cmd,
+ const struct lr_result *res,
+ struct pivot_table *table,
+ enum pivot_axis_type axis_type,
+ const char *label, const char *total)
+{
+ struct pivot_dimension *d = pivot_dimension_create (
+ table, axis_type, label);
+ d->root->show_label = true;
+ struct pivot_category *pred_group = pivot_category_create_group__ (
+ d->root, pivot_value_new_variable (cmd->dep_var));
+ for (int i = 0; i < 2; i++)
+ {
+ const union value *y = i ? &res->y1 : &res->y0;
+ pivot_category_create_leaf_rc (
+ pred_group, pivot_value_new_var_value (cmd->dep_var, y),
+ PIVOT_RC_COUNT);
+ }
+ pivot_category_create_leaves (d->root, total, PIVOT_RC_PERCENT);
+}
+
+static void
+output_classification_table (const struct lr_spec *cmd, const struct lr_result *res)
+{
+ struct pivot_table *table = pivot_table_create (N_("Classification Table"));
+ pivot_table_set_weight_var (table, cmd->wv);
+
+ create_classification_dimension (cmd, res, table, PIVOT_AXIS_COLUMN,
+ N_("Predicted"), N_("Percentage Correct"));
+ create_classification_dimension (cmd, res, table, PIVOT_AXIS_ROW,
+ N_("Observed"), N_("Overall Percentage"));
+
+ pivot_dimension_create (table, PIVOT_AXIS_ROW, N_("Step"), N_("Step 1"));
+
+ struct entry
+ {
+ int pred_idx;
+ int obs_idx;
+ double x;
+ }
+ entries[] = {
+ { 0, 0, res->tn },
+ { 0, 1, res->fn },
+ { 1, 0, res->fp },
+ { 1, 1, res->tp },
+ { 2, 0, 100 * res->tn / (res->tn + res->fp) },
+ { 2, 1, 100 * res->tp / (res->tp + res->fn) },
+ { 2, 2,
+ 100 * (res->tp + res->tn) / (res->tp + res->tn + res->fp + res->fn)},
+ };
+ for (size_t i = 0; i < sizeof entries / sizeof *entries; i++)
+ {
+ const struct entry *e = &entries[i];
+ pivot_table_put3 (table, e->pred_idx, e->obs_idx, 0,
+ pivot_value_new_number (e->x));
+ }