pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] pspp/src regression.q


From: Jason H Stover
Subject: [Pspp-cvs] pspp/src regression.q
Date: Fri, 06 Jan 2006 17:27:16 +0000

CVSROOT:        /sources/pspp
Module name:    pspp
Branch:         
Changes by:     Jason H Stover <address@hidden> 06/01/06 17:27:16

Modified files:
        src            : regression.q 

Log message:
        Added categorical values to coefficient table for clarity

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/regression.q.diff?tr1=1.33&tr2=1.34&r1=text&r2=text

Patches:
Index: pspp/src/regression.q
diff -u pspp/src/regression.q:1.33 pspp/src/regression.q:1.34
--- pspp/src/regression.q:1.33  Wed Jan  4 18:02:14 2006
+++ pspp/src/regression.q       Fri Jan  6 17:27:16 2006
@@ -91,6 +91,57 @@
 int pspp_reg_rc = CMD_SUCCESS;
 
 static void run_regression (const struct casefile *, void *);
+static union value *pspp_reg_coefficient_to_value (const pspp_linreg_cache *,
+                                                  const struct
+                                                  pspp_linreg_coeff *,
+                                                  size_t);
+
+/*
+  Which value of a categorical variable corresponds to the 
+  coefficient? This routine provides the answer IF the
+  categorical variable is encoded in the usual way: The
+  first value maps to the zero vector, the second value to
+  the vector (0, 1, 0, ...), the third value (0, 0, 1, 0, ...),
+  etc.
+ */
+static union value *
+pspp_reg_coefficient_to_value (const pspp_linreg_cache * cache,
+                              const struct pspp_linreg_coeff *coeff,
+                              size_t j)
+{
+  size_t which = 0;
+  int k = 1;                   /* First coefficient is the intercept. */
+  int found = 0;
+  const union value *result;
+  struct pspp_linreg_coeff c;
+
+  assert (cache != NULL);
+  assert (coeff != NULL);
+  assert (coeff->v->type == ALPHA);
+  while (!found && k < cache->n_coeffs)
+    {
+      c = cache->coeff[k];
+      /*
+         compare_var_names returns 0 if the variable
+         names match.
+       */
+      if (!compare_var_names (coeff->v, c.v, NULL))
+       {
+         if (j == k)
+           {
+             found = 1;
+           }
+         else
+           {
+             which++;
+           }
+       }
+      k++;
+    }
+  result = cat_subscript_to_value ((const size_t) which, coeff->v);
+  return result;
+}
+
 /* 
    STATISTICS subcommand output functions.
  */
@@ -161,9 +212,13 @@
   double std_err;
   double beta;
   const char *label;
+  char *tmp;
+  const union value *val;
+  const char *val_s;
   struct tab_table *t;
 
   assert (c != NULL);
+  tmp = xnmalloc (MAX_STRING, sizeof (*tmp));
   n_rows = c->n_coeffs + 2;
 
   t = tab_create (n_cols, n_rows, 0);
@@ -194,7 +249,21 @@
     {
       i = indep_vars[j];
       label = var_to_string (c->coeff[j].v);
-      tab_text (t, 1, j + 1, TAB_CENTER, label);
+      /* Do not overwrite the variable's name. */
+      strncpy (tmp, label, MAX_STRING);
+      if (c->coeff[j].v->type == ALPHA)
+       {
+         /*
+            Append the value associated with this coefficient.
+            This makes sense only if we us the usual binary encoding
+            for that value.
+          */
+         val = pspp_reg_coefficient_to_value (c, &(c->coeff[j]), j);
+         val_s = value_to_string (val, c->coeff[j].v);
+         strncat (tmp, val_s, MAX_STRING);
+       }
+
+      tab_text (t, 1, j + 1, TAB_CENTER, tmp);
       /*
          Regression coefficients.
        */
@@ -226,6 +295,7 @@
     }
   tab_title (t, 0, _("Coefficients"));
   tab_submit (t);
+  free (tmp);
 }
 
 /*
@@ -831,13 +901,13 @@
       lcache->indep_std = gsl_vector_alloc (X->m->size2);
       lcache->depvar = (const struct variable *) depvar;
       /*
-       For large data sets, use QR decomposition.
-      */
+         For large data sets, use QR decomposition.
+       */
       if (n_data > sqrt (n_indep) && n_data > REG_LARGE_DATA)
        {
          lcache->method = PSPP_LINREG_SVD;
        }
-      
+
       /*
          The second pass creates the design matrix.
        */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]