GLM: Do not print the intercept if the model is unbalanced
[pspp] / src / math / categoricals.c
index d89dfdbb26b2c583513ff6d266ca4f2ac2e5a032..140542fe02de630b4e3443857532851d2d8b6c23 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010, 2011, 2012, 2014 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -19,6 +19,7 @@
 #include "math/categoricals.h"
 #include "math/interaction.h"
 
+#include <float.h>
 #include <stdio.h>
 
 #include "data/case.h"
@@ -195,6 +196,31 @@ struct categoricals
   const struct payload *payload;
 };
 
+
+bool
+categoricals_isbalanced (const struct categoricals *cat)
+{
+  int i;
+
+  for (i = 0 ; i < cat->n_iap; ++i)
+    {
+      int v;
+      const struct interact_params *iap = &cat->iap[i];
+
+      double oval = -1.0;
+      for (v = 0; v < hmap_count (&iap->ivmap); ++v)
+       {
+         const struct interaction_value *iv = iap->reverse_interaction_value_map[v];
+         if (oval == -1.0)
+           oval = iv->cc;
+         if (oval != iv->cc)
+           return false;
+       }
+    }
+  return true;
+}
+
+
 static void
 categoricals_dump (const struct categoricals *cat)
 {
@@ -216,7 +242,7 @@ categoricals_dump (const struct categoricals *cat)
        }
       printf ("\n");
 
-      printf ("Number of interactions %d\n", cat->n_iap);
+      printf ("Number of interactions %zu\n", cat->n_iap);
       for (i = 0 ; i < cat->n_iap; ++i)
        {
          int v;
@@ -252,7 +278,7 @@ categoricals_dump (const struct categoricals *cat)
 
                  assert (vn->var == var);
 
-                 printf ("%g(%d)", val->f, valn->index);
+                 printf ("%.*g(%d)", DBL_DIG + 1, val->f, valn->index);
                  if (vv < iact->n_vars - 1)
                    printf (", ");
                }