#include "data/variable.h"
#include "libpspp/message.h"
#include "libpspp/misc.h"
-#include "output/tab.h"
+#include "output/pivot-table.h"
#include "gettext.h"
+#define N_(msgid) msgid
#define _(msgid) gettext (msgid)
const struct dictionary *dict;
};
-static void show_ranks_box (const struct one_sample_test *ost,
+static void show_ranks_box (const struct one_sample_test *ost,
const struct friedman *fr);
static void show_sig_box (const struct one_sample_test *ost,
if (a->x < b->x)
return -1;
-
+
return (a->x > b->x);
}
if (a->posn < b->posn)
return -1;
-
+
return (a->posn > b->posn);
}
struct friedman_test *ft = UP_CAST (ost, struct friedman_test, parent);
bool warn = true;
- double sigma_t = 0.0;
- struct datum *row = xcalloc (ost->n_vars, sizeof *row);
+ double sigma_t = 0.0;
+ struct datum *row = XCALLOC (ost->n_vars, struct datum);
double rsq;
struct friedman fr;
fr.rank_sum = xcalloc (ost->n_vars, sizeof *fr.rank_sum);
double prev_x = SYSMIS;
int run_length = 0;
- const double w = weight ? case_data (c, weight)->f: 1.0;
+ const double w = weight ? case_num (c, weight) : 1.0;
fr.cc += w;
{
double x = row[v].x;
/* Replace value by the Rank */
- if ( prev_x == x)
+ if (prev_x == x)
{
/* Deal with ties */
int i;
else
{
row[v].x = v + 1;
- if ( run_length > 0)
+ if (run_length > 0)
{
double t = run_length + 1;
sigma_t += w * (pow3 (t) - t);
}
prev_x = x;
}
- if ( run_length > 0)
+ if (run_length > 0)
{
double t = run_length + 1;
- sigma_t += w * (pow3 (t) - t );
+ sigma_t += w * (pow3 (t) - t);
}
qsort (row, ost->n_vars, sizeof *row, cmp_posn);
rsq = numerator;
- numerator *= 12.0 / (fr.cc * ost->n_vars * ( ost->n_vars + 1));
- numerator -= 3 * fr.cc * ( ost->n_vars + 1);
+ numerator *= 12.0 / (fr.cc * ost->n_vars * (ost->n_vars + 1));
+ numerator -= 3 * fr.cc * (ost->n_vars + 1);
- denominator = 1 - sigma_t / ( fr.cc * ost->n_vars * ( pow2 (ost->n_vars) - 1));
+ denominator = 1 - sigma_t / (fr.cc * ost->n_vars * (pow2 (ost->n_vars) - 1));
fr.chi_sq = numerator / denominator;
- if ( ft->kendalls_w)
+ if (ft->kendalls_w)
{
fr.w = 12 * rsq ;
fr.w -= 3 * pow2 (fr.cc) *
static void
show_ranks_box (const struct one_sample_test *ost, const struct friedman *fr)
{
- int i;
- const int row_headers = 1;
- const int column_headers = 1;
- struct tab_table *table =
- tab_create (row_headers + 1, column_headers + ost->n_vars);
-
- tab_headers (table, row_headers, 0, column_headers, 0);
-
- tab_title (table, _("Ranks"));
+ struct pivot_table *table = pivot_table_create (N_("Ranks"));
- /* Vertical lines inside the box */
- tab_box (table, 1, 0, -1, TAL_1,
- row_headers, 0, tab_nc (table) - 1, tab_nr (table) - 1 );
+ pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("Mean Rank"),
+ N_("Mean Rank"), PIVOT_RC_OTHER);
- /* Box around the table */
- tab_box (table, TAL_2, TAL_2, -1, -1,
- 0, 0, tab_nc (table) - 1, tab_nr (table) - 1 );
+ struct pivot_dimension *variables = pivot_dimension_create (
+ table, PIVOT_AXIS_ROW, N_("Variable"));
-
- tab_text (table, 1, 0, 0, _("Mean Rank"));
-
- tab_hline (table, TAL_2, 0, tab_nc (table) - 1, column_headers);
- tab_vline (table, TAL_2, row_headers, 0, tab_nr (table) - 1);
-
- for (i = 0 ; i < ost->n_vars ; ++i)
+ for (size_t i = 0 ; i < ost->n_vars ; ++i)
{
- tab_text (table, 0, row_headers + i,
- TAB_LEFT, var_to_string (ost->vars[i]));
+ int row = pivot_category_create_leaf (
+ variables->root, pivot_value_new_variable (ost->vars[i]));
- tab_double (table, 1, row_headers + i,
- 0, fr->rank_sum[i] / fr->cc, 0);
+ pivot_table_put2 (table, 0, row,
+ pivot_value_new_number (fr->rank_sum[i] / fr->cc));
}
- tab_submit (table);
+ pivot_table_submit (table);
}
show_sig_box (const struct one_sample_test *ost, const struct friedman *fr)
{
const struct friedman_test *ft = UP_CAST (ost, const struct friedman_test, parent);
-
- int row = 0;
- const struct variable *weight = dict_get_weight (fr->dict);
- const struct fmt_spec *wfmt = weight ? var_get_print_format (weight) : &F_8_0;
-
- const int row_headers = 1;
- const int column_headers = 0;
- struct tab_table *table =
- tab_create (row_headers + 1, column_headers + (ft->kendalls_w ? 5 : 4));
-
- tab_headers (table, row_headers, 0, column_headers, 0);
- tab_title (table, _("Test Statistics"));
-
- tab_text (table, 0, column_headers + row++,
- TAT_TITLE | TAB_LEFT , _("N"));
-
- if ( ft->kendalls_w)
- tab_text (table, 0, column_headers + row++,
- TAT_TITLE | TAB_LEFT , _("Kendall's W"));
-
- tab_text (table, 0, column_headers + row++,
- TAT_TITLE | TAB_LEFT , _("Chi-Square"));
-
- tab_text (table, 0, column_headers + row++,
- TAT_TITLE | TAB_LEFT, _("df"));
-
- tab_text (table, 0, column_headers + row++,
- TAT_TITLE | TAB_LEFT, _("Asymp. Sig."));
-
- /* Box around the table */
- tab_box (table, TAL_2, TAL_2, -1, -1,
- 0, 0, tab_nc (table) - 1, tab_nr (table) - 1 );
-
-
- tab_hline (table, TAL_2, 0, tab_nc (table) -1, column_headers);
- tab_vline (table, TAL_2, row_headers, 0, tab_nr (table) - 1);
-
- row = 0;
- tab_double (table, 1, column_headers + row++,
- 0, fr->cc, wfmt);
+ struct pivot_table *table = pivot_table_create (N_("Test Statistics"));
+ pivot_table_set_weight_var (table, dict_get_weight (fr->dict));
+ struct pivot_dimension *statistics = pivot_dimension_create (
+ table, PIVOT_AXIS_ROW, N_("Statistics"),
+ N_("N"), PIVOT_RC_COUNT);
if (ft->kendalls_w)
- tab_double (table, 1, column_headers + row++,
- 0, fr->w, 0);
+ pivot_category_create_leaves (statistics->root, N_("Kendall's W"),
+ PIVOT_RC_OTHER);
+ pivot_category_create_leaves (statistics->root,
+ N_("Chi-Square"), PIVOT_RC_OTHER,
+ N_("df"), PIVOT_RC_INTEGER,
+ N_("Asymp. Sig."), PIVOT_RC_SIGNIFICANCE);
- tab_double (table, 1, column_headers + row++,
- 0, fr->chi_sq, 0);
+ double entries[5];
+ int n = 0;
- tab_double (table, 1, column_headers + row++,
- 0, ost->n_vars - 1, &F_8_0);
+ entries[n++] = fr->cc;
+ if (ft->kendalls_w)
+ entries[n++] = fr->w;
+ entries[n++] = fr->chi_sq;
+ entries[n++] = ost->n_vars - 1;
+ entries[n++] = gsl_cdf_chisq_Q (fr->chi_sq, ost->n_vars - 1);
+ assert (n <= sizeof entries / sizeof *entries);
- tab_double (table, 1, column_headers + row++,
- 0, gsl_cdf_chisq_Q (fr->chi_sq, ost->n_vars - 1),
- 0);
+ for (size_t i = 0; i < n; i++)
+ pivot_table_put1 (table, i, pivot_value_new_number (entries[i]));
- tab_submit (table);
+ pivot_table_submit (table);
}