From: John Darrington Date: Sat, 9 Oct 2010 10:51:50 +0000 (+0200) Subject: NPAR TESTS: Add framework for n sample independent variable tests. X-Git-Tag: v0.7.6~43 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec7e9edc4433264efc66e6e3d661c198148f87c9;p=pspp-builds.git NPAR TESTS: Add framework for n sample independent variable tests. Upcomming commits will rely on this functionaly. --- diff --git a/src/language/stats/npar.c b/src/language/stats/npar.c index 409369ed..ad1724da 100644 --- a/src/language/stats/npar.c +++ b/src/language/stats/npar.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -303,6 +304,11 @@ static void two_sample_insert_variables (const struct npar_test *test, struct const_hsh_table *variables); +static void n_sample_insert_variables (const struct npar_test *test, + struct const_hsh_table *variables); + + + static void npar_execute (struct casereader *input, const struct npar_specs *specs, @@ -720,6 +726,52 @@ parse_two_sample_related_test (struct lexer *lexer, } +static bool +parse_n_sample_related_test (struct lexer *lexer, + const struct dictionary *dict, + struct n_sample_test *nst, + struct pool *pool + ) +{ + union value val1, val2; + + if (!parse_variables_const_pool (lexer, pool, + dict, + &nst->vars, &nst->n_vars, + PV_NUMERIC | PV_NO_SCRATCH | PV_NO_DUPLICATE) ) + return false; + + if ( ! lex_force_match (lexer, T_BY)) + return false; + + nst->indep_var = parse_variable_const (lexer, dict); + + if ( ! lex_force_match (lexer, '(')) + return false; + + value_init (&val1, var_get_width (nst->indep_var)); + if ( ! parse_value (lexer, &val1, var_get_width (nst->indep_var))) + { + value_destroy (&val1, var_get_width (nst->indep_var)); + return false; + } + + if ( ! lex_force_match (lexer, ',')) + return false; + + value_init (&val2, var_get_width (nst->indep_var)); + if ( ! parse_value (lexer, &val2, var_get_width (nst->indep_var))) + { + value_destroy (&val2, var_get_width (nst->indep_var)); + return false; + } + + if ( ! lex_force_match (lexer, ')')) + return false; + + return true; +} + static int npar_wilcoxon (struct lexer *lexer, struct dataset *ds, @@ -766,7 +818,6 @@ npar_sign (struct lexer *lexer, struct dataset *ds, return 1; } - /* Insert the variables for TEST into VAR_HASH */ static void one_sample_insert_variables (const struct npar_test *test, @@ -797,6 +848,19 @@ two_sample_insert_variables (const struct npar_test *test, } } +static void +n_sample_insert_variables (const struct npar_test *test, + struct const_hsh_table *var_hash) +{ + int i; + const struct n_sample_test *tst = UP_CAST (test, const struct n_sample_test, parent); + + for ( i = 0 ; i < tst->n_vars ; ++i ) + const_hsh_insert (var_hash, tst->vars[i]); + + const_hsh_insert (var_hash, tst->indep_var); +} + static int npar_method (struct lexer *lexer, struct npar_specs *specs) { diff --git a/src/language/stats/npar.h b/src/language/stats/npar.h index 6aed01cf..082d396b 100644 --- a/src/language/stats/npar.h +++ b/src/language/stats/npar.h @@ -45,6 +45,7 @@ struct npar_test struct const_hsh_table *); }; + struct one_sample_test { struct npar_test parent; @@ -60,4 +61,13 @@ struct two_sample_test }; +struct n_sample_test +{ + struct npar_test parent; + const struct variable **vars; + size_t n_vars; + + const struct variable *indep_var; +}; + #endif