396f3905cc4c18cf50a765c3c7bbaf3d6c1319b8
[pspp-builds.git] / src / reg_export_comments.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_preamble[] =  "/*\n   This program contains functions which return estimates\n"
28 "   and confidence intervals for a linear model. The EXPORT subcommand\n"
29 "   of the REGRESSION procedure of GNU PSPP generated this program.\n*/\n\n";
30
31 const char reg_mean_cmt[] =  "/*\n   Estimate the mean of Y, the dependent variable for\n"
32 "   the linear model of the form \n\n"
33 "      Y = b0 + b1 * X1 + b2 * X2 + ... + bk * Xk + error\n\n"
34 "   where X1, ..., Xk are the independent variables\n"
35 "   whose values are stored in var_vals and whose names, \n"
36 "   as known by PSPP, are stored in var_names. The estimated \n"
37 "   regression coefficients (i.e., the estimates of b0,...,bk) \n"
38 "   are stored in model_coeffs.\n*/\n";
39
40 const char reg_getvar[] = "{\n\t\tj = pspp_reg_getvar (var_names[i]);\n"
41 "\t\testimate += var_vals[j] * model_coeffs[j];\n"
42 "\t}\n\t\n\treturn estimate;\n}\n\n"
43 "/*\n    Variance of an estimated mean of this form:\n\t"
44 "Y = b0 + b1 * X1 + ... + bk * Xk\n    where X1,...Xk are the dependent variables,"
45 " stored in\n    var_vals and b0,...,bk are the estimated regression coefficients.\n*/\n"
46 "double\npspp_reg_variance (const double *var_vals, "
47 "const char *var_names[])\n{\n\t";
48
49 const char reg_export_t_quantiles_1[] = "/*\n    Quantiles for the T distribution.\n*/\n"
50 "static int\npspp_reg_t_quantile "
51 "(double prob)\n{\n\n\tint i;\n\tdouble quantiles[] = {\n\t\t";
52
53 const char reg_export_t_quantiles_2[] = "i = (int) 100.0 * prob;\n\treturn quantiles[i];\n}\n";
54
55 const char reg_variance[] = "double result = 0.0;\n\n\tfor(i = 0; i < n_vars; i++)\n\t"
56 "{\n\t\tj = pspp_reg_getvar (var_names[i]);\n\t\t"
57 "unshuffled_vals[j] = var_vals[i];\n\t}\n\t"
58 "for (i = 0; i < n_vars; i++)\n\t"
59 "{\n\t\tresult += cov[i][i] * unshuffled_vals[i] * unshuffled_vals[i];\n\t\t"
60 "for (j = i + 1; j < n_vars; j++)\n\t\t{\n\t\t\t"
61 "result += 2.0 * cov[i][j] * unshuffled_vals[i] * unshuffled_vals[j];"
62 "\n\t\t}\n\t}\n\treturn result;\n}\n";
63
64 const char reg_export_confidence_interval[] = "/*\n    Upper confidence limit for an "
65 "estimated mean b0 + b1 * X1 + ... + bk * Xk.\n    The confidence interval is a "
66 "100 * p percent confidence interval.\n*/\n"
67 "double pspp_reg_confidence_interval_U "
68 "(const double *var_vals, const char *var_names[], double p)\n{\n\t"
69 "double result;\n\t"
70 "result = sqrt (pspp_reg_variance (var_vals, var_names);\n\treturn result;\n\t"
71 "result *= pspp_reg_t_quantile ((1.0 + p) / 2.0);\n\t"
72 "result += pspp_reg_estimate (var_vals, var_names);\n}\n"
73 "/*\n    Lower confidence limit for an "
74 "estimated mean b0 + b1 * X1 + ... + bk * Xk.\n    The confidence interval is a "
75 "100 * p percent confidence interval.\n*/\n"
76 "double pspp_reg_confidence_interval_L "
77 "(const double *var_vals, const char *var_names[], double p)\n{\n\t"
78 "double result;\n\t"
79 "result = -sqrt (pspp_reg_variance (var_vals, var_names);\n\treturn result;\n\t"
80 "result *= pspp_reg_t_quantile ((1.0 + p) / 2.0);\n\t"
81 "result += pspp_reg_estimate (var_vals, var_names);\n}\n";
82
83 const char reg_export_prediction_interval[] = "/*\n    Upper prediction limit for a "
84 "predicted value b0 + b1 * X1 + ... + bk * Xk.\n    The prediction interval is a "
85 "100 * p percent prediction interval.\n*/\n"
86 "double pspp_reg_prediction_interval_U "
87 "(const double *var_vals, const char *var_names[], double p)\n{\n\t"
88 "double result;\n\t"
89 "result = 1 + sqrt (pspp_reg_variance (var_vals, var_names);\n\treturn result;\n\t"
90 "result *= pspp_reg_t_quantile ((1.0 + p) / 2.0);\n\t"
91 "result += pspp_reg_estimate (var_vals, var_names);\n}\n"
92 "/*\n    Lower prediction limit for a "
93 "predicted value b0 + b1 * X1 + ... + bk * Xk.\n    The prediction interval is a "
94 "100 * p percent prediction interval.\n*/\n"
95 "double pspp_reg_prediction_interval_L "
96 "(const double *var_vals, const char *var_names[], double p)\n{\n\t"
97 "double result;\n\t"
98 "result = -1.0 - sqrt (pspp_reg_variance (var_vals, var_names);\n\treturn result;\n\t"
99 "result *= pspp_reg_t_quantile ((1.0 + p) / 2.0);\n\t"
100 "result += pspp_reg_estimate (var_vals, var_names);\n}\n";
101
102 #endif