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, 30 Dec 2005 04:59:49 +0000

CVSROOT:        /sources/pspp
Module name:    pspp
Branch:         
Changes by:     Jason H Stover <address@hidden> 05/12/30 04:59:49

Modified files:
        src            : regression.q 

Log message:
        Added categorical variable support for model export

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

Patches:
Index: pspp/src/regression.q
diff -u pspp/src/regression.q:1.28 pspp/src/regression.q:1.29
--- pspp/src/regression.q:1.28  Thu Dec 29 18:02:14 2005
+++ pspp/src/regression.q       Fri Dec 30 04:59:49 2005
@@ -472,6 +472,44 @@
   statistics_keyword_output (reg_stats_tol, keywords[tol], c);
   statistics_keyword_output (reg_stats_selection, keywords[selection], c);
 }
+
+static void
+reg_print_categorical_encoding (FILE *fp, pspp_linreg_cache *c)
+{
+  int i;
+  size_t j;
+  struct pspp_linreg_coeff coeff;
+  union value *val;
+  
+  fprintf (fp, "%s", reg_export_categorical_encode_1);
+
+  for (i = 1; i < c->n_indeps; i++)   /* c->coeff[0] is the intercept. */
+    {
+      coeff = c->coeff[i];
+      if (coeff.v->type == ALPHA)
+       {
+         fprintf (fp, "struct pspp_reg_categorical_variable %s;\n\t", 
coeff.v->name);
+       }
+    }
+  for (i = 1; i < c->n_indeps; i++)
+    {
+      coeff = c->coeff[i];
+      if (coeff.v->type == ALPHA)
+       {
+         fprintf (fp, "%s.name = \"%s\";\n\t", coeff.v->name, coeff.v->name);
+         fprintf (fp, "%s.n_vals = %d;\n\t", coeff.v->name, 
coeff.v->obs_vals->n_categories);
+         fprintf (fp, "%s.values = {", coeff.v->name);
+         for (j = 0; j < coeff.v->obs_vals->n_categories - 1; j++)
+           {
+             val = cat_subscript_to_value ( (const size_t) j, coeff.v);
+             fprintf (fp, "\"%s\",\n\t\t", val->s);
+           }
+         val = cat_subscript_to_value ( (const size_t) j, coeff.v);
+         fprintf (fp, "\"%s\"};\n\n\t", val->s);
+       }
+    }
+}
+
 static void
 reg_print_depvars (FILE *fp, pspp_linreg_cache *c)
 {
@@ -517,6 +555,7 @@
       fprintf (fp, "%s", reg_preamble);
       fprintf (fp, "#include <string.h>\n#include <math.h>\n\n");
       reg_print_getvar (fp, c);
+      reg_print_categorical_encoding (fp, c);
       fprintf (fp, "%s", reg_export_t_quantiles_1);
       increment = 0.5 / (double) increment;
       for (i = 0; i < n_quantiles - 1; i++)




reply via email to

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