+/* Populate the ssbox for independent samples */
+void
+ssbox_independent_samples_populate(struct ssbox *ssb,
+ struct cmd_t_test *cmd)
+{
+ int i;
+
+ char *val_lab0=0;
+ char *val_lab1=0;
+ double indep_value[2];
+
+ char prefix[2][3]={"",""};
+
+ if ( indep_var->type == NUMERIC )
+ {
+ val_lab0 = val_labs_find( indep_var->val_labs,gp.v.g_value[0]);
+ val_lab1 = val_labs_find( indep_var->val_labs,gp.v.g_value[1]);
+ }
+ else
+ {
+ val_lab0 = gp.v.g_value[0].s;
+ val_lab1 = gp.v.g_value[1].s;
+ }
+
+ if (gp.criterion == CMP_LE )
+ {
+ strcpy(prefix[0],"< ");
+ strcpy(prefix[1],">=");
+ indep_value[0] = gp.v.critical_value;
+ indep_value[1] = gp.v.critical_value;
+ }
+ else
+ {
+ indep_value[0] = gp.v.g_value[0].f;
+ indep_value[1] = gp.v.g_value[1].f;
+ }
+
+ assert(ssb->t);
+
+ for (i=0; i < cmd->n_variables; ++i)
+ {
+ struct variable *var = cmd->v_variables[i];
+ struct hsh_table *grp_hash = group_proc_get (var)->group_hash;
+ int count=0;
+
+ tab_text (ssb->t, 0, i*2+1, TAB_LEFT, cmd->v_variables[i]->name);
+
+ if (val_lab0)
+ tab_text (ssb->t, 1, i*2+1, TAB_LEFT | TAT_PRINTF,
+ "%s%s", prefix[0], val_lab0);
+ else
+ tab_text (ssb->t, 1, i*2+1, TAB_LEFT | TAT_PRINTF,
+ "%s%g", prefix[0], indep_value[0]);
+
+
+ if (val_lab1)
+ tab_text (ssb->t, 1, i*2+1+1, TAB_LEFT | TAT_PRINTF,
+ "%s%s", prefix[1], val_lab1);
+ else
+ tab_text (ssb->t, 1, i*2+1+1, TAB_LEFT | TAT_PRINTF,
+ "%s%g", prefix[1], indep_value[1]);
+
+
+ /* Fill in the group statistics */
+ for ( count = 0 ; count < 2 ; ++count )
+ {
+ union value search_val;
+
+ struct group_statistics *gs;
+
+ if ( gp.criterion == CMP_LE )
+ {
+ if ( count == 0 )
+ {
+ /* less than ( < ) case */
+ search_val.f = gp.v.critical_value - 1.0;
+ }
+ else
+ {
+ /* >= case */
+ search_val.f = gp.v.critical_value + 1.0;
+ }
+ }
+ else
+ {
+ search_val = gp.v.g_value[count];
+ }
+
+ gs = hsh_find(grp_hash, (void *) &search_val);
+ assert(gs);
+
+ tab_float(ssb->t, 2 ,i*2+count+1, TAB_RIGHT, gs->n, 2, 0);
+ tab_float(ssb->t, 3 ,i*2+count+1, TAB_RIGHT, gs->mean, 8, 2);
+ tab_float(ssb->t, 4 ,i*2+count+1, TAB_RIGHT, gs->std_dev, 8, 3);
+ tab_float(ssb->t, 5 ,i*2+count+1, TAB_RIGHT, gs->se_mean, 8, 3);
+ }
+ }
+}
+
+
+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)
+{
+ int hsize=6;
+
+ int vsize = n_pairs*2+1;
+
+ 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)
+{
+ int i;
+
+ assert(ssb->t);
+
+ for (i=0; i < n_pairs; ++i)
+ {
+ int j;
+
+ tab_text (ssb->t, 0, i*2+1, TAB_LEFT | TAT_PRINTF , _("Pair %d"),i);
+
+ for (j=0 ; j < 2 ; ++j)
+ {
+ struct group_statistics *gs;
+
+ gs = &group_proc_get (pairs[i].v[j])->ugs;
+
+ /* Titles */
+
+ tab_text (ssb->t, 1, i*2+j+1, TAB_LEFT, pairs[i].v[j]->name);
+
+ /* Values */
+ tab_float (ssb->t,2, i*2+j+1, TAB_RIGHT, pairs[i].mean[j], 8, 2);
+ tab_float (ssb->t,3, i*2+j+1, TAB_RIGHT, pairs[i].n, 2, 0);
+ tab_float (ssb->t,4, i*2+j+1, TAB_RIGHT, pairs[i].std_dev[j], 8, 3);
+ tab_float (ssb->t,5, i*2+j+1, TAB_RIGHT, pairs[i].std_dev[j]/sqrt(pairs[i].n), 8, 3);
+
+ }
+ }
+}
+
+/* Populate the one sample ssbox */
+void
+ssbox_one_sample_populate(struct ssbox *ssb, struct cmd_t_test *cmd)
+{
+ int i;
+
+ assert(ssb->t);
+
+ for (i=0; i < cmd->n_variables; ++i)
+ {
+ struct group_statistics *gs = &group_proc_get (cmd->v_variables[i])->ugs;
+
+ tab_text (ssb->t, 0, i+1, TAB_LEFT, cmd->v_variables[i]->name);
+ tab_float (ssb->t,1, i+1, TAB_RIGHT, gs->n, 2, 0);
+ tab_float (ssb->t,2, i+1, TAB_RIGHT, gs->mean, 8, 2);
+ tab_float (ssb->t,3, i+1, TAB_RIGHT, gs->std_dev, 8, 2);
+ tab_float (ssb->t,4, i+1, TAB_RIGHT, gs->se_mean, 8, 3);
+ }
+
+}
+
+
+
+/* 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);
+
+void trbox_independent_samples_init(struct trbox *trb,
+ struct cmd_t_test *cmd );
+
+void trbox_independent_samples_populate(struct trbox *trb,
+ struct cmd_t_test *cmd);
+
+void trbox_one_sample_init(struct trbox *self,
+ struct cmd_t_test *cmd );
+
+void trbox_one_sample_populate(struct trbox *trb,
+ struct cmd_t_test *cmd);
+
+void trbox_paired_init(struct trbox *self,
+ struct cmd_t_test *cmd );
+
+void trbox_paired_populate(struct trbox *trb,
+ struct cmd_t_test *cmd);
+
+
+
+/* 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 */
+void
+trbox_populate(struct trbox *trb, struct cmd_t_test *cmd)
+{
+ trb->populate(trb,cmd);
+}
+
+/* Submit and destroy a trbox */
+void
+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)
+{
+ const int hsize=11;
+ const int vsize=cmd->n_variables*2+3;
+
+ 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_CENTER,_("Levene'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"));
+ tab_text(self->t,5,2, TAB_CENTER | TAT_TITLE,_("df"));
+ tab_text(self->t,6,2, TAB_CENTER | TAT_TITLE,_("Sig. (2-tailed)"));
+ tab_text(self->t,7,2, TAB_CENTER | TAT_TITLE,_("Mean Difference"));
+ tab_text(self->t,8,2, TAB_CENTER | TAT_TITLE,_("Std. Error Difference"));
+ tab_text(self->t,9,2, TAB_CENTER | TAT_TITLE,_("Lower"));
+ tab_text(self->t,10,2, TAB_CENTER | TAT_TITLE,_("Upper"));
+
+ tab_joint_text(self->t, 9, 1, 10, 1, TAB_CENTER | TAT_PRINTF,
+ _("%g%% Confidence Interval of the Difference"),
+ cmd->criteria*100.0);
+
+}
+
+/* Populate the independent samples trbox */
+void
+trbox_independent_samples_populate(struct trbox *self,
+ struct cmd_t_test *cmd )
+{
+ int i;
+
+ assert(self);
+ for (i=0; i < cmd->n_variables; ++i)
+ {
+ double p,q;
+
+ double t;
+ double df;
+
+ double df1, df2;
+
+ double pooled_variance;
+ double std_err_diff;
+ double mean_diff;
+
+ struct variable *var = cmd->v_variables[i];
+ struct group_proc *grp_data = group_proc_get (var);
+
+ struct hsh_table *grp_hash = grp_data->group_hash;
+
+ struct group_statistics *gs0 ;
+ struct group_statistics *gs1 ;
+
+ union value search_val;
+
+ if ( gp.criterion == CMP_LE )
+ search_val.f = gp.v.critical_value - 1.0;
+ else
+ search_val = gp.v.g_value[0];
+
+ gs0 = hsh_find(grp_hash, (void *) &search_val);
+ assert(gs0);
+
+ if ( gp.criterion == CMP_LE )
+ search_val.f = gp.v.critical_value + 1.0;
+ else
+ search_val = gp.v.g_value[1];
+
+ gs1 = hsh_find(grp_hash, (void *) &search_val);
+ assert(gs1);
+
+
+ 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_float(self->t, 2, i*2+3, TAB_CENTER, grp_data->levene, 8,3);
+
+ /* Now work out the significance of the Levene test */
+ df1 = 1; df2 = grp_data->ugs.n - 2;
+ q = gsl_cdf_fdist_Q(grp_data->levene, df1, df2);
+
+ tab_float(self->t, 3, i*2+3, TAB_CENTER, q, 8,3 );
+
+ df = gs0->n + gs1->n - 2.0 ;
+ tab_float (self->t, 5, i*2+3, TAB_RIGHT, df, 2, 0);
+
+ pooled_variance = ( (gs0->n )*pow2(gs0->s_std_dev)
+ +
+ (gs1->n )*pow2(gs1->s_std_dev)
+ ) / df ;
+
+ t = (gs0->mean - gs1->mean) / sqrt(pooled_variance) ;
+ t /= sqrt((gs0->n + gs1->n)/(gs0->n*gs1->n));
+
+ tab_float (self->t, 4, i*2+3, TAB_RIGHT, t, 8, 3);
+
+ p = gsl_cdf_tdist_P(t, df);
+ q = gsl_cdf_tdist_Q(t, df);
+
+ tab_float(self->t, 6, i*2+3, TAB_RIGHT, 2.0*(t>0?q:p) , 8, 3);
+
+ mean_diff = gs0->mean - gs1->mean;
+ tab_float(self->t, 7, i*2+3, TAB_RIGHT, mean_diff, 8, 3);
+
+
+ std_err_diff = sqrt( pow2(gs0->se_mean) + pow2(gs1->se_mean));
+ tab_float(self->t, 8, i*2+3, TAB_RIGHT, std_err_diff, 8, 3);
+
+
+ /* Now work out the confidence interval */
+ q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
+
+ t = gsl_cdf_tdist_Qinv(q,df);
+ tab_float(self->t, 9, i*2+3, TAB_RIGHT,
+ mean_diff - t * std_err_diff, 8, 3);
+
+ tab_float(self->t, 10, i*2+3, TAB_RIGHT,
+ mean_diff + t * std_err_diff, 8, 3);
+
+
+ {
+ double se2;
+ /* Now for the \sigma_1 != \sigma_2 case */
+ tab_text (self->t, 1, i*2+3+1,
+ TAB_LEFT, _("Equal variances not assumed"));
+
+
+ se2 = (pow2(gs0->s_std_dev)/(gs0->n -1) ) +
+ (pow2(gs1->s_std_dev)/(gs1->n -1) );
+
+ t = mean_diff / sqrt(se2) ;
+ tab_float (self->t, 4, i*2+3+1, TAB_RIGHT, t, 8, 3);
+
+ df = pow2(se2) / (
+ (pow2(pow2(gs0->s_std_dev)/(gs0->n - 1 ))
+ /(gs0->n -1 )
+ )
+ +
+ (pow2(pow2(gs1->s_std_dev)/(gs1->n - 1 ))
+ /(gs1->n -1 )
+ )
+ ) ;
+ tab_float (self->t, 5, i*2+3+1, TAB_RIGHT, df, 8, 3);
+
+ p = gsl_cdf_tdist_P(t, df);
+ q = gsl_cdf_tdist_Q(t, df);
+
+ tab_float(self->t, 6, i*2+3+1, TAB_RIGHT, 2.0*(t>0?q:p) , 8, 3);
+
+ /* Now work out the confidence interval */
+ q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
+
+ t = gsl_cdf_tdist_Qinv(q, df);
+
+ tab_float(self->t, 7, i*2+3+1, TAB_RIGHT, mean_diff, 8, 3);
+
+
+ tab_float(self->t, 8, i*2+3+1, TAB_RIGHT, std_err_diff, 8, 3);
+
+
+ tab_float(self->t, 9, i*2+3+1, TAB_RIGHT,
+ mean_diff - t * std_err_diff, 8, 3);
+
+ tab_float(self->t, 10, i*2+3+1, TAB_RIGHT,
+ mean_diff + t * std_err_diff, 8, 3);
+
+ }
+ }
+}
+
+/* Initialize the paired samples trbox */
+void
+trbox_paired_init(struct trbox *self,
+ struct cmd_t_test *cmd UNUSED)
+{
+
+ const int hsize=10;
+ const int vsize=n_pairs+3;
+
+ self->populate = trbox_paired_populate;
+
+ trbox_base_init(self,n_pairs,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 - 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_joint_text(self->t, 5, 1, 6, 1, TAB_CENTER | TAT_PRINTF,
+ _("%g%% Confidence Interval of the Difference"),
+ cmd->criteria*100.0);
+
+ tab_text (self->t, 2, 2, TAB_CENTER | TAT_TITLE, _("Mean"));
+ tab_text (self->t, 3, 2, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
+ tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Std. Error Mean"));
+ tab_text (self->t, 5, 2, TAB_CENTER | TAT_TITLE, _("Lower"));
+ tab_text (self->t, 6, 2, TAB_CENTER | TAT_TITLE, _("Upper"));
+ 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)
+{
+ int i;
+
+ for (i=0; i < n_pairs; ++i)
+ {
+ double p,q;
+ double se_mean;
+
+ double n = pairs[i].n;
+ double t;
+ double df = n - 1;
+
+ tab_text (trb->t, 0, i+3, TAB_LEFT | TAT_PRINTF, _("Pair %d"),i);
+
+ tab_text (trb->t, 1, i+3, TAB_LEFT | TAT_PRINTF, "%s - %s",
+ pairs[i].v[0]->name, pairs[i].v[1]->name);
+
+ tab_float(trb->t, 2, i+3, TAB_RIGHT, pairs[i].mean_diff, 8, 4);
+
+ tab_float(trb->t, 3, i+3, TAB_RIGHT, pairs[i].std_dev_diff, 8, 5);
+
+ /* SE Mean */
+ se_mean = pairs[i].std_dev_diff / sqrt(n) ;
+ tab_float(trb->t, 4, i+3, TAB_RIGHT, se_mean, 8,5 );
+
+ /* Now work out the confidence interval */
+ q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
+
+ t = gsl_cdf_tdist_Qinv(q, df);
+
+ tab_float(trb->t, 5, i+3, TAB_RIGHT,
+ pairs[i].mean_diff - t * se_mean , 8, 4);
+
+ tab_float(trb->t, 6, i+3, TAB_RIGHT,
+ pairs[i].mean_diff + t * se_mean , 8, 4);
+
+ t = (pairs[i].mean[0] - pairs[i].mean[1])
+ / sqrt (
+ ( pow2 (pairs[i].s_std_dev[0]) + pow2 (pairs[i].s_std_dev[1]) -
+ 2 * pairs[i].correlation *
+ pairs[i].s_std_dev[0] * pairs[i].s_std_dev[1] )
+ / (n - 1)
+ );
+
+ tab_float(trb->t, 7, i+3, TAB_RIGHT, t , 8,3 );
+
+ /* Degrees of freedom */
+ tab_float(trb->t, 8, i+3, TAB_RIGHT, df , 2, 0 );
+
+ p = gsl_cdf_tdist_P(t,df);
+ q = gsl_cdf_tdist_P(t,df);
+
+ tab_float(trb->t, 9, i+3, TAB_RIGHT, 2.0*(t>0?q:p) , 8, 3);
+
+ }
+}
+
+/* Initialize the one sample trbox */
+void
+trbox_one_sample_init(struct trbox *self, struct cmd_t_test *cmd )
+{
+ const int hsize=7;
+ const int vsize=cmd->n_variables+3;
+
+ self->populate = trbox_one_sample_populate;
+
+ 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 - 1);
+
+ tab_joint_text(self->t, 1, 0, hsize-1,0, TAB_CENTER | TAT_PRINTF,
+ _("Test Value = %f"), cmd->n_testval[0]);
+
+ tab_box(self->t, -1, -1, -1, TAL_1, 1,1,hsize-1,vsize-1);
+
+
+ tab_joint_text(self->t,5,1,6,1,TAB_CENTER | TAT_PRINTF,
+ _("%g%% Confidence Interval of the Difference"),
+ cmd->criteria*100.0);
+
+ 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)"));
+ tab_text (self->t, 4, 2, TAB_CENTER | TAT_TITLE, _("Mean Difference"));
+ 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)
+{
+ int i;
+
+ assert(trb->t);
+
+ for (i=0; i < cmd->n_variables; ++i)
+ {
+ double t;
+ double p,q;
+ double df;
+ struct group_statistics *gs = &group_proc_get (cmd->v_variables[i])->ugs;
+
+
+ tab_text (trb->t, 0, i+3, TAB_LEFT, cmd->v_variables[i]->name);
+
+ t = (gs->mean - cmd->n_testval[0] ) * sqrt(gs->n) / gs->std_dev ;
+
+ tab_float (trb->t, 1, i+3, TAB_RIGHT, t, 8,3);
+
+ /* degrees of freedom */
+ df = gs->n - 1;
+
+ tab_float (trb->t, 2, i+3, TAB_RIGHT, df, 8,0);
+
+ p = gsl_cdf_tdist_P(t, df);
+ q = gsl_cdf_tdist_Q(t, df);
+
+ /* Multiply by 2 to get 2-tailed significance, makeing sure we've got
+ the correct tail*/
+ tab_float (trb->t, 3, i+3, TAB_RIGHT, 2.0*(t>0?q:p), 8,3);
+
+ tab_float (trb->t, 4, i+3, TAB_RIGHT, gs->mean_diff, 8,3);
+
+
+ q = (1 - cmd->criteria)/2.0; /* 2-tailed test */
+ t = gsl_cdf_tdist_Qinv(q, df);
+
+ tab_float (trb->t, 5, i+3, TAB_RIGHT,
+ gs->mean_diff - t * gs->se_mean, 8,4);
+
+ tab_float (trb->t, 6, i+3, TAB_RIGHT,
+ gs->mean_diff + t * gs->se_mean, 8,4);
+ }
+}
+
+/* Base initializer for the generalized trbox */
+void
+trbox_base_init(struct trbox *self, int data_rows, int cols)
+{
+ 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);
+}
+
+
+/* Base finalizer for the trbox */
+void
+trbox_base_finalize(struct trbox *trb)
+{
+ tab_submit(trb->t);
+}
+
+
+/* Create , populate and submit the Paired Samples Correlation box */
+void
+pscbox(void)
+{
+ 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."));
+
+ for (i=0; i < n_pairs; ++i)
+ {
+ double p,q;
+
+ double df = pairs[i].n -2;
+
+ double correlation_t =
+ pairs[i].correlation * sqrt(df) /
+ sqrt(1 - pow2(pairs[i].correlation));
+
+
+ /* row headings */
+ tab_text(table, 0,i+1, TAB_LEFT | TAT_TITLE | TAT_PRINTF,
+ _("Pair %d"), i);
+
+ tab_text(table, 1,i+1, TAB_LEFT | TAT_TITLE | TAT_PRINTF,
+ _("%s & %s"), pairs[i].v[0]->name, pairs[i].v[1]->name);
+
+
+ /* row data */
+ tab_float(table, 2, i+1, TAB_RIGHT, pairs[i].n, 4, 0);
+ tab_float(table, 3, i+1, TAB_RIGHT, pairs[i].correlation, 8, 3);
+
+ p = gsl_cdf_tdist_P(correlation_t, df);
+ q = gsl_cdf_tdist_Q(correlation_t, df);
+
+ tab_float(table, 4, i+1, TAB_RIGHT, 2.0*(correlation_t>0?q:p), 8, 3);
+ }
+
+ tab_submit(table);
+}
+
+
+
+
+/* Calculation Implementation */
+
+/* Per case calculations common to all variants of the T test */
+static int
+common_calc (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);
+
+
+ /* Skip the entire case if /MISSING=LISTWISE is set */
+ if ( cmd->miss == TTS_LISTWISE )
+ {
+ for(i=0; i< cmd->n_variables ; ++i)
+ {
+ struct variable *v = cmd->v_variables[i];
+ const union value *val = case_data (c, v->fv);
+
+ if (value_is_missing(val,v) )
+ {
+ return 0;
+ }
+ }
+ }
+
+ /* Listwise has to be implicit if the independent variable is missing ?? */
+ if ( cmd->sbc_groups )
+ {
+ const union value *gv = case_data (c, indep_var->fv);
+ if ( value_is_missing(gv,indep_var) )
+ {
+ return 0;
+ }
+ }
+
+
+ for(i=0; i< cmd->n_variables ; ++i)
+ {
+ struct group_statistics *gs;
+ struct variable *v = cmd->v_variables[i];
+ const union value *val = case_data (c, v->fv);
+
+ gs= &group_proc_get (cmd->v_variables[i])->ugs;
+
+ if (! value_is_missing(val,v) )
+ {
+ gs->n+=weight;
+ gs->sum+=weight * val->f;
+ gs->ssq+=weight * val->f * val->f;
+ }
+ }
+ return 0;
+}
+
+/* Pre calculations common to all variants of the T test */
+static void
+common_precalc ( struct cmd_t_test *cmd )
+{
+ int i=0;
+
+ for(i=0; i< cmd->n_variables ; ++i)
+ {
+ struct group_statistics *gs;
+ gs= &group_proc_get (cmd->v_variables[i])->ugs;
+
+ gs->sum=0;
+ gs->n=0;
+ gs->ssq=0;
+ gs->sum_diff=0;
+ }
+}
+
+/* Post calculations common to all variants of the T test */
+void
+common_postcalc ( struct cmd_t_test *cmd )
+{
+ int i=0;
+
+
+ for(i=0; i< cmd->n_variables ; ++i)