X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Ft-test.q;h=c2fc85d7f774bdf5308cd458f5684efc65518536;hb=d69833d7d425cd98c3793a89945153306dfa7ab3;hp=839d0dc8fa323abd6acbfbb99258a2bd7ce8c96c;hpb=e91248ddc41199bda0676817debf080c2b7835a1;p=pspp-builds.git diff --git a/src/t-test.q b/src/t-test.q index 839d0dc8..c2fc85d7 100644 --- a/src/t-test.q +++ b/src/t-test.q @@ -55,6 +55,7 @@ static struct cmd_t_test cmd; + static struct pool *t_test_pool ; /* Variable for the GROUPS subcommand, if given. */ @@ -98,6 +99,9 @@ void ssbox_populate(struct ssbox *ssb, struct cmd_t_test *cmd); /* Submit and destroy a ssbox */ void ssbox_finalize(struct ssbox *ssb); +/* A function to create, populate and submit the Paired Samples Correlation + box */ +void pscbox(struct cmd_t_test *cmd); /* Structures and Functions for the Test Results Box */ @@ -129,6 +133,16 @@ enum { T_PAIRED }; + +static int common_calc (struct ccase *); +static void common_precalc (void); +static void common_postcalc (void); + +static int one_sample_calc (struct ccase *); +static void one_sample_precalc (void); +static void one_sample_postcalc (void); + + int cmd_t_test(void) { @@ -137,7 +151,6 @@ cmd_t_test(void) struct ssbox stat_summary_box; struct trbox test_results_box; - if (!lex_force_match_id ("T")) return CMD_FAILURE; @@ -147,11 +160,9 @@ cmd_t_test(void) if ( !parse_t_test(&cmd) ) return CMD_FAILURE; - if (! cmd.sbc_criteria) cmd.criteria=0.95; - if ( cmd.sbc_testval + cmd.sbc_groups + cmd.sbc_pairs != 1 ) { msg(SE, @@ -173,28 +184,33 @@ cmd_t_test(void) return CMD_FAILURE; } + procedure(common_precalc,common_calc,common_postcalc); + if (mode == T_1_SAMPLE) + procedure(one_sample_precalc,one_sample_calc,one_sample_postcalc); t_test_pool = pool_create (); ssbox_create(&stat_summary_box,&cmd,mode); - trbox_create(&test_results_box,&cmd,mode); - ssbox_populate(&stat_summary_box,&cmd); - trbox_populate(&test_results_box,&cmd); - ssbox_finalize(&stat_summary_box); + + if ( mode == T_PAIRED) + { + pscbox(&cmd); + } + + trbox_create(&test_results_box,&cmd,mode); + trbox_populate(&test_results_box,&cmd); trbox_finalize(&test_results_box); pool_destroy (t_test_pool); t_test_pool=0; - return CMD_SUCCESS; } - static int tts_custom_groups (struct cmd_t_test *cmd unused) { @@ -224,7 +240,6 @@ tts_custom_groups (struct cmd_t_test *cmd unused) if (!lex_match ('(')) { - if (groups->type == NUMERIC) { n_groups_values = 2; @@ -245,7 +260,6 @@ tts_custom_groups (struct cmd_t_test *cmd unused) n_groups_values = 1; lex_match (','); - if (lex_match (')')) return 1; @@ -259,13 +273,17 @@ tts_custom_groups (struct cmd_t_test *cmd unused) return 1; } + + + static int tts_custom_pairs (struct cmd_t_test *cmd unused) { struct variable **vars; int n_vars; + int n_before_WITH ; - int n_after_WITH =-1; + int n_after_WITH = -1; int paired ; /* Was the PAIRED keyword given ? */ lex_match('='); @@ -284,15 +302,12 @@ tts_custom_pairs (struct cmd_t_test *cmd unused) free (vars); return 0; } - - assert (n_vars); n_before_WITH=0; if (lex_match (T_WITH)) { n_before_WITH = n_vars; - if (!parse_variables (default_dict, &vars, &n_vars, PV_DUPLICATE | PV_APPEND | PV_NUMERIC | PV_NO_SCRATCH)) @@ -300,16 +315,12 @@ tts_custom_pairs (struct cmd_t_test *cmd unused) free (vars); return 0; } - n_after_WITH = n_vars - n_before_WITH; } - paired = (lex_match ('(') && lex_match_id ("PAIRED") && lex_match (')')); - /* Determine the number of pairs needed */ - if (paired) { if (n_before_WITH != n_after_WITH) @@ -321,9 +332,7 @@ tts_custom_pairs (struct cmd_t_test *cmd unused) n_before_WITH, n_after_WITH ); return 0; } - n_pairs=n_before_WITH; - } else if (n_before_WITH > 0) /* WITH keyword given, but not PAIRED keyword */ { @@ -344,12 +353,9 @@ tts_custom_pairs (struct cmd_t_test *cmd unused) } /* Allocate storage for the pairs */ - pairs = xrealloc(pairs,sizeof(pair_t) *n_pairs); - /* Populate the pairs with the appropriate variables */ - if ( paired ) { int i; @@ -395,7 +401,6 @@ tts_custom_pairs (struct cmd_t_test *cmd unused) return 1; } - /* Parses the current token (numeric or string, depending on type) value v and returns success. */ static int @@ -420,12 +425,7 @@ parse_value (union value * v, int type ) } -/* ******************************************************************* - SSBOX Implementation - - ***************************************************************** */ - - +/* Implementation of the SSBOX object */ void ssbox_base_init(struct ssbox *this, int cols,int rows); @@ -444,7 +444,6 @@ void ssbox_paired_init(struct ssbox *this, void ssbox_create(struct ssbox *ssb, struct cmd_t_test *cmd, int mode) { - switch (mode) { case T_1_SAMPLE: @@ -459,10 +458,10 @@ ssbox_create(struct ssbox *ssb, struct cmd_t_test *cmd, int mode) default: assert(0); } - } +/* Despatcher for the populate method */ void ssbox_populate(struct ssbox *ssb,struct cmd_t_test *cmd) { @@ -470,6 +469,7 @@ ssbox_populate(struct ssbox *ssb,struct cmd_t_test *cmd) } +/* Despatcher for finalize */ void ssbox_finalize(struct ssbox *ssb) { @@ -477,14 +477,14 @@ ssbox_finalize(struct ssbox *ssb) } - +/* Submit the box and clear up */ void ssbox_base_finalize(struct ssbox *ssb) { tab_submit(ssb->t); } - +/* Initialize a ssbox struct */ void ssbox_base_init(struct ssbox *this, int cols,int rows) { @@ -492,24 +492,16 @@ ssbox_base_init(struct ssbox *this, int cols,int rows) this->t = tab_create (cols, rows, 0); tab_columns (this->t, SOM_COL_DOWN, 1); - tab_headers (this->t,0,0,1,0); - tab_box (this->t, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, cols -1, rows -1 ); - tab_hline(this->t, TAL_2,0,cols-1,1); - tab_dim (this->t, tab_natural_dimensions); - } - - void ssbox_one_sample_populate(struct ssbox *ssb, struct cmd_t_test *cmd); - - +/* Initialize the one_sample ssbox */ void ssbox_one_sample_init(struct ssbox *this, struct cmd_t_test *cmd ) @@ -520,29 +512,21 @@ 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_vline(this->t, TAL_2, 1,0,vsize); - tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, _("N")); tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("Mean")); tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation")); tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean")); - - } - void ssbox_independent_samples_populate(struct ssbox *ssb, struct cmd_t_test *cmd); - +/* Initialize the independent samples ssbox */ void ssbox_independent_samples_init(struct ssbox *this, struct cmd_t_test *cmd) - { int hsize=6; int vsize = cmd->n_variables*2 +1; @@ -550,22 +534,17 @@ 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); - tab_text (this->t, 1, 0, TAB_CENTER | TAT_TITLE, groups->name); - tab_text (this->t, 2, 0, TAB_CENTER | TAT_TITLE, _("N")); tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Mean")); tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation")); tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean")); - - } +/* Populate the ssbox for independent samples */ void ssbox_independent_samples_populate(struct ssbox *ssb, struct cmd_t_test *cmd) @@ -586,42 +565,31 @@ ssbox_independent_samples_populate(struct ssbox *ssb, val_lab2 = groups_values[1].s; } - assert(ssb->t); for (i=0; i < cmd->n_variables; ++i) { - tab_text (ssb->t, 0, i*2+1, - TAB_LEFT, cmd->v_variables[i]->name); + tab_text (ssb->t, 0, i*2+1, TAB_LEFT, cmd->v_variables[i]->name); if (val_lab1) - tab_text (ssb->t, 1, i*2+1, - TAB_LEFT, val_lab1); + tab_text (ssb->t, 1, i*2+1, TAB_LEFT, val_lab1); else - tab_float(ssb->t, 1 ,i*2+1, - TAB_LEFT, groups_values[0].f, 2,0); - + tab_float(ssb->t, 1 ,i*2+1, TAB_LEFT, groups_values[0].f, 2,0); if (val_lab2) - tab_text (ssb->t, 1, i*2+1+1, - TAB_LEFT, val_lab2); + tab_text (ssb->t, 1, i*2+1+1, TAB_LEFT, val_lab2); else - tab_float(ssb->t, 1 ,i*2+1+1, - TAB_LEFT, groups_values[1].f,2,0); - - + tab_float(ssb->t, 1 ,i*2+1+1, TAB_LEFT, groups_values[1].f,2,0); } - } void ssbox_paired_populate(struct ssbox *ssb, struct cmd_t_test *cmd); - +/* Initialize the paired values ssbox */ void -ssbox_paired_init(struct ssbox *this, - struct cmd_t_test *cmd unused) +ssbox_paired_init(struct ssbox *this, struct cmd_t_test *cmd unused) { int hsize=6; @@ -630,42 +598,33 @@ ssbox_paired_init(struct ssbox *this, 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_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")); tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation")); tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("SE. Mean")); - - } +/* Populate the ssbox for paired values */ void -ssbox_paired_populate(struct ssbox *ssb, - struct cmd_t_test *cmd unused) +ssbox_paired_populate(struct ssbox *ssb,struct cmd_t_test *cmd unused) { int i; struct string ds; assert(ssb->t); - ds_init(t_test_pool,&ds,15); - for (i=0; i < n_pairs; ++i) { - ds_clear(&ds); ds_printf(&ds,_("Pair %d"),i); tab_text (ssb->t, 0, i*2+1, TAB_LEFT, ds.string); - tab_text (ssb->t, 1, i*2+1, TAB_LEFT, pairs[i][0]->name); tab_text (ssb->t, 1, i*2+2, TAB_LEFT, pairs[i][1]->name); } @@ -673,10 +632,9 @@ ssbox_paired_populate(struct ssbox *ssb, ds_destroy(&ds); } - +/* Populate the one sample ssbox */ void -ssbox_one_sample_populate(struct ssbox *ssb, - struct cmd_t_test *cmd) +ssbox_one_sample_populate(struct ssbox *ssb, struct cmd_t_test *cmd) { int i; @@ -684,18 +642,21 @@ ssbox_one_sample_populate(struct ssbox *ssb, for (i=0; i < cmd->n_variables; ++i) { - tab_text (ssb->t, 0, i+1, - TAB_LEFT, cmd->v_variables[i]->name); + struct t_test_proc *ttp; + ttp= &cmd->v_variables[i]->p.t_t; + + tab_text (ssb->t, 0, i+1, TAB_LEFT, cmd->v_variables[i]->name); + tab_float (ssb->t,1, i+1, TAB_RIGHT, ttp->n, 2, 0); + tab_float (ssb->t,2, i+1, TAB_RIGHT, ttp->mean, 8, 2); + tab_float (ssb->t,3, i+1, TAB_RIGHT, ttp->std_dev, 8, 2); + tab_float (ssb->t,4, i+1, TAB_RIGHT, ttp->se_mean, 8, 3); } } -/* **************************************************************** - TEST RESULT BOX Implementation - - *****************************************************************/ +/* Implementation of the Test Results box struct */ void trbox_base_init(struct trbox *self,int n_vars, int cols); void trbox_base_finalize(struct trbox *trb); @@ -720,32 +681,25 @@ void trbox_paired_populate(struct trbox *trb, -/* Create a trbox */ +/* Create a trbox according to mode*/ void trbox_create(struct trbox *trb, struct cmd_t_test *cmd, int mode) { - switch (mode) { case T_1_SAMPLE: trbox_one_sample_init(trb,cmd); break; - - case T_IND_SAMPLES: trbox_independent_samples_init(trb,cmd); break; - - case T_PAIRED: trbox_paired_init(trb,cmd); break; - default: assert(0); } - } /* Populate a trbox according to cmd */ @@ -762,7 +716,7 @@ trbox_finalize(struct trbox *trb) trb->finalize(trb); } - +/* Initialize the independent samples trbox */ void trbox_independent_samples_init(struct trbox *self, struct cmd_t_test *cmd unused) @@ -773,36 +727,21 @@ trbox_independent_samples_init(struct trbox *self, struct string ds; assert(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_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); - - tab_box(self->t,-1,-1,-1,TAL_1, - 2,1,hsize-2,vsize-1); - - - tab_hline(self->t,TAL_1, - hsize-2,hsize-1,2); - - tab_box(self->t,-1,-1,-1,TAL_1, - hsize-2,2,hsize-1,vsize-1); - - - tab_joint_text(self->t, 2,0,3,0, + tab_box(self->t,-1,-1,-1,TAL_1, 2,1,hsize-2,vsize-1); + tab_hline(self->t,TAL_1, hsize-2,hsize-1,2); + tab_box(self->t,-1,-1,-1,TAL_1, hsize-2,2,hsize-1,vsize-1); + tab_joint_text(self->t, 2, 0, 3, 0, TAB_CENTER,_("Levine's Test for Equality of Variances")); - tab_joint_text(self->t, 4,0,hsize-1,0, TAB_CENTER,_("t-test for Equality of Means")); - tab_text(self->t,2,2, TAB_CENTER | TAT_TITLE,_("F")); tab_text(self->t,3,2, TAB_CENTER | TAT_TITLE,_("Sig.")); tab_text(self->t,4,2, TAB_CENTER | TAT_TITLE,_("t")); @@ -813,47 +752,36 @@ trbox_independent_samples_init(struct trbox *self, tab_text(self->t,9,2, TAB_CENTER | TAT_TITLE,_("Lower")); tab_text(self->t,10,2, TAB_CENTER | TAT_TITLE,_("Upper")); - ds_init(t_test_pool,&ds,80); ds_printf(&ds,_("%d%% Confidence Interval of the Difference"), (int)round(cmd->criteria*100.0)); - tab_joint_text(self->t,9,1,10,1,TAB_CENTER, - ds.string); - + tab_joint_text(self->t,9,1,10,1,TAB_CENTER, ds.string); ds_destroy(&ds); - - - } +/* Populate the independent samples trbox */ void trbox_independent_samples_populate(struct trbox *self, - struct cmd_t_test *cmd ) + struct cmd_t_test *cmd ) { int i; assert(self); - for (i=0; i < cmd->n_variables; ++i) { - tab_text (self->t, 0, i*2+3, - TAB_LEFT, cmd->v_variables[i]->name); + tab_text (self->t, 0, i*2+3, TAB_LEFT, cmd->v_variables[i]->name); - tab_text (self->t, 1, i*2+3, - TAB_LEFT, _("Equal variances assumed")); + tab_text (self->t, 1, i*2+3, TAB_LEFT, _("Equal variances assumed")); tab_text (self->t, 1, i*2+3+1, TAB_LEFT, _("Equal variances not assumed")); - - } - } - +/* Initialize the paired samples trbox */ void trbox_paired_init(struct trbox *self, struct cmd_t_test *cmd unused) @@ -867,40 +795,21 @@ trbox_paired_init(struct trbox *self, self->populate = trbox_paired_populate; trbox_base_init(self,n_pairs*2,hsize); - - tab_title (self->t, 0, _("Paired Samples Test")); - - tab_hline(self->t,TAL_1,2,6,1); tab_vline(self->t,TAL_2,2,0,vsize); - - - 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_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); - ds_init(t_test_pool,&ds,80); ds_printf(&ds,_("%d%% Confidence Interval of the Difference"), (int)round(cmd->criteria*100.0)); - tab_joint_text(self->t,5,1,6,1,TAB_CENTER, - ds.string); - + tab_joint_text(self->t,5,1,6,1,TAB_CENTER, ds.string); ds_destroy(&ds); @@ -912,16 +821,9 @@ trbox_paired_init(struct trbox *self, tab_text (self->t, 7, 2, TAB_CENTER | TAT_TITLE, _("t")); tab_text (self->t, 8, 2, TAB_CENTER | TAT_TITLE, _("df")); tab_text (self->t, 9, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)")); - - - - - - - } - +/* Populate the paired samples trbox */ void trbox_paired_populate(struct trbox *trb, struct cmd_t_test *cmd unused) @@ -929,31 +831,23 @@ trbox_paired_populate(struct trbox *trb, int i; struct string ds; - ds_init(t_test_pool,&ds,15); for (i=0; i < n_pairs; ++i) { - ds_clear(&ds); - ds_printf(&ds,_("Pair %d"),i); tab_text (trb->t, 0, i*2+3, TAB_LEFT, ds.string); - tab_text (trb->t, 1, i*2+3, TAB_LEFT, pairs[i][0]->name); tab_text (trb->t, 1, i*2+4, TAB_LEFT, pairs[i][1]->name); } - - ds_destroy(&ds); - } - +/* Initialize the one sample trbox */ void -trbox_one_sample_init(struct trbox *self, - struct cmd_t_test *cmd ) +trbox_one_sample_init(struct trbox *self, struct cmd_t_test *cmd ) { const int hsize=7; const int vsize=cmd->n_variables+3; @@ -962,38 +856,22 @@ trbox_one_sample_init(struct trbox *self, self->populate = trbox_one_sample_populate; - trbox_base_init(self,cmd->n_variables,hsize); - - + trbox_base_init(self, cmd->n_variables,hsize); tab_title (self->t, 0, _("One-Sample Test")); - - tab_hline(self->t,TAL_1,1,hsize-1,1); - tab_vline(self->t,TAL_2,1,0,vsize); - - ds_init(t_test_pool,&ds,80); - + tab_hline(self->t, TAL_1, 1, hsize - 1, 1); + tab_vline(self->t, TAL_2, 1, 0, vsize); + ds_init(t_test_pool, &ds, 80); ds_printf(&ds,_("Test Value = %f"),cmd->n_testval); - - tab_joint_text(self->t,1,0,hsize-1,0,TAB_CENTER,ds.string); - - tab_box(self->t,-1,-1,-1,TAL_1, - 1,1,hsize-1,vsize-1); - + tab_joint_text(self->t, 1, 0, hsize-1,0, TAB_CENTER,ds.string); + tab_box(self->t, -1, -1, -1, TAL_1, 1,1,hsize-1,vsize-1); ds_clear(&ds); - ds_printf(&ds,_("%d%% Confidence Interval of the Difference"), (int)round(cmd->criteria*100.0)); - - tab_joint_text(self->t,5,1,6,1,TAB_CENTER, - ds.string); - + tab_joint_text(self->t,5,1,6,1,TAB_CENTER, ds.string); ds_destroy(&ds); - tab_vline(self->t,TAL_0,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")); tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Sig. (2-tailed)")); @@ -1001,14 +879,12 @@ trbox_one_sample_init(struct trbox *self, tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower")); tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper")); - } - +/* Populate the one sample trbox */ void -trbox_one_sample_populate(struct trbox *trb, - struct cmd_t_test *cmd) +trbox_one_sample_populate(struct trbox *trb, struct cmd_t_test *cmd) { int i; @@ -1016,36 +892,251 @@ trbox_one_sample_populate(struct trbox *trb, for (i=0; i < cmd->n_variables; ++i) { - tab_text (trb->t, 0, i+3, - TAB_LEFT, cmd->v_variables[i]->name); + int which =1; + double t; + double p,q; + double df; + int status; + double bound; + struct t_test_proc *ttp; + ttp= &cmd->v_variables[i]->p.t_t; + + + tab_text (trb->t, 0, i+3, TAB_LEFT, cmd->v_variables[i]->name); + + t = (ttp->mean - cmd->n_testval ) * sqrt(ttp->n) / ttp->std_dev ; + + tab_float (trb->t, 1, i+3, TAB_RIGHT, t, 8,3); + + /* degrees of freedom */ + df = ttp->n - 1; + + tab_float (trb->t, 2, i+3, TAB_RIGHT, df, 8,0); + + cdft(&which, &p, &q, &t, &df, &status, &bound); + + if ( 0 != status ) + { + msg( SE, _("Error calculating T statistic (cdft returned %d)."),status); + } + + + /* Multiply by 2 to get 2-tailed significance */ + tab_float (trb->t, 3, i+3, TAB_RIGHT, q*2.0, 8,3); + + tab_float (trb->t, 4, i+3, TAB_RIGHT, ttp->mean_diff, 8,3); + + + q = (1 - cmd->criteria)/2.0; /* 2-tailed test */ + p = 1 - q ; + which=2; /* Calc T from p,q and df */ + cdft(&which, &p, &q, &t, &df, &status, &bound); + if ( 0 != status ) + { + msg( SE, _("Error calculating T statistic (cdft returned %d)."),status); + } + + tab_float (trb->t, 5, i+3, TAB_RIGHT, + ttp->mean_diff - t * ttp->se_mean, 8,4); + + tab_float (trb->t, 6, i+3, TAB_RIGHT, + ttp->mean_diff + t * ttp->se_mean, 8,4); } - } - +/* Base initializer for the generalized trbox */ void -trbox_base_init(struct trbox *self, int data_rows,int cols) +trbox_base_init(struct trbox *self, int data_rows, int cols) { - const int rows=3+data_rows; + const int rows = 3 + data_rows; self->finalize = trbox_base_finalize; self->t = tab_create (cols, rows, 0); + tab_headers (self->t,0,0,3,0); + tab_box (self->t, TAL_2, TAL_2, TAL_0, TAL_0, 0, 0, cols -1, rows -1); + tab_hline(self->t, TAL_2,0,cols-1,3); + tab_dim (self->t, tab_natural_dimensions); +} - tab_headers (self->t,0,0,3,0); +/* Base finalizer for the trbox */ +void +trbox_base_finalize(struct trbox *trb) +{ + tab_submit(trb->t); +} - tab_box (self->t, TAL_2, TAL_2, TAL_0, TAL_0, 0, 0, cols -1, rows -1); +/* Create , populate and submit the Paired Samples Correlation box */ +void +pscbox(struct cmd_t_test *cmd) +{ + const int rows=1+n_pairs; + const int cols=5; + int i; + + struct tab_table *table; + + table = tab_create (cols,rows,0); + + tab_columns (table, SOM_COL_DOWN, 1); + tab_headers (table,0,0,1,0); + tab_box (table, TAL_2, TAL_2, TAL_0, TAL_1, 0, 0, cols -1, rows -1 ); + 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")); + + /* column headings */ + tab_text(table, 2,0, TAB_CENTER | TAT_TITLE, _("N")); + tab_text(table, 3,0, TAB_CENTER | TAT_TITLE, _("Correlation")); + tab_text(table, 4,0, TAB_CENTER | TAT_TITLE, _("Sig.")); + + /* row headings */ + { + struct string ds; - tab_hline(self->t, TAL_2,0,cols-1,3); + ds_init(t_test_pool,&ds,15); - tab_dim (self->t, tab_natural_dimensions); + for (i=0; i < n_pairs; ++i) + { + ds_clear(&ds); + ds_printf(&ds,_("Pair %d"),i); + tab_text(table, 0,i+1, TAB_LEFT | TAT_TITLE, ds.string); + + ds_clear(&ds); + ds_printf(&ds,_("%s & %s"),pairs[i][0]->name,pairs[i][1]->name); + tab_text(table, 1,i+1, TAB_LEFT | TAT_TITLE, ds.string); + } + + ds_destroy(&ds); + } + + tab_submit(table); } + +/* Calculation Implementation */ + +/* Per case calculations common to all variants of the T test */ +static int +common_calc (struct ccase *c) +{ + int i; + + double weight = dict_get_case_weight(default_dict,c); + + for(i=0; i< cmd.n_variables ; ++i) + { + struct t_test_proc *ttp; + struct variable *v = cmd.v_variables[i]; + union value *val = &c->data[v->fv]; + + ttp= &cmd.v_variables[i]->p.t_t; + + if (val->f != SYSMIS) + { + ttp->n+=weight; + ttp->sum+=weight * val->f; + ttp->ssq+=weight * val->f * val->f; + } + } + return 0; +} + +/* Pre calculations common to all variants of the T test */ +static void +common_precalc (void) +{ + int i=0; + + for(i=0; i< cmd.n_variables ; ++i) + { + struct t_test_proc *ttp; + ttp= &cmd.v_variables[i]->p.t_t; + + ttp->sum=0; + ttp->n=0; + ttp->ssq=0; + ttp->sum_diff=0; + } +} + +/* Post calculations common to all variants of the T test */ void -trbox_base_finalize(struct trbox *trb) +common_postcalc (void) { - tab_submit(trb->t); + int i=0; + + for(i=0; i< cmd.n_variables ; ++i) + { + struct t_test_proc *ttp; + ttp= &cmd.v_variables[i]->p.t_t; + + ttp->mean=ttp->sum / ttp->n; + ttp->std_dev= sqrt( + ttp->n/(ttp->n-1) * + ( (ttp->ssq / ttp->n ) - ttp->mean * ttp->mean ) + ) ; + + ttp->se_mean = ttp->std_dev / sqrt(ttp->n); + + ttp->mean_diff= ttp->sum_diff / ttp->n; + } +} + +/* Per case calculations for one sample t test */ +static int +one_sample_calc (struct ccase *c) +{ + int i; + + double weight = dict_get_case_weight(default_dict,c); + + for(i=0; i< cmd.n_variables ; ++i) + { + struct t_test_proc *ttp; + struct variable *v = cmd.v_variables[i]; + union value *val = &c->data[v->fv]; + + ttp= &cmd.v_variables[i]->p.t_t; + + if (val->f != SYSMIS) + ttp->sum_diff += weight * (val->f - cmd.n_testval); + } + + return 0; +} + +/* Pre calculations for one sample t test */ +static void +one_sample_precalc (void) +{ + int i=0; + + for(i=0; i< cmd.n_variables ; ++i) + { + struct t_test_proc *ttp; + ttp= &cmd.v_variables[i]->p.t_t; + + ttp->sum_diff=0; + } +} + +/* Post calculations for one sample t test */ +static void +one_sample_postcalc (void) +{ + int i=0; + + for(i=0; i< cmd.n_variables ; ++i) + { + struct t_test_proc *ttp; + ttp= &cmd.v_variables[i]->p.t_t; + + + ttp->mean_diff = ttp->sum_diff / ttp->n ; + } }