X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fregression_export.h;h=083064d163f5be6a84f0c0f873285c3ed908e65e;hb=f3cf52b51e6d89e94190de22b1fa813e8d3746f7;hp=e7f880e331d4409f5b0a688aa6e3edca777a3456;hpb=6331aa1af5f813fbe463fd0970c39a35c5243332;p=pspp diff --git a/src/regression_export.h b/src/regression_export.h index e7f880e331..083064d163 100644 --- a/src/regression_export.h +++ b/src/regression_export.h @@ -39,7 +39,8 @@ const char reg_header[] = "#ifndef REG_EXPORT_COMMENTS_H\n#define REG_EXPORT_COM const char reg_preamble[] = "/*\n This program contains functions which return estimates\n" " and confidence intervals for a linear model. The EXPORT subcommand\n" -" of the REGRESSION procedure of GNU PSPP generated this program.\n*/\n\n"; +" of the REGRESSION procedure of GNU PSPP generated this program.\n*/\n\n" +"#include \n#include \n#define PSPP_REG_MAXLEN 1024\n\n"; const char reg_mean_cmt[] = "/*\n Estimate the mean of Y, the dependent variable for\n" " the linear model of the form \n\n" @@ -115,4 +116,33 @@ const char reg_export_prediction_interval_3[] = " + pspp_reg_variance (var_vals, "\n\tresult *= pspp_reg_t_quantile ((1.0 + p) / 2.0);\n\t" "result += pspp_reg_estimate (var_vals, var_names);\n\treturn result;\n}\n"; +/* + Change categorical values to binary vectors. The routine will use + an encoding in which a categorical variable with n values is mapped + to a vector with n-1 entries. Value 0 is mapped to the zero vector, + value 1 is mapped to a vector whose first entry is 1 and all others are + 0, etc. For example, if a variable can have 'a', 'b' or 'c' as values, + then the value 'a' will be encoded as (0,0), 'b' as (1,0) and 'c' as + (0,1). If the design matrix used to create the model used a different + encoding, then the function pspp_reg_categorical_encode () will return + a vector which does not match its categorical value in the model. + */ +const char reg_export_categorical_encode_1[] = "struct pspp_reg_categorical_variable\n" +"{\n\tchar * name;\n\tsize_t n_vals;\n\tchar *values[1024];\n};\n\n" +"/*\n This function returns the binary vector which corresponds to the value\n" +" of the categorical variable stored in 'value'. The name of the variable is\n" +" stored in the 'var' argument. Notice the values stored in the\n" +" pspp_categorical_variable structures all end with a space character.\n" +" That means the values of the categorical variables you pass to any function\n" +" in this program should also end with a space character.\n*/\n" +"static\ndouble * pspp_reg_get_value_vector (char *var, char *value)\n{\n\tdouble *result;\n\t" +"int i;\n\t"; + +const char reg_export_categorical_encode_2[] = "int v_index = 0;\n\t" +"while (v_index < n_vars && strncmp (var, varlist[i]->name, PSPP_REG_MAXLEN) != 0)\n\t{\n\t\t" +"v_index++;\n\t}\n\tresult = (double *) malloc (varlist[v_index]->n_vals * sizeof (*result));\n\t" +"for (i = 0; i < varlist[v_index]->n_vals; i++)\n\t{\n\t\t" +"if (strncmp ( (varlist[v_index]->values)[i], value, PSPP_REG_MAXLEN) == 0)\n\t\t{\n\t\t\t" +"result[i] = 1.0;\n\t\t}\n\t\telse result[i] = 0.0;\n\t}\n\n\t" +"return result;\n}\n\n"; #endif