- ds_init_empty (&catstr1);
- ds_init_empty (&catstr2);
-
- var_append_value_name (var, cat1[v].value, &catstr1);
- var_append_value_name (var, cat2[v].value, &catstr2);
-
- tab_hline (table, TAL_1, 0, tab_nc (table) -1, 1 + v * 3);
-
- /* Titles */
- tab_text (table, 0, 1 + v * 3, TAB_LEFT, var_to_string (var));
- tab_text (table, 1, 1 + v * 3, TAB_LEFT, _("Group1"));
- tab_text (table, 1, 2 + v * 3, TAB_LEFT, _("Group2"));
- tab_text (table, 1, 3 + v * 3, TAB_LEFT, _("Total"));
-
- /* Test Prop */
- tab_float (table, 5, 1 + v * 3, TAB_NONE, bst->p, 8, 3);
-
- /* Category labels */
- tab_text (table, 2, 1 + v * 3, TAB_NONE, ds_cstr (&catstr1));
- tab_text (table, 2, 2 + v * 3, TAB_NONE, ds_cstr (&catstr2));
-
- /* Observed N */
- tab_float (table, 3, 1 + v * 3, TAB_NONE, cat1[v].count, 8, 0);
- tab_float (table, 3, 2 + v * 3, TAB_NONE, cat2[v].count, 8, 0);
-
- n_total = cat1[v].count + cat2[v].count;
- tab_float (table, 3, 3 + v * 3, TAB_NONE, n_total, 8, 0);
-
- /* Observed Proportions */
- tab_float (table, 4, 1 + v * 3, TAB_NONE,
- cat1[v].count / n_total, 8, 3);
- tab_float (table, 4, 2 + v * 3, TAB_NONE,
- cat2[v].count / n_total, 8, 3);
- tab_float (table, 4, 3 + v * 3, TAB_NONE,
- (cat1[v].count + cat2[v].count) / n_total, 8, 2);
-
- /* Significance */
- sig = calculate_binomial (cat1[v].count, cat2[v].count, bst->p);
- tab_float (table, 6, 1 + v * 3, TAB_NONE, sig, 8, 3);
-
- ds_destroy (&catstr1);
- ds_destroy (&catstr2);
+ int var_idx = pivot_category_create_leaf (
+ variables->root, pivot_value_new_variable (var));
+
+ /* Category. */
+ if (bst->cutpoint != SYSMIS)
+ pivot_table_put3 (
+ table, 0, 0, var_idx,
+ pivot_value_new_user_text_nocopy (
+ xasprintf ("<= %.*g", DBL_DIG + 1, bst->cutpoint)));
+ else
+ for (int i = 0; i < 2; i++)
+ pivot_table_put3 (
+ table, 0, i, var_idx,
+ pivot_value_new_var_value (var, cat[i][v].values));
+
+ double n_total = cat[0][v].count + cat[1][v].count;
+ double sig = calculate_binomial (cat[0][v].count, cat[1][v].count,
+ bst->p);
+ struct entry
+ {
+ int stat_idx;
+ int group_idx;
+ double x;
+ }
+ entries[] = {
+ /* N. */
+ { 1, 0, cat[0][v].count },
+ { 1, 1, cat[1][v].count },
+ { 1, 2, n_total },
+ /* Observed Prop. */
+ { 2, 0, cat[0][v].count / n_total },
+ { 2, 1, cat[1][v].count / n_total },
+ { 2, 2, 1.0 },
+ /* Test Prop. */
+ { 3, 0, bst->p },
+ /* Significance. */
+ { 4, 0, sig }
+ };
+ for (size_t i = 0; i < sizeof entries / sizeof *entries; i++)
+ {
+ const struct entry *e = &entries[i];
+ pivot_table_put3 (table, e->stat_idx, e->group_idx,
+ var_idx, pivot_value_new_number (e->x));
+ }