Fix typos in printed strings
[pspp] / src / language / stats / t-test.q
index 3d47bb81f8d7b0bfcfbb648e9fe2f49fb873af38..9eb2c471356b2daa7a6e94f7a7174aac1c7cb65f 100644 (file)
 #include <libpspp/taint.h>
 #include <math/group-proc.h>
 #include <math/levene.h>
-#include <output/manager.h>
-#include <output/table.h>
+#include <math/correlation.h>
+#include <output/tab.h>
 #include <data/format.h>
 
+#include "minmax.h"
 #include "xalloc.h"
 #include "xmemdup0.h"
 
@@ -477,11 +478,9 @@ ssbox_base_init (struct ssbox *this, int cols, int rows)
   this->finalize = ssbox_base_finalize;
   this->t = tab_create (cols, rows);
 
-  tab_columns (this->t, SOM_COL_DOWN);
   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, NULL, NULL);
 }
 \f
 /* ssbox implementations. */
@@ -506,7 +505,7 @@ ssbox_one_sample_init (struct ssbox *this, struct t_test_proc *proc)
   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"));
+  tab_text (this->t, 4, 0, TAB_CENTER | TAT_TITLE, _("S.E. Mean"));
 }
 
 /* Initialize the independent samples ssbox */
@@ -526,7 +525,7 @@ ssbox_independent_samples_init (struct ssbox *this, struct t_test_proc *proc)
   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"));
+  tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("S.E. Mean"));
 }
 
 /* Populate the ssbox for independent samples */
@@ -625,7 +624,7 @@ ssbox_paired_init (struct ssbox *this, struct t_test_proc *proc)
   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"));
+  tab_text (this->t, 5, 0, TAB_CENTER | TAT_TITLE, _("S.E. Mean"));
 }
 
 /* Populate the ssbox for paired values */
@@ -974,8 +973,8 @@ trbox_paired_populate (struct trbox *trb,
       /* Degrees of freedom */
       tab_double (trb->t, 8, i + 3, TAB_RIGHT, df, &proc->weight_format);
 
-      p = gsl_cdf_tdist_P (t, df);
-      q = gsl_cdf_tdist_P (t, df);
+      p = gsl_cdf_tdist_P (t,df);
+      q = gsl_cdf_tdist_Q (t,df);
 
       tab_double (trb->t, 9, i + 3, TAB_RIGHT, 2.0 * (t > 0 ? q : p), NULL);
     }
@@ -1071,7 +1070,6 @@ trbox_base_init (struct trbox *self, size_t data_rows, int cols)
   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, NULL, NULL);
 }
 
 /* Base finalizer for the trbox */
@@ -1093,12 +1091,10 @@ pscbox (struct t_test_proc *proc)
 
   table = tab_create (cols, rows);
 
-  tab_columns (table, SOM_COL_DOWN);
   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, NULL, NULL);
   tab_title (table, _("Paired Samples Correlations"));
 
   /* column headings */
@@ -1109,10 +1105,6 @@ pscbox (struct t_test_proc *proc)
   for (i = 0; i < proc->n_pairs; i++)
     {
       struct pair *pair = &proc->pairs[i];
-      double p, q;
-      double df = pair->n -2;
-      double correlation_t = (pair->correlation * sqrt (df) /
-                              sqrt (1 - pow2 (pair->correlation)));
 
       /* row headings */
       tab_text_format (table, 0, i + 1, TAB_LEFT | TAT_TITLE,
@@ -1126,10 +1118,8 @@ pscbox (struct t_test_proc *proc)
       tab_double (table, 2, i + 1, TAB_RIGHT, pair->n, &proc->weight_format);
       tab_double (table, 3, i + 1, TAB_RIGHT, pair->correlation, NULL);
 
-      p = gsl_cdf_tdist_P (correlation_t, df);
-      q = gsl_cdf_tdist_Q (correlation_t, df);
-      tab_double (table, 4, i + 1, TAB_RIGHT,
-                 2.0 * (correlation_t > 0 ? q : p), NULL);
+      tab_double (table, 4, i + 1, TAB_RIGHT, 
+                 2.0 * significance_of_correlation (pair->correlation, pair->n), NULL);
     }
 
   tab_submit (table);
@@ -1411,6 +1401,23 @@ group_calc (const struct dictionary *dict, struct t_test_proc *proc,
   return 0;
 }
 
+
+static bool
+is_criteria_value (const struct ccase *c, void *aux)
+{
+  const struct t_test_proc *proc = aux;
+  const union value *val = case_data (c, proc->indep_var);
+  int width = var_get_width (proc->indep_var);
+
+  if ( value_equal (val, &proc->g_value[0], width))
+    return true;
+
+  if ( value_equal (val, &proc->g_value[1], width))
+    return true;
+
+  return false;
+}
+
 static void
 calculate (struct t_test_proc *proc,
            struct casereader *input, const struct dataset *ds)
@@ -1420,7 +1427,7 @@ calculate (struct t_test_proc *proc,
   struct trbox test_results_box;
   struct taint *taint;
   struct ccase *c;
-
+  int i;
   c = casereader_peek (input, 0);
   if (c == NULL)
     {
@@ -1449,8 +1456,20 @@ calculate (struct t_test_proc *proc,
       break;
     case T_IND_SAMPLES:
       group_calc (dict, proc, casereader_clone (input));
-      levene (dict, input, proc->indep_var, proc->n_vars, proc->vars,
-              proc->exclude);
+
+      for (i = 0; i < proc->n_vars; ++i)
+       {
+         struct group_proc *grp_data = group_proc_get (proc->vars[i]);
+
+         if ( proc->criterion == CMP_EQ )
+           {
+             input = casereader_create_filter_func (input, is_criteria_value, NULL,
+                                                    proc, 
+                                                    NULL);
+           }
+
+         grp_data->levene = levene ( input, proc->indep_var, proc->vars[i], dict_get_weight (dict), proc->exclude);
+       }
       break;
     default:
       NOT_REACHED ();