+
+/* Per case calculations for one sample t test */
+static int
+one_sample_calc (struct ccase *c, void *aux UNUSED)
+{
+ int i;
+
+ double weight = dict_get_case_weight(default_dict,c);
+
+ for(i=0; i< cmd.n_variables ; ++i)
+ {
+ struct group_statistics *gs;
+ struct variable *v = cmd.v_variables[i];
+ union value *val = &c->data[v->fv];
+
+ gs= &cmd.v_variables[i]->p.t_t.ugs;
+
+ if (val->f != SYSMIS)
+ gs->sum_diff += weight * (val->f - cmd.n_testval);
+ }
+
+ return 0;
+}
+
+/* Pre calculations for one sample t test */
+static void
+one_sample_precalc (void *aux UNUSED)
+{
+ int i=0;
+
+ for(i=0; i< cmd.n_variables ; ++i)
+ {
+ struct group_statistics *gs;
+ gs= &cmd.v_variables[i]->p.t_t.ugs;
+
+ gs->sum_diff=0;
+ }
+}
+
+/* Post calculations for one sample t test */
+static void
+one_sample_postcalc (void *aux UNUSED)
+{
+ int i=0;
+
+ for(i=0; i< cmd.n_variables ; ++i)
+ {
+ struct group_statistics *gs;
+ gs= &cmd.v_variables[i]->p.t_t.ugs;
+
+
+ gs->mean_diff = gs->sum_diff / gs->n ;
+ }
+}
+
+
+
+static int
+compare_var_name (const void *a_, const void *b_, void *v_ UNUSED)
+{
+ const struct variable *a = a_;
+ const struct variable *b = b_;
+
+ return strcmp(a->name,b->name);
+}
+
+static unsigned
+hash_var_name (const void *a_, void *v_ UNUSED)
+{
+ const struct variable *a = a_;
+
+ return hsh_hash_bytes (a->name, strlen(a->name));
+}
+
+
+
+static void
+paired_precalc (void *aux UNUSED)
+{
+ int i;
+
+ for(i=0; i < n_pairs ; ++i )
+ {
+ pairs[i].correlation=0;
+ pairs[i].sum_of_diffs=0;
+ pairs[i].ssq_diffs=0;
+ }
+
+}
+
+
+static int
+paired_calc (struct ccase *c, void *aux UNUSED)
+{
+ int i;
+
+ for(i=0; i < n_pairs ; ++i )
+ {
+ struct variable *v0 = pairs[i].v[0];
+ struct variable *v1 = pairs[i].v[1];
+
+ union value *val0 = &c->data[v0->fv];
+ union value *val1 = &c->data[v1->fv];
+
+ pairs[i].correlation += ( val0->f - pairs[i].v[0]->p.t_t.ugs.mean )
+ *
+ ( val1->f - pairs[i].v[1]->p.t_t.ugs.mean );
+
+ pairs[i].sum_of_diffs += val0->f - val1->f ;
+ pairs[i].ssq_diffs += sqr(val0->f - val1->f);
+
+ }
+
+ return 0;
+}
+
+static void
+paired_postcalc (void *aux UNUSED)
+{
+ int i;
+
+ for(i=0; i < n_pairs ; ++i )
+ {
+ const double n = pairs[i].v[0]->p.t_t.ugs.n ;
+
+ pairs[i].correlation /= pairs[i].v[0]->p.t_t.ugs.std_dev *
+ pairs[i].v[1]->p.t_t.ugs.std_dev ;
+ pairs[i].correlation /= pairs[i].v[0]->p.t_t.ugs.n -1;
+
+
+ pairs[i].mean_diff = pairs[i].sum_of_diffs / n ;
+
+
+ pairs[i].std_dev_diff = sqrt ( n / (n - 1) * (
+ ( pairs[i].ssq_diffs / n )
+ -
+ sqr(pairs[i].mean_diff )
+ ) );
+ }
+}
+
+static int
+get_group(const union value *val, struct variable *var)
+{
+ if ( 0 == compare_values(val,&groups_values[0],var->width) )
+ return 0;
+ else if (0 == compare_values(val,&groups_values[1],var->width) )
+ return 1;
+
+ /* Never reached */
+ assert(0);
+ return -1;
+}
+
+
+static void
+group_precalc (void *aux UNUSED)
+{
+ int i;
+ int j;
+
+ for(i=0; i< cmd.n_variables ; ++i)
+ {
+ struct t_test_proc *ttpr = &cmd.v_variables[i]->p.t_t;
+
+ /* There's always 2 groups for a T - TEST */
+ ttpr->n_groups = 2;
+ ttpr->gs = xmalloc(sizeof(struct group_statistics) * 2) ;
+
+ for (j=0 ; j < 2 ; ++j)
+ {
+ ttpr->gs[j].sum=0;
+ ttpr->gs[j].n=0;
+ ttpr->gs[j].ssq=0;
+ ttpr->gs[j].id = groups_values[j];
+ }
+ }
+
+}
+
+static int
+group_calc (struct ccase *c, void *aux UNUSED)
+{
+ int i;
+ union value *gv = &c->data[groups->fv];
+
+ double weight = dict_get_case_weight(default_dict,c);
+
+ gv = &c->data[groups->fv];
+
+ for(i=0; i< cmd.n_variables ; ++i)
+ {
+ int g = get_group(gv,groups);
+
+ struct group_statistics *gs = &cmd.v_variables[i]->p.t_t.gs[g];
+
+ union value *val=&c->data[cmd.v_variables[i]->fv];
+
+ gs->n+=weight;
+ gs->sum+=weight * val->f;
+ gs->ssq+=weight * sqr(val->f);
+ }
+
+ return 0;
+}
+
+
+static void
+group_postcalc (void *aux UNUSED)
+{
+ int i;
+ int j;
+
+ for(i=0; i< cmd.n_variables ; ++i)
+ {
+ for (j=0 ; j < 2 ; ++j)
+ {
+ struct group_statistics *gs;
+ gs=&cmd.v_variables[i]->p.t_t.gs[j];
+
+ gs->mean = gs->sum / gs->n;
+
+ gs->s_std_dev= sqrt(
+ ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
+ ) ;
+
+ gs->std_dev= sqrt(
+ gs->n/(gs->n-1) *
+ ( (gs->ssq / gs->n ) - gs->mean * gs->mean )
+ ) ;
+
+ gs->se_mean = gs->std_dev / sqrt(gs->n);
+ }
+ }
+}
+