double *rank_sum;
double cc;
double chi_sq;
+ double w;
const struct dictionary *dict;
};
static void show_sig_box (const struct one_sample_test *ost,
const struct friedman *fr);
-
struct datum
{
long posn;
void
friedman_execute (const struct dataset *ds,
- struct casereader *input,
- enum mv_class exclude,
- const struct npar_test *test,
- bool exact UNUSED,
- double timer UNUSED)
+ struct casereader *input,
+ enum mv_class exclude,
+ const struct npar_test *test,
+ bool exact UNUSED,
+ double timer UNUSED)
{
double numerator = 0.0;
double denominator = 0.0;
const struct dictionary *dict = dataset_dict (ds);
const struct variable *weight = dict_get_weight (dict);
- struct one_sample_test *ft = UP_CAST (test, struct one_sample_test, parent);
+ struct one_sample_test *ost = UP_CAST (test, struct one_sample_test, parent);
+ struct friedman_test *ft = UP_CAST (ost, struct friedman_test, parent);
bool warn = true;
double sigma_t = 0.0;
- struct datum *row = xcalloc (ft->n_vars, sizeof *row);
-
+ struct datum *row = xcalloc (ost->n_vars, sizeof *row);
+ double rsq;
struct friedman fr;
- fr.rank_sum = xcalloc (ft->n_vars, sizeof *fr.rank_sum);
+ fr.rank_sum = xcalloc (ost->n_vars, sizeof *fr.rank_sum);
fr.cc = 0.0;
fr.dict = dict;
- for (v = 0; v < ft->n_vars; ++v)
+ for (v = 0; v < ost->n_vars; ++v)
{
row[v].posn = v;
fr.rank_sum[v] = 0.0;
input = casereader_create_filter_weight (input, dict, &warn, NULL);
input = casereader_create_filter_missing (input,
- ft->vars, ft->n_vars,
+ ost->vars, ost->n_vars,
exclude, 0, 0);
for (; (c = casereader_read (input)); case_unref (c))
fr.cc += w;
- for (v = 0; v < ft->n_vars; ++v)
+ for (v = 0; v < ost->n_vars; ++v)
{
- const struct variable *var = ft->vars[v];
+ const struct variable *var = ost->vars[v];
const union value *val = case_data (c, var);
row[v].x = val->f;
}
- qsort (row, ft->n_vars, sizeof *row, cmp_x);
- for (v = 0; v < ft->n_vars; ++v)
+ qsort (row, ost->n_vars, sizeof *row, cmp_x);
+ for (v = 0; v < ost->n_vars; ++v)
{
double x = row[v].x;
/* Replace value by the Rank */
sigma_t += w * (pow3 (t) - t );
}
- qsort (row, ft->n_vars, sizeof *row, cmp_posn);
+ qsort (row, ost->n_vars, sizeof *row, cmp_posn);
- for (v = 0; v < ft->n_vars; ++v)
+ for (v = 0; v < ost->n_vars; ++v)
fr.rank_sum[v] += row[v].x * w;
}
casereader_destroy (input);
free (row);
- for (v = 0; v < ft->n_vars; ++v)
+ for (v = 0; v < ost->n_vars; ++v)
{
numerator += pow2 (fr.rank_sum[v]);
}
- numerator *= 12.0 / (fr.cc * ft->n_vars * ( ft->n_vars + 1));
- numerator -= 3 * fr.cc * ( ft->n_vars + 1);
+ rsq = numerator;
+
+ 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 * ft->n_vars * ( pow2 (ft->n_vars) - 1));
+ denominator = 1 - sigma_t / ( fr.cc * ost->n_vars * ( pow2 (ost->n_vars) - 1));
fr.chi_sq = numerator / denominator;
- show_ranks_box (ft, &fr);
+ if ( ft->kendalls_w)
+ {
+ fr.w = 12 * rsq ;
+ fr.w -= 3 * pow2 (fr.cc) *
+ ost->n_vars * pow2 (ost->n_vars + 1);
- show_sig_box (ft, &fr);
+ fr.w /= pow2 (fr.cc) * (pow3 (ost->n_vars) - ost->n_vars)
+ - fr.cc * sigma_t;
+ }
+
+ show_ranks_box (ost, &fr);
+ show_sig_box (ost, &fr);
free (fr.rank_sum);
}
static void
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 + 4);
+ 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,
+ tab_text (table, 0, column_headers + row++,
TAT_TITLE | TAB_LEFT , _("N"));
- tab_text (table, 0, 1 + column_headers,
+ 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, 2 + column_headers,
+ tab_text (table, 0, column_headers + row++,
TAT_TITLE | TAB_LEFT, _("df"));
- tab_text (table, 0, 3 + column_headers,
+ tab_text (table, 0, column_headers + row++,
TAT_TITLE | TAB_LEFT, _("Asymp. Sig."));
/* Box around the table */
tab_hline (table, TAL_2, 0, tab_nc (table) -1, column_headers);
tab_vline (table, TAL_2, row_headers, 0, tab_nr (table) - 1);
- tab_double (table, 1, column_headers,
+ row = 0;
+ tab_double (table, 1, column_headers + row++,
0, fr->cc, wfmt);
- tab_double (table, 1, column_headers + 1,
+ if (ft->kendalls_w)
+ tab_double (table, 1, column_headers + row++,
+ 0, fr->w, 0);
+
+ tab_double (table, 1, column_headers + row++,
0, fr->chi_sq, 0);
- tab_double (table, 1, column_headers + 2,
+ tab_double (table, 1, column_headers + row++,
0, ost->n_vars - 1, &F_8_0);
- tab_double (table, 1, column_headers + 3,
+ tab_double (table, 1, column_headers + row++,
0, gsl_cdf_chisq_Q (fr->chi_sq, ost->n_vars - 1),
0);
int sign;
int runs;
int friedman;
+ int kendall;
int kruskal_wallis;
int mann_whitney;
int missing;
static int npar_binomial (struct lexer *, struct dataset *, struct npar_specs *);
static int npar_runs (struct lexer *, struct dataset *, struct npar_specs *);
static int npar_friedman (struct lexer *, struct dataset *, struct npar_specs *);
+static int npar_kendall (struct lexer *, struct dataset *, struct npar_specs *);
static int npar_cochran (struct lexer *, struct dataset *, struct npar_specs *);
static int npar_wilcoxon (struct lexer *, struct dataset *, struct npar_specs *);
static int npar_sign (struct lexer *, struct dataset *, struct npar_specs *);
NOT_REACHED ();
}
}
+ else if (lex_match_hyphenated_word (lexer, "KENDALL"))
+ {
+ npt->kendall++;
+ switch (npar_kendall (lexer, ds, nps))
+ {
+ case 0:
+ goto lossage;
+ case 1:
+ break;
+ case 2:
+ lex_error (lexer, NULL);
+ goto lossage;
+ default:
+ NOT_REACHED ();
+ }
+ }
else if (lex_match_hyphenated_word (lexer, "RUNS"))
{
npt->runs++;
npar_friedman (struct lexer *lexer, struct dataset *ds,
struct npar_specs *specs)
{
- struct one_sample_test *ft = pool_alloc (specs->pool, sizeof (*ft));
- struct npar_test *nt = &ft->parent;
+ struct friedman_test *ft = pool_alloc (specs->pool, sizeof (*ft));
+ struct one_sample_test *ost = &ft->parent;
+ struct npar_test *nt = &ost->parent;
+ ft->kendalls_w = false;
nt->execute = friedman_execute;
nt->insert_variables = one_sample_insert_variables;
lex_match (lexer, '=');
if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
- &ft->vars, &ft->n_vars,
+ &ost->vars, &ost->n_vars,
+ PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
+ {
+ return 2;
+ }
+
+ specs->n_tests++;
+ specs->test = pool_realloc (specs->pool,
+ specs->test,
+ sizeof (*specs->test) * specs->n_tests);
+
+ specs->test[specs->n_tests - 1] = nt;
+
+ return 1;
+}
+
+static int
+npar_kendall (struct lexer *lexer, struct dataset *ds,
+ struct npar_specs *specs)
+{
+ struct friedman_test *kt = pool_alloc (specs->pool, sizeof (*kt));
+ struct one_sample_test *ost = &kt->parent;
+ struct npar_test *nt = &ost->parent;
+
+ kt->kendalls_w = true;
+ nt->execute = friedman_execute;
+ nt->insert_variables = one_sample_insert_variables;
+
+ lex_match (lexer, '=');
+
+ if (!parse_variables_const_pool (lexer, specs->pool, dataset_dict (ds),
+ &ost->vars, &ost->n_vars,
PV_NO_SCRATCH | PV_NO_DUPLICATE | PV_NUMERIC))
{
return 2;
return 1;
}
+
static int
npar_cochran (struct lexer *lexer, struct dataset *ds,
struct npar_specs *specs)