Amalgamated t-test.h and oneway.h into a single group_proc.h file
[pspp] / src / t-test.q
index 4c4135ba732d97f4f5f75c095bd03c7a3bf8da54..2993ac9114f3b3fd1e50d8887d753ccbd42833af 100644 (file)
@@ -27,6 +27,7 @@
 #include <math.h>
 #include "alloc.h"
 #include "str.h"
+#include "case.h"
 #include "command.h"
 #include "lexer.h"
 #include "error.h"
@@ -38,7 +39,7 @@
 #include "var.h"
 #include "vfm.h"
 #include "hash.h"
-#include "t-test.h"
+#include "group_proc.h"
 #include "casefile.h"
 #include "levene.h"
 
@@ -214,8 +215,6 @@ int
 cmd_t_test(void)
 {
 
-
-
   if ( !parse_t_test(&cmd) )
     return CMD_FAILURE;
 
@@ -310,7 +309,7 @@ cmd_t_test(void)
       /* Destroy any group statistics we created */
       for (i= 0 ; i < cmd.n_variables ; ++i ) 
        {
-         free(cmd.v_variables[i]->p.t_t.gs);
+         free(cmd.v_variables[i]->p.grp_data.gs);
        }
     }
     
@@ -514,6 +513,7 @@ tts_custom_pairs (struct cmd_t_test *cmd UNUSED)
 
   n_pairs+=n_pairs_local;
 
+  free (vars);
   return 1;
 }
 
@@ -532,7 +532,7 @@ parse_value (union value * v, int type )
     {
       if (!lex_force_string ())
        return 0;
-      strncpy (v->s, ds_value (&tokstr), ds_length (&tokstr));
+      strncpy (v->s, ds_c_str (&tokstr), ds_length (&tokstr));
     }
 
   lex_get ();
@@ -629,7 +629,7 @@ ssbox_one_sample_init(struct ssbox *this,
 
   ssbox_base_init(this, hsize,vsize);
   tab_title (this->t, 0, _("One-Sample Statistics"));
-  tab_vline(this->t, TAL_2, 1,0,vsize);
+  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"));
   tab_text (this->t, 3, 0, TAB_CENTER | TAT_TITLE, _("Std. Deviation"));
@@ -651,7 +651,7 @@ ssbox_independent_samples_init(struct ssbox *this,
 
   ssbox_base_init(this, hsize,vsize);
   tab_title (this->t, 0, _("Group Statistics"));
-  tab_vline(this->t,0,1,0,vsize);
+  tab_vline(this->t,0,1,0,vsize - 1);
   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"));
@@ -715,7 +715,7 @@ ssbox_independent_samples_populate(struct ssbox *ssb,
       /* Fill in the group statistics */
       for ( g=0; g < 2 ; ++g ) 
        {
-         struct group_statistics *gs = &cmd->v_variables[i]->p.t_t.gs[g];
+         struct group_statistics *gs = &cmd->v_variables[i]->p.grp_data.gs[g];
 
          tab_float(ssb->t, 2 ,i*2+g+1, TAB_RIGHT, gs->n, 2, 0);
          tab_float(ssb->t, 3 ,i*2+g+1, TAB_RIGHT, gs->mean, 8, 2);
@@ -768,7 +768,7 @@ ssbox_paired_populate(struct ssbox *ssb,struct cmd_t_test *cmd UNUSED)
        {
          struct group_statistics *gs;
 
-         gs=&pairs[i].v[j]->p.t_t.ugs;
+         gs=&pairs[i].v[j]->p.grp_data.ugs;
 
          /* Titles */
 
@@ -795,7 +795,7 @@ ssbox_one_sample_populate(struct ssbox *ssb, struct cmd_t_test *cmd)
   for (i=0; i < cmd->n_variables; ++i)
     {
       struct group_statistics *gs;
-      gs= &cmd->v_variables[i]->p.t_t.ugs;
+      gs= &cmd->v_variables[i]->p.grp_data.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);
@@ -929,8 +929,8 @@ trbox_independent_samples_populate(struct trbox *self,
       double std_err_diff;
       double mean_diff;
 
-      struct group_statistics *gs0 = &cmd->v_variables[i]->p.t_t.gs[0];
-      struct group_statistics *gs1 = &cmd->v_variables[i]->p.t_t.gs[1];
+      struct group_statistics *gs0 = &cmd->v_variables[i]->p.grp_data.gs[0];
+      struct group_statistics *gs1 = &cmd->v_variables[i]->p.grp_data.gs[1];
          
       tab_text (self->t, 0, i*2+3, TAB_LEFT, cmd->v_variables[i]->name);
 
@@ -938,11 +938,11 @@ trbox_independent_samples_populate(struct trbox *self,
 
 
       tab_float(self->t, 2, i*2+3, TAB_CENTER, 
-               cmd->v_variables[i]->p.t_t.levene, 8,3);
+               cmd->v_variables[i]->p.grp_data.levene, 8,3);
 
       /* Now work out the significance of the Levene test */
-      df1 = 1; df2 = cmd->v_variables[i]->p.t_t.ugs.n - 2;
-      q = gsl_cdf_fdist_Q(cmd->v_variables[i]->p.t_t.levene, df1, df2);
+      df1 = 1; df2 = cmd->v_variables[i]->p.grp_data.ugs.n - 2;
+      q = gsl_cdf_fdist_Q(cmd->v_variables[i]->p.grp_data.levene, df1, df2);
 
       tab_float(self->t, 3, i*2+3, TAB_CENTER, q, 8,3 );
 
@@ -1047,7 +1047,7 @@ trbox_paired_init(struct trbox *self,
   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);
+  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);
@@ -1141,7 +1141,7 @@ trbox_one_sample_init(struct trbox *self, struct cmd_t_test *cmd )
   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);
+  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);
@@ -1179,7 +1179,7 @@ trbox_one_sample_populate(struct trbox *trb, struct cmd_t_test *cmd)
       double p,q;
       double df;
       struct group_statistics *gs;
-      gs= &cmd->v_variables[i]->p.t_t.ugs;
+      gs= &cmd->v_variables[i]->p.grp_data.ugs;
 
 
       tab_text (trb->t, 0, i+3, TAB_LEFT, cmd->v_variables[i]->name);
@@ -1314,7 +1314,7 @@ common_calc (const struct ccase *c, void *_cmd)
       for(i=0; i< cmd->n_variables ; ++i) 
        {
          struct variable *v = cmd->v_variables[i];
-         const union value *val = &c->data[v->fv];
+         const union value *val = case_data (c, v->fv);
 
          if (value_is_missing(val,v) )
            {
@@ -1326,7 +1326,7 @@ common_calc (const struct ccase *c, void *_cmd)
   /* Listwise has to be implicit if the independent variable is missing ?? */
   if ( cmd->sbc_groups )
     {
-      const union value *gv = &c->data[indep_var->fv];
+      const union value *gv = case_data (c, indep_var->fv);
       if ( value_is_missing(gv,indep_var) )
        {
          return 0;
@@ -1338,9 +1338,9 @@ common_calc (const struct ccase *c, void *_cmd)
     {
       struct group_statistics *gs;
       struct variable *v = cmd->v_variables[i];
-      const union value *val = &c->data[v->fv];
+      const union value *val = case_data (c, v->fv);
 
-      gs= &cmd->v_variables[i]->p.t_t.ugs;
+      gs= &cmd->v_variables[i]->p.grp_data.ugs;
 
       if (! value_is_missing(val,v) )
        {
@@ -1361,7 +1361,7 @@ common_precalc ( struct cmd_t_test *cmd )
   for(i=0; i< cmd->n_variables ; ++i) 
     {
       struct group_statistics *gs;
-      gs= &cmd->v_variables[i]->p.t_t.ugs;
+      gs= &cmd->v_variables[i]->p.grp_data.ugs;
       
       gs->sum=0;
       gs->n=0;
@@ -1380,7 +1380,7 @@ common_postcalc (  struct cmd_t_test *cmd )
   for(i=0; i< cmd->n_variables ; ++i) 
     {
       struct group_statistics *gs;
-      gs= &cmd->v_variables[i]->p.t_t.ugs;
+      gs= &cmd->v_variables[i]->p.grp_data.ugs;
       
       gs->mean=gs->sum / gs->n;
       gs->s_std_dev= sqrt(
@@ -1413,7 +1413,7 @@ one_sample_calc (const struct ccase *c, void *cmd_)
       for(i=0; i< cmd->n_variables ; ++i) 
        {
          struct variable *v = cmd->v_variables[i];
-         const union value *val = &c->data[v->fv];
+         const union value *val = case_data (c, v->fv);
 
          if (value_is_missing(val,v) )
            {
@@ -1426,9 +1426,9 @@ one_sample_calc (const struct ccase *c, void *cmd_)
     {
       struct group_statistics *gs;
       struct variable *v = cmd->v_variables[i];
-      const union value *val = &c->data[v->fv];
+      const union value *val = case_data (c, v->fv);
 
-      gs= &cmd->v_variables[i]->p.t_t.ugs;
+      gs= &cmd->v_variables[i]->p.grp_data.ugs;
       
       if ( ! value_is_missing(val,v))
        gs->sum_diff += weight * (val->f - cmd->n_testval);
@@ -1446,7 +1446,7 @@ one_sample_precalc ( struct cmd_t_test *cmd )
   for(i=0; i< cmd->n_variables ; ++i) 
     {
       struct group_statistics *gs;
-      gs= &cmd->v_variables[i]->p.t_t.ugs;
+      gs= &cmd->v_variables[i]->p.grp_data.ugs;
       
       gs->sum_diff=0;
     }
@@ -1461,7 +1461,7 @@ one_sample_postcalc (struct cmd_t_test *cmd)
   for(i=0; i< cmd->n_variables ; ++i) 
     {
       struct group_statistics *gs;
-      gs= &cmd->v_variables[i]->p.t_t.ugs;
+      gs= &cmd->v_variables[i]->p.grp_data.ugs;
 
       gs->mean_diff = gs->sum_diff / gs->n ;
     }
@@ -1525,8 +1525,8 @@ paired_calc (const struct ccase *c, void *cmd_)
          struct variable *v0 = pairs[i].v[0];
          struct variable *v1 = pairs[i].v[1];
 
-         const union value *val0 = &c->data[v0->fv];
-         const union value *val1 = &c->data[v1->fv];
+         const union value *val0 = case_data (c, v0->fv);
+         const union value *val1 = case_data (c, v1->fv);
          
          if ( value_is_missing(val0,v0) ||
               value_is_missing(val1,v1) )
@@ -1541,8 +1541,8 @@ paired_calc (const struct ccase *c, void *cmd_)
       struct variable *v0 = pairs[i].v[0];
       struct variable *v1 = pairs[i].v[1];
 
-      const union value *val0 = &c->data[v0->fv];
-      const union value *val1 = &c->data[v1->fv];
+      const union value *val0 = case_data (c, v0->fv);
+      const union value *val1 = case_data (c, v1->fv);
 
       if ( ( !value_is_missing(val0,v0) && !value_is_missing(val1,v1) ) )
       {
@@ -1648,7 +1648,7 @@ group_precalc (struct cmd_t_test *cmd )
 
   for(i=0; i< cmd->n_variables ; ++i) 
     {
-      struct t_test_proc *ttpr = &cmd->v_variables[i]->p.t_t;
+      struct group_proc *ttpr = &cmd->v_variables[i]->p.grp_data;
 
       /* There's always 2 groups for a T - TEST */
       ttpr->n_groups = 2;
@@ -1676,7 +1676,7 @@ group_calc (const struct ccase *c, struct cmd_t_test *cmd)
   int i;
   int g;
 
-  const union value *gv = &c->data[indep_var->fv];
+  const union value *gv = case_data (c, indep_var->fv);
 
   const double weight = dict_get_case_weight(default_dict,c,&bad_weight_warn);
 
@@ -1690,7 +1690,7 @@ group_calc (const struct ccase *c, struct cmd_t_test *cmd)
       for(i=0; i< cmd->n_variables ; ++i) 
        {
          struct variable *v = cmd->v_variables[i];
-         const union value *val = &c->data[v->fv];
+         const union value *val = case_data (c, v->fv);
 
          if (value_is_missing(val,v) )
            {
@@ -1700,7 +1700,7 @@ group_calc (const struct ccase *c, struct cmd_t_test *cmd)
     }
 
 
-  gv = &c->data[indep_var->fv];
+  gv = case_data (c, indep_var->fv);
 
   g = get_group(gv,indep_var);
 
@@ -1714,9 +1714,9 @@ group_calc (const struct ccase *c, struct cmd_t_test *cmd)
     {
       struct variable *var = cmd->v_variables[i];
 
-      struct group_statistics *gs = &var->p.t_t.gs[g];
+      struct group_statistics *gs = &var->p.grp_data.gs[g];
 
-      const union value *val=&c->data[var->fv];
+      const union value *val = case_data (c, var->fv);
 
       if ( !value_is_missing(val,var) )
        {
@@ -1741,7 +1741,7 @@ group_postcalc ( struct cmd_t_test *cmd )
       for (j=0 ; j < 2 ; ++j)
        {
          struct group_statistics *gs;
-         gs=&cmd->v_variables[i]->p.t_t.gs[j];
+         gs=&cmd->v_variables[i]->p.grp_data.gs[j];
 
          gs->mean = gs->sum / gs->n;
          
@@ -1768,15 +1768,16 @@ calculate(const struct casefile *cf, void *cmd_)
   struct trbox test_results_box;
 
   struct casereader *r;
-  const struct ccase *c;
+  struct ccase c;
 
   struct cmd_t_test *cmd = (struct cmd_t_test *) cmd_;
 
   common_precalc(cmd);
   for(r = casefile_get_reader (cf);
-      casereader_read (r, &c) ; ) 
+      casereader_read (r, &c) ;
+      case_destroy (&c)) 
     {
-      common_calc(c,cmd);
+      common_calc(&c,cmd);
     }
   casereader_destroy (r);
   common_postcalc(cmd);
@@ -1786,9 +1787,10 @@ calculate(const struct casefile *cf, void *cmd_)
     case T_1_SAMPLE:
       one_sample_precalc(cmd);
       for(r = casefile_get_reader (cf);
-         casereader_read (r, &c) ; ) 
+         casereader_read (r, &c) ;
+          case_destroy (&c)) 
        {
-         one_sample_calc(c,cmd);
+         one_sample_calc(&c,cmd);
        }
       casereader_destroy (r);
       one_sample_postcalc(cmd);
@@ -1797,9 +1799,10 @@ calculate(const struct casefile *cf, void *cmd_)
     case T_PAIRED:
       paired_precalc(cmd);
       for(r = casefile_get_reader (cf);
-         casereader_read (r, &c) ; ) 
+         casereader_read (r, &c) ;
+          case_destroy (&c)) 
        {
-         paired_calc(c,cmd);
+         paired_calc(&c,cmd);
        }
       casereader_destroy (r);
       paired_postcalc(cmd);
@@ -1809,9 +1812,10 @@ calculate(const struct casefile *cf, void *cmd_)
 
       group_precalc(cmd);
       for(r = casefile_get_reader (cf);
-         casereader_read (r, &c) ; ) 
+         casereader_read (r, &c) ;
+          case_destroy (&c)) 
        {
-         group_calc(c,cmd);
+         group_calc(&c,cmd);
        }
       casereader_destroy (r);
       group_postcalc(cmd);