[Top][All Lists]
[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: |
Tue, 20 Dec 2005 04:05:20 +0000 |
CVSROOT: /sources/pspp
Module name: pspp
Branch:
Changes by: Jason H Stover <address@hidden> 05/12/20 04:05:20
Modified files:
src : regression.q
Log message:
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/regression.q.diff?tr1=1.25&tr2=1.26&r1=text&r2=text
Patches:
Index: pspp/src/regression.q
diff -u pspp/src/regression.q:1.25 pspp/src/regression.q:1.26
--- pspp/src/regression.q:1.25 Sun Dec 18 18:48:44 2005
+++ pspp/src/regression.q Tue Dec 20 04:05:20 2005
@@ -473,6 +473,31 @@
statistics_keyword_output (reg_stats_selection, keywords[selection], c);
}
static void
+reg_print_depvars (FILE *fp, pspp_linreg_cache *c)
+{
+ int i;
+ struct pspp_linreg_coeff coeff;
+
+ fprintf (fp, "char *model_depvars[%d] = {", c->n_indeps);
+ for (i = 1; i < c->n_indeps; i++)
+ {
+ coeff = c->coeff[i];
+ fprintf (fp, "\"%s\",\n\t\t", coeff.v->name);
+ }
+ coeff = c->coeff[i];
+ fprintf (fp, "\"%s\"};\n\t", coeff.v->name);
+}
+static void
+reg_print_getvar (FILE *fp, pspp_linreg_cache *c)
+{
+ fprintf (fp, "static int\npspp_reg_getvar (char *v_name)\n{\n\t");
+ fprintf (fp, "int i;\n\tint n_vars = %d;\n\t",c->n_indeps);
+ reg_print_depvars (fp, c);
+ fprintf (fp, "for (i = 0; i < n_vars; i++)\n\t{\n\t\t");
+ fprintf (fp, "if (strcmp (v_name, model_depvars[i]) == 0)\n\t\t{\n\t\t\t");
+ fprintf (fp, "return i;\n\t\t}\n\t}\n}\n");
+}
+static void
subcommand_export (int export, pspp_linreg_cache *c)
{
FILE *fp;
@@ -487,15 +512,10 @@
fp = fopen (handle_get_filename (model_file), "w");
fprintf (fp, "%s", reg_preamble);
fprintf (fp, "#include <string.h>\n\n");
+ reg_print_getvar (fp, c);
fprintf (fp, "%s", reg_mean_cmt);
- fprintf (fp, "double\npspp_reg_estimate (const double *var_vals, const
char *var_names[])\n{\n\tchar *model_depvars[%d] = {", c->n_indeps);
- for (i = 1; i < c->n_indeps; i++)
- {
- coeff = c->coeff[i];
- fprintf (fp, "\"%s\",\n\t\t", coeff.v->name);
- }
- coeff = c->coeff[i];
- fprintf (fp, "\"%s\"};\n\t", coeff.v->name);
+ fprintf (fp, "double\npspp_reg_estimate (const double *var_vals,");
+ fprintf (fp, "const char *var_names[])\n{\n\t");
fprintf (fp, "double model_coeffs[%d] = {", c->n_indeps);
for (i = 1; i < c->n_indeps; i++)
{
@@ -508,10 +528,11 @@
fprintf (fp, "double estimate = %.15e;\n\t", coeff.estimate);
fprintf (fp, "int i;\n\tint j;\n\n\t");
fprintf (fp, "for (i = 0; i < %d; i++)\n\t", c->n_indeps);
- fprintf (fp, "{\n\t\tfor (j = 0; j < %d; j++)\n\t\t", c->n_indeps);
- fprintf (fp, "{\n\t\t\tif (strcmp (var_names[i], model_depvars[j]) ==
0)\n");
- fprintf (fp, "\t\t\t{\n\t\t\t\testimate += var_vals[i] *
model_coeffs[j];\n");
- fprintf (fp, "\t\t\t}\n\t\t}\n\t}\n\treturn estimate;\n}\n");
+ fprintf (fp, "{\n\t\tj = pspp_reg_getvar (var_names[i]);\n");
+ fprintf (fp, "\t\testimate += var_vals[j] * model_coeffs[j];\n");
+ fprintf (fp, "\t}\n\t\n\treturn estimate;\n}\n\n");
+ fprintf (fp, "double\npspp_reg_standard_error (const double *var_vals,");
+ fprintf (fp, "const char *var_names[])\n{\n\t");
fclose (fp);
}
}
- [Pspp-cvs] pspp/src regression.q, Jason H Stover, 2005/12/15
- [Pspp-cvs] pspp/src regression.q, Jason H Stover, 2005/12/15
- [Pspp-cvs] pspp/src regression.q, Jason H Stover, 2005/12/15
- [Pspp-cvs] pspp/src regression.q, Jason H Stover, 2005/12/16
- [Pspp-cvs] pspp/src regression.q, Jason H Stover, 2005/12/17
- [Pspp-cvs] pspp/src regression.q, Jason H Stover, 2005/12/18
- [Pspp-cvs] pspp/src regression.q, Jason H Stover, 2005/12/18
- [Pspp-cvs] pspp/src regression.q,
Jason H Stover <=
- [Pspp-cvs] pspp/src regression.q, Jason H Stover, 2005/12/26
- [Pspp-cvs] pspp/src regression.q, Jason H Stover, 2005/12/29
- [Pspp-cvs] pspp/src regression.q, Jason H Stover, 2005/12/30
- [Pspp-cvs] pspp/src regression.q, Jason H Stover, 2005/12/31