Renamed reg_export_comments.h regression_export.h
[pspp-builds.git] / src / regression_export.h
1 /* PSPP - Comments for C files generated by REGRESSION's EXPORT subcommand.
2    Copyright (C) 2005 Free Software Foundation, Inc.
3    Written by Jason H Stover <jason@sakla.net>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 /*
21   Exported C code for a regression model. The EXPORT subcommand causes PSPP
22   to save a model as a small C program. This file contains some of the code
23   of that saved program.
24  */
25 #ifndef REG_EXPORT_COMMENTS_H
26 #define REG_EXPORT_COMMENTS_H
27 const char reg_header[] = "#ifndef REG_EXPORT_COMMENTS_H\n#define REG_EXPORT_COMMENTS_H\n"
28 "double pspp_reg_estimate (const double *, const char *[]);\n\n"
29 "double pspp_reg_variance (const double *var_vals, const char *[]);\n\n"
30 "double pspp_reg_confidence_interval_U "
31 "(const double *var_vals, const char *var_names[], double p);\n\n"
32 "double pspp_reg_confidence_interval_L "
33 "(const double *var_vals, const char *var_names[], double p);\n\n"
34 "double pspp_reg_prediction_interval_U "
35 "(const double *var_vals, const char *var_names[], double p);\n\n"
36 "double pspp_reg_prediction_interval_L "
37 "(const double *var_vals, const char *var_names[], double p);\n"
38 "#endif\n";
39
40 const char reg_preamble[] =  "/*\n   This program contains functions which return estimates\n"
41 "   and confidence intervals for a linear model. The EXPORT subcommand\n"
42 "   of the REGRESSION procedure of GNU PSPP generated this program.\n*/\n\n";
43
44 const char reg_mean_cmt[] =  "/*\n   Estimate the mean of Y, the dependent variable for\n"
45 "   the linear model of the form \n\n"
46 "      Y = b0 + b1 * X1 + b2 * X2 + ... + bk * Xk + error\n\n"
47 "   where X1, ..., Xk are the independent variables\n"
48 "   whose values are stored in var_vals and whose names, \n"
49 "   as known by PSPP, are stored in var_names. The estimated \n"
50 "   regression coefficients (i.e., the estimates of b0,...,bk) \n"
51 "   are stored in model_coeffs.\n*/\n";
52
53 const char reg_getvar[] = "{\n\t\tj = pspp_reg_getvar (var_names[i]);\n"
54 "\t\testimate += var_vals[j] * model_coeffs[j];\n"
55 "\t}\n\t\n\treturn estimate;\n}\n\n"
56 "/*\n    Variance of an estimated mean of this form:\n\t"
57 "Y = b0 + b1 * X1 + ... + bk * Xk\n    where X1,...Xk are the dependent variables,"
58 " stored in\n    var_vals and b0,...,bk are the estimated regression coefficients.\n*/\n"
59 "double\npspp_reg_variance (const double *var_vals, "
60 "const char *var_names[])\n{\n\t";
61
62 const char reg_export_t_quantiles_1[] = "/*\n    Quantiles for the T distribution.\n*/\n"
63 "static int\npspp_reg_t_quantile "
64 "(double prob)\n{\n\n\tint i;\n\tdouble quantiles[] = {\n\t\t";
65
66 const char reg_export_t_quantiles_2[] = "i = (int) 100.0 * prob;\n\treturn quantiles[i];\n}\n";
67
68 const char reg_variance[] = "double result = 0.0;\n\n\tfor(i = 0; i < n_vars; i++)\n\t"
69 "{\n\t\tj = pspp_reg_getvar (var_names[i]);\n\t\t"
70 "unshuffled_vals[j] = var_vals[i];\n\t}\n\t"
71 "for (i = 0; i < n_vars; i++)\n\t"
72 "{\n\t\tresult += cov[i][i] * unshuffled_vals[i] * unshuffled_vals[i];\n\t\t"
73 "for (j = i + 1; j < n_vars; j++)\n\t\t{\n\t\t\t"
74 "result += 2.0 * cov[i][j] * unshuffled_vals[i] * unshuffled_vals[j];"
75 "\n\t\t}\n\t}\n\treturn result;\n}\n";
76
77 const char reg_export_confidence_interval[] = "/*\n    Upper confidence limit for an "
78 "estimated mean b0 + b1 * X1 + ... + bk * Xk.\n    The confidence interval is a "
79 "100 * p percent confidence interval.\n*/\n"
80 "double pspp_reg_confidence_interval_U "
81 "(const double *var_vals, const char *var_names[], double p)\n{\n\t"
82 "double result;\n\t"
83 "result = sqrt (pspp_reg_variance (var_vals, var_names));\n\t"
84 "result *= pspp_reg_t_quantile ((1.0 + p) / 2.0);\n\t"
85 "result += pspp_reg_estimate (var_vals, var_names);\n\treturn result;\n}\n"
86 "/*\n    Lower confidence limit for an "
87 "estimated mean b0 + b1 * X1 + ... + bk * Xk.\n    The confidence interval is a "
88 "100 * p percent confidence interval.\n*/\n"
89 "double pspp_reg_confidence_interval_L "
90 "(const double *var_vals, const char *var_names[], double p)\n{\n\t"
91 "double result;\n\t"
92 "result = -sqrt (pspp_reg_variance (var_vals, var_names));\n\t"
93 "result *= pspp_reg_t_quantile ((1.0 + p) / 2.0);\n\t"
94 "result += pspp_reg_estimate (var_vals, var_names);\n\treturn result;\n}\n";
95
96 const char reg_export_prediction_interval_1[] = "/*\n    Upper prediction limit for a "
97 "predicted value b0 + b1 * X1 + ... + bk * Xk.\n    The prediction interval is a "
98 "100 * p percent prediction interval.\n*/\n"
99 "double pspp_reg_prediction_interval_U "
100 "(const double *var_vals, const char *var_names[], double p)\n{\n\t"
101 "double result;\n\tresult = sqrt (";
102
103 const char reg_export_prediction_interval_2[] = " + pspp_reg_variance (var_vals, var_names));\n"
104 "\tresult *= pspp_reg_t_quantile ((1.0 + p) / 2.0);\n\t"
105 "result += pspp_reg_estimate (var_vals, var_names);\n\treturn result;\n}\n"
106 "/*\n    Lower prediction limit for a "
107 "predicted value b0 + b1 * X1 + ... + bk * Xk.\n    The prediction interval is a "
108 "100 * p percent prediction interval.\n*/\n"
109 "double pspp_reg_prediction_interval_L "
110 "(const double *var_vals, const char *var_names[], double p)\n{\n\t"
111 "double result;\n\t"
112 "result = -sqrt (";
113
114 const char reg_export_prediction_interval_3[] = " + pspp_reg_variance (var_vals, var_names));"
115 "\n\tresult *= pspp_reg_t_quantile ((1.0 + p) / 2.0);\n\t"
116 "result += pspp_reg_estimate (var_vals, var_names);\n\treturn result;\n}\n";
117
118 #endif