- assert (c != NULL);
- assert (model_file != NULL);
- fp = fopen (fh_get_file_name (model_file), "w");
- assert (fp != NULL);
- fprintf (fp, "%s", reg_preamble);
- reg_print_getvar (fp, c);
- if (reg_has_categorical (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++)
- {
- tmp = 0.5 + 0.005 * (double) i;
- fprintf (fp, "%.15e,\n\t\t",
- gsl_cdf_tdist_Pinv (tmp, c->n_obs - c->n_indeps));
- }
- fprintf (fp, "%.15e};\n\t",
- gsl_cdf_tdist_Pinv (.9995, c->n_obs - c->n_indeps));
- fprintf (fp, "%s", reg_export_t_quantiles_2);
- fprintf (fp, "%s", reg_mean_cmt);
- 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++)
- {
- coeff = c->coeff[i];
- fprintf (fp, "%.15e,\n\t\t", coeff->estimate);
- }
- coeff = c->coeff[i];
- fprintf (fp, "%.15e};\n\t", coeff->estimate);
- coeff = c->coeff[0];
- 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, "%s", reg_getvar);
- fprintf (fp, "const double cov[%d][%d] = {\n\t", c->n_coeffs,
- c->n_coeffs);
- for (i = 0; i < c->cov->size1 - 1; i++)
- {
- fprintf (fp, "{");
- for (j = 0; j < c->cov->size2 - 1; j++)
- {
- fprintf (fp, "%.15e, ", gsl_matrix_get (c->cov, i, j));
- }
- fprintf (fp, "%.15e},\n\t", gsl_matrix_get (c->cov, i, j));
- }
- fprintf (fp, "{");
- for (j = 0; j < c->cov->size2 - 1; j++)
- {
- fprintf (fp, "%.15e, ",
- gsl_matrix_get (c->cov, c->cov->size1 - 1, j));
- }
- fprintf (fp, "%.15e}\n\t",
- gsl_matrix_get (c->cov, c->cov->size1 - 1, c->cov->size2 - 1));
- fprintf (fp, "};\n\tint n_vars = %d;\n\tint i;\n\tint j;\n\t",
- c->n_indeps);
- fprintf (fp, "double unshuffled_vals[%d];\n\t", c->n_indeps);
- fprintf (fp, "%s", reg_variance);
- fprintf (fp, "%s", reg_export_confidence_interval);
- tmp = c->mse * c->mse;
- fprintf (fp, "%s %.15e", reg_export_prediction_interval_1, tmp);
- fprintf (fp, "%s %.15e", reg_export_prediction_interval_2, tmp);
- fprintf (fp, "%s", reg_export_prediction_interval_3);
- fclose (fp);
- fp = fopen ("pspp_model_reg.h", "w");
- fprintf (fp, "%s", reg_header);
- fclose (fp);