subcase: Rename subcase_destroy() to subcase_uninit().
[pspp] / src / language / stats / runs.c
index eb95372ae81d8573b1c294341f1752b7a10ca2b6..8a63b29c96b8e43a582267571e7adaad68e048f7 100644 (file)
@@ -78,7 +78,7 @@ runs_statistic (const struct run_state *rs)
 
   z = rs->runs - mu;
 
-  if ( rs->n < 50)
+  if (rs->n < 50)
     {
       if (z <= -0.5)
        z += 0.5;
@@ -116,9 +116,9 @@ runs_execute (const struct dataset *ds,
 
   struct one_sample_test *otp = UP_CAST (test, struct one_sample_test, parent);
   struct runs_test *rt = UP_CAST (otp, struct runs_test, parent);
-  struct run_state *rs = xcalloc (otp->n_vars, sizeof (*rs));
+  struct run_state *rs = XCALLOC (otp->n_vars,  struct run_state);
 
-  switch  ( rt->cp_mode)
+  switch  (rt->cp_mode)
     {
     case CP_MODE:
       {
@@ -143,22 +143,22 @@ runs_execute (const struct dataset *ds,
                struct ccase *c;
                for (; (c = casereader_read (group)); case_unref (c))
                  {
-                   const double w = weight ? case_data (c, weight)->f: 1.0;
+                   const double w = weight ? case_num (c, weight) : 1.0;
                    const union value *val = case_data (c, var);
-                   if ( var_is_value_missing (var, val, exclude))
+                   if (var_is_value_missing (var, val) & exclude)
                      continue;
                    x = val->f;
                    cc += w;
                  }
 
-               if ( cc > last_cc)
+               if (cc > last_cc)
                  {
                    run->cutpoint = x;
                  }
-               else if ( cc == last_cc)
+               else if (cc == last_cc)
                  {
                    multimodal = true;
-                   if ( x > run->cutpoint)
+                   if (x > run->cutpoint)
                      run->cutpoint = x;
                  }
                last_cc = cc;
@@ -188,11 +188,11 @@ runs_execute (const struct dataset *ds,
            subcase_init_var (&sc, var, SC_ASCEND);
            writer = sort_create_writer (&sc, casereader_get_proto (reader));
 
-           for (; (c = casereader_read (reader)); )
+           for (; (c = casereader_read (reader));)
              {
                const union value *val = case_data (c, var);
-               const double w = weight ? case_data (c, weight)->f: 1.0;
-               if ( var_is_value_missing (var, val, exclude))
+               const double w = weight ? case_num (c, weight) : 1.0;
+               if (var_is_value_missing (var, val) & exclude)
                  {
                    case_unref (c);
                    continue;
@@ -201,7 +201,7 @@ runs_execute (const struct dataset *ds,
                cc += w;
                casewriter_write (writer, c);
              }
-           subcase_destroy (&sc);
+           subcase_uninit (&sc);
            casereader_destroy (reader);
            reader = casewriter_make_reader (writer);
 
@@ -224,7 +224,7 @@ runs_execute (const struct dataset *ds,
        struct casereader *reader = casereader_clone (input);
        for (; (c = casereader_read (reader)); case_unref (c))
          {
-           const double w = weight ? case_data (c, weight)->f: 1.0;
+           const double w = weight ? case_num (c, weight) : 1.0;
            for (v = 0; v < otp->n_vars; ++v)
              {
                const struct variable *var = otp->vars[v];
@@ -232,7 +232,7 @@ runs_execute (const struct dataset *ds,
                const double x = val->f;
                struct run_state *run = &rs[v];
 
-               if ( var_is_value_missing (var, val, exclude))
+               if (var_is_value_missing (var, val) & exclude)
                  continue;
 
                run->cutpoint += x * w;
@@ -260,7 +260,7 @@ runs_execute (const struct dataset *ds,
 
   for (; (c = casereader_read (input)); case_unref (c))
     {
-      const double w = weight ? case_data (c, weight)->f: 1.0;
+      const double w = weight ? case_num (c, weight) : 1.0;
 
       for (v = 0; v < otp->n_vars; ++v)
        {
@@ -271,7 +271,7 @@ runs_execute (const struct dataset *ds,
          double d = x - run->cutpoint;
          short sign = 0;
 
-         if ( var_is_value_missing (var, val, exclude))
+         if (var_is_value_missing (var, val) & exclude)
            continue;
 
          if (d >= 0)
@@ -346,7 +346,7 @@ show_runs_result (const struct runs_test *rt, const struct run_state *rs, const
         run->n,
         run->runs,
         z,
-        2.0 * (1.0 - gsl_cdf_ugaussian_P (z)),
+        2.0 * (1.0 - gsl_cdf_ugaussian_P (fabs (z))),
       };
 
       for (int row = 0; row < sizeof rows / sizeof *rows; row++)