X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Ft-test.q;h=3fbb6d88602fbd84627481e6323eb25e86fe3c60;hb=e7d0a9f16192ceeff9243f0ede8e399ee1ef0d44;hp=d0fff3fd0cb4505ecdaa801bf248fbde829c6415;hpb=dcf9b154cbcaa35c3d8459a201b77eec8bcb30bd;p=pspp-builds.git diff --git a/src/language/stats/t-test.q b/src/language/stats/t-test.q index d0fff3fd..3fbb6d88 100644 --- a/src/language/stats/t-test.q +++ b/src/language/stats/t-test.q @@ -20,30 +20,36 @@ 02110-1301, USA. */ #include + #include -#include "message.h" +#include #include #include -#include -#include "alloc.h" -#include "case.h" -#include "casefile.h" -#include "command.h" -#include "dictionary.h" -#include "message.h" -#include "group-proc.h" -#include "hash.h" -#include "levene.h" -#include "lexer.h" -#include "magic.h" -#include "misc.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "size_max.h" -#include "manager.h" -#include "str.h" -#include "table.h" -#include "value-labels.h" -#include "variable.h" -#include "procedure.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -54,11 +60,11 @@ "T-TEST" (tts_): +groups=custom; testval=double; - variables=varlist("PV_NO_SCRATCH | PV_NUMERIC"); - pairs=custom; - +missing=miss:!analysis/listwise, - incl:include/!exclude; - format=fmt:!labels/nolabels; + +variables=varlist("PV_NO_SCRATCH | PV_NUMERIC"); + +pairs=custom; + missing=miss:!analysis/listwise, + incl:include/!exclude; + +format=fmt:!labels/nolabels; criteria=:cin(d:criteria,"%s > 0. && %s < 1."). */ /* (declarations) */ @@ -212,30 +218,33 @@ enum { }; -static int common_calc (const struct ccase *, void *); +static int common_calc (const struct dictionary *dict, + const struct ccase *, void *); static void common_precalc (struct cmd_t_test *); static void common_postcalc (struct cmd_t_test *); -static int one_sample_calc (const struct ccase *, void *); +static int one_sample_calc (const struct dictionary *dict, const struct ccase *, void *); static void one_sample_precalc (struct cmd_t_test *); static void one_sample_postcalc (struct cmd_t_test *); -static int paired_calc (const struct ccase *, void *); +static int paired_calc (const struct dictionary *dict, const struct ccase *, void *); static void paired_precalc (struct cmd_t_test *); static void paired_postcalc (struct cmd_t_test *); static void group_precalc (struct cmd_t_test *); -static int group_calc (const struct ccase *, struct cmd_t_test *); +static int group_calc (const struct dictionary *dict, const struct ccase *, struct cmd_t_test *); static void group_postcalc (struct cmd_t_test *); -static bool calculate(const struct casefile *cf, void *_mode); +static bool calculate(const struct ccase *first, + const struct casefile *cf, void *_mode, + const struct dataset *ds); static int mode; static struct cmd_t_test cmd; -static int bad_weight_warn; +static bool bad_weight_warn = false; static int compare_group_binary(const struct group_statistics *a, @@ -249,11 +258,11 @@ static unsigned hash_group_binary(const struct group_statistics *g, int -cmd_t_test(void) +cmd_t_test (struct dataset *ds) { bool ok; - if ( !parse_t_test(&cmd) ) + if ( !parse_t_test (ds, &cmd, NULL) ) return CMD_FAILURE; if (! cmd.sbc_criteria) @@ -336,9 +345,9 @@ cmd_t_test(void) else value_is_missing = mv_is_value_missing; - bad_weight_warn = 1; + bad_weight_warn = true; - ok = multipass_procedure_with_splits (calculate, &cmd); + ok = multipass_procedure_with_splits (ds, calculate, &cmd); n_pairs=0; free(pairs); @@ -360,13 +369,13 @@ cmd_t_test(void) } static int -tts_custom_groups (struct cmd_t_test *cmd UNUSED) +tts_custom_groups (struct dataset *ds, struct cmd_t_test *cmd UNUSED, void *aux UNUSED) { int n_group_values=0; lex_match('='); - indep_var = parse_variable (); + indep_var = parse_variable (dataset_dict (ds)); if (!indep_var) { lex_error ("expecting variable name in GROUPS subcommand"); @@ -439,7 +448,7 @@ tts_custom_groups (struct cmd_t_test *cmd UNUSED) static int -tts_custom_pairs (struct cmd_t_test *cmd UNUSED) +tts_custom_pairs (struct dataset *ds, struct cmd_t_test *cmd UNUSED, void *aux UNUSED) { struct variable **vars; size_t n_vars; @@ -452,7 +461,7 @@ tts_custom_pairs (struct cmd_t_test *cmd UNUSED) lex_match('='); n_vars=0; - if (!parse_variables (default_dict, &vars, &n_vars, + if (!parse_variables (dataset_dict (ds), &vars, &n_vars, PV_DUPLICATE | PV_NUMERIC | PV_NO_SCRATCH)) { free (vars); @@ -464,7 +473,7 @@ tts_custom_pairs (struct cmd_t_test *cmd UNUSED) if (lex_match (T_WITH)) { n_before_WITH = n_vars; - if (!parse_variables (default_dict, &vars, &n_vars, + if (!parse_variables (dataset_dict (ds), &vars, &n_vars, PV_DUPLICATE | PV_APPEND | PV_NUMERIC | PV_NO_SCRATCH)) { @@ -576,7 +585,7 @@ parse_value (union value * v, int type ) { if (!lex_force_string ()) return 0; - strncpy (v->s, ds_c_str (&tokstr), ds_length (&tokstr)); + strncpy (v->s, ds_cstr (&tokstr), ds_length (&tokstr)); } lex_get (); @@ -617,7 +626,7 @@ ssbox_create(struct ssbox *ssb, struct cmd_t_test *cmd, int mode) ssbox_paired_init(ssb,cmd); break; default: - assert(0); + NOT_REACHED (); } } @@ -676,7 +685,7 @@ ssbox_one_sample_init(struct ssbox *this, this->populate = ssbox_one_sample_populate; ssbox_base_init(this, hsize,vsize); - tab_title (this->t, 0, _("One-Sample Statistics")); + tab_title (this->t, _("One-Sample Statistics")); tab_vline(this->t, TAL_2, 1,0,vsize - 1); tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, _("N")); tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean")); @@ -698,8 +707,8 @@ ssbox_independent_samples_init(struct ssbox *this, this->populate = ssbox_independent_samples_populate; ssbox_base_init(this, hsize,vsize); - tab_title (this->t, 0, _("Group Statistics")); - tab_vline(this->t,0,1,0,vsize - 1); + tab_vline (this->t, TAL_GAP, 1, 0,vsize - 1); + tab_title (this->t, _("Group Statistics")); tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, indep_var->name); tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("N")); tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Mean")); @@ -822,8 +831,8 @@ ssbox_paired_init(struct ssbox *this, struct cmd_t_test *cmd UNUSED) this->populate = ssbox_paired_populate; ssbox_base_init(this, hsize,vsize); - tab_title (this->t, 0, _("Paired Sample Statistics")); - tab_vline(this->t,TAL_0,1,0,vsize-1); + tab_title (this->t, _("Paired Sample Statistics")); + tab_vline(this->t,TAL_GAP,1,0,vsize-1); tab_vline(this->t,TAL_2,2,0,vsize-1); tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean")); tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("N")); @@ -931,7 +940,7 @@ trbox_create(struct trbox *trb, trbox_paired_init(trb,cmd); break; default: - assert(0); + NOT_REACHED (); } } @@ -961,7 +970,7 @@ trbox_independent_samples_init(struct trbox *self, self->populate = trbox_independent_samples_populate; trbox_base_init(self,cmd->n_variables*2,hsize); - tab_title(self->t,0,_("Independent Samples Test")); + tab_title(self->t,_("Independent Samples Test")); tab_hline(self->t,TAL_1,2,hsize-1,1); tab_vline(self->t,TAL_2,2,0,vsize-1); tab_vline(self->t,TAL_1,4,0,vsize-1); @@ -1149,14 +1158,14 @@ trbox_paired_init(struct trbox *self, self->populate = trbox_paired_populate; trbox_base_init(self,n_pairs,hsize); - tab_title (self->t, 0, _("Paired Samples Test")); + tab_title (self->t, _("Paired Samples Test")); tab_hline(self->t,TAL_1,2,6,1); tab_vline(self->t,TAL_2,2,0,vsize - 1); tab_joint_text(self->t,2,0,6,0,TAB_CENTER,_("Paired Differences")); tab_box(self->t,-1,-1,-1,TAL_1, 2,1,6,vsize-1); tab_box(self->t,-1,-1,-1,TAL_1, 6,0,hsize-1,vsize-1); tab_hline(self->t,TAL_1,5,6, 2); - tab_vline(self->t,TAL_0,6,0,1); + tab_vline(self->t,TAL_GAP,6,0,1); tab_joint_text(self->t, 5, 1, 6, 1, TAB_CENTER | TAT_PRINTF, _("%g%% Confidence Interval of the Difference"), @@ -1243,7 +1252,7 @@ trbox_one_sample_init(struct trbox *self, struct cmd_t_test *cmd ) self->populate = trbox_one_sample_populate; trbox_base_init(self, cmd->n_variables,hsize); - tab_title (self->t, 0, _("One-Sample Test")); + tab_title (self->t, _("One-Sample Test")); tab_hline(self->t, TAL_1, 1, hsize - 1, 1); tab_vline(self->t, TAL_2, 1, 0, vsize - 1); @@ -1257,7 +1266,7 @@ trbox_one_sample_init(struct trbox *self, struct cmd_t_test *cmd ) _("%g%% Confidence Interval of the Difference"), cmd->criteria*100.0); - tab_vline(self->t,TAL_0,6,1,1); + tab_vline(self->t,TAL_GAP,6,1,1); tab_hline(self->t,TAL_1,5,6,2); tab_text (self->t, 1, 2, TAB_CENTER | TAT_TITLE, _("t")); tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("df")); @@ -1358,7 +1367,7 @@ pscbox(void) tab_hline(table, TAL_2, 0, cols - 1, 1); tab_vline(table, TAL_2, 2, 0, rows - 1); tab_dim(table, tab_natural_dimensions); - tab_title(table, 0, _("Paired Samples Correlations")); + tab_title(table, _("Paired Samples Correlations")); /* column headings */ tab_text(table, 2,0, TAB_CENTER | TAT_TITLE, _("N")); @@ -1404,12 +1413,12 @@ pscbox(void) /* Per case calculations common to all variants of the T test */ static int -common_calc (const struct ccase *c, void *_cmd) +common_calc (const struct dictionary *dict, const struct ccase *c, void *_cmd) { int i; struct cmd_t_test *cmd = (struct cmd_t_test *)_cmd; - double weight = dict_get_case_weight(default_dict,c,&bad_weight_warn); + double weight = dict_get_case_weight (dict, c, &bad_weight_warn); /* Skip the entire case if /MISSING=LISTWISE is set */ @@ -1503,13 +1512,14 @@ common_postcalc ( struct cmd_t_test *cmd ) /* Per case calculations for one sample t test */ static int -one_sample_calc (const struct ccase *c, void *cmd_) +one_sample_calc (const struct dictionary *dict, + const struct ccase *c, void *cmd_) { int i; struct cmd_t_test *cmd = (struct cmd_t_test *)cmd_; - double weight = dict_get_case_weight(default_dict,c,&bad_weight_warn); + double weight = dict_get_case_weight (dict, c, &bad_weight_warn); /* Skip the entire case if /MISSING=LISTWISE is set */ if ( cmd->miss == TTS_LISTWISE ) @@ -1593,13 +1603,13 @@ paired_precalc (struct cmd_t_test *cmd UNUSED) static int -paired_calc (const struct ccase *c, void *cmd_) +paired_calc (const struct dictionary *dict, const struct ccase *c, void *cmd_) { int i; struct cmd_t_test *cmd = (struct cmd_t_test *) cmd_; - double weight = dict_get_case_weight(default_dict,c,&bad_weight_warn); + double weight = dict_get_case_weight (dict, c, &bad_weight_warn); /* Skip the entire case if /MISSING=LISTWISE is set , AND one member of a pair is missing */ @@ -1738,13 +1748,15 @@ group_precalc (struct cmd_t_test *cmd ) } static int -group_calc (const struct ccase *c, struct cmd_t_test *cmd) +group_calc (const struct dictionary *dict, + const struct ccase *c, struct cmd_t_test *cmd) { int i; const union value *gv = case_data (c, indep_var->fv); - const double weight = dict_get_case_weight(default_dict,c,&bad_weight_warn); + const double weight = + dict_get_case_weight (dict, c, &bad_weight_warn); if ( value_is_missing(&indep_var->miss, gv) ) { @@ -1831,8 +1843,10 @@ group_postcalc ( struct cmd_t_test *cmd ) static bool -calculate(const struct casefile *cf, void *cmd_) +calculate(const struct ccase *first, const struct casefile *cf, + void *cmd_, const struct dataset *ds) { + const struct dictionary *dict = dataset_dict (ds); struct ssbox stat_summary_box; struct trbox test_results_box; @@ -1841,12 +1855,13 @@ calculate(const struct casefile *cf, void *cmd_) struct cmd_t_test *cmd = (struct cmd_t_test *) cmd_; + output_split_file_values (ds, first); common_precalc(cmd); for(r = casefile_get_reader (cf); casereader_read (r, &c) ; case_destroy (&c)) { - common_calc(&c,cmd); + common_calc(dict, &c,cmd); } casereader_destroy (r); common_postcalc(cmd); @@ -1859,7 +1874,7 @@ calculate(const struct casefile *cf, void *cmd_) casereader_read (r, &c) ; case_destroy (&c)) { - one_sample_calc(&c,cmd); + one_sample_calc (dict, &c,cmd); } casereader_destroy (r); one_sample_postcalc(cmd); @@ -1871,10 +1886,10 @@ calculate(const struct casefile *cf, void *cmd_) casereader_read (r, &c) ; case_destroy (&c)) { - paired_calc(&c,cmd); + paired_calc (dict, &c,cmd); } casereader_destroy (r); - paired_postcalc(cmd); + paired_postcalc (cmd); break; case T_IND_SAMPLES: @@ -1884,12 +1899,12 @@ calculate(const struct casefile *cf, void *cmd_) casereader_read (r, &c) ; case_destroy (&c)) { - group_calc(&c,cmd); + group_calc (dict, &c, cmd); } casereader_destroy (r); group_postcalc(cmd); - levene(cf, indep_var, cmd->n_variables, cmd->v_variables, + levene (dict, cf, indep_var, cmd->n_variables, cmd->v_variables, (cmd->miss == TTS_LISTWISE)?LEV_LISTWISE:LEV_ANALYSIS , value_is_missing); break; @@ -1963,7 +1978,7 @@ hash_group_binary(const struct group_statistics *g, flag = which_group(g,p); } else - assert(0); + NOT_REACHED (); return flag; }