X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fstats%2Froc.c;h=d011bf547e7a20fd4ab4acf9699d6e0db941ab99;hb=9cb6dec84b34ad0b8d424e2e023b66ab2d84e5c1;hp=dd2093674b16c34ecb8db3702687b6b38cd5245e;hpb=2462550d05c7cecd168815ef82fa7d25d5855be2;p=pspp diff --git a/src/language/stats/roc.c b/src/language/stats/roc.c index dd2093674b..d011bf547e 100644 --- a/src/language/stats/roc.c +++ b/src/language/stats/roc.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,27 +16,27 @@ #include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "language/stats/roc.h" #include +#include "data/casegrouper.h" +#include "data/casereader.h" +#include "data/casewriter.h" +#include "data/dataset.h" +#include "data/dictionary.h" +#include "data/format.h" +#include "data/subcase.h" +#include "language/command.h" +#include "language/lexer/lexer.h" +#include "language/lexer/value-parser.h" +#include "language/lexer/variable-parser.h" +#include "libpspp/misc.h" +#include "math/sort.h" +#include "output/chart-item.h" +#include "output/charts/roc-chart.h" +#include "output/tab.h" + #include "gettext.h" #define _(msgid) gettext (msgid) #define N_(msgid) msgid @@ -49,6 +49,7 @@ struct cmd_roc const struct variable *state_var; union value state_value; + size_t state_var_width; /* Plot the roc curve */ bool curve; @@ -94,8 +95,9 @@ cmd_roc (struct lexer *lexer, struct dataset *ds) roc.neg = roc.neg_weighted = 0; roc.dict = dataset_dict (ds); roc.state_var = NULL; + roc.state_var_width = -1; - lex_match (lexer, '/'); + lex_match (lexer, T_SLASH); if (!parse_variables_const (lexer, dict, &roc.vars, &roc.n_vars, PV_APPEND | PV_NO_DUPLICATE | PV_NUMERIC)) goto error; @@ -107,28 +109,28 @@ cmd_roc (struct lexer *lexer, struct dataset *ds) roc.state_var = parse_variable (lexer, dict); - if ( !lex_force_match (lexer, '(')) + if ( !lex_force_match (lexer, T_LPAREN)) { goto error; } - value_init (&roc.state_value, var_get_width (roc.state_var)); - parse_value (lexer, &roc.state_value, var_get_width (roc.state_var)); + roc.state_var_width = var_get_width (roc.state_var); + value_init (&roc.state_value, roc.state_var_width); + parse_value (lexer, &roc.state_value, roc.state_var); - if ( !lex_force_match (lexer, ')')) + if ( !lex_force_match (lexer, T_RPAREN)) { goto error; } - - while (lex_token (lexer) != '.') + while (lex_token (lexer) != T_ENDCMD) { - lex_match (lexer, '/'); + lex_match (lexer, T_SLASH); if (lex_match_id (lexer, "MISSING")) { - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { if (lex_match_id (lexer, "INCLUDE")) { @@ -147,15 +149,15 @@ cmd_roc (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "PLOT")) { - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); if (lex_match_id (lexer, "CURVE")) { roc.curve = true; - if (lex_match (lexer, '(')) + if (lex_match (lexer, T_LPAREN)) { roc.reference = true; lex_force_match_id (lexer, "REFERENCE"); - lex_force_match (lexer, ')'); + lex_force_match (lexer, T_RPAREN); } } else if (lex_match_id (lexer, "NONE")) @@ -170,8 +172,8 @@ cmd_roc (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "PRINT")) { - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { if (lex_match_id (lexer, "SE")) { @@ -190,12 +192,12 @@ cmd_roc (struct lexer *lexer, struct dataset *ds) } else if (lex_match_id (lexer, "CRITERIA")) { - lex_match (lexer, '='); - while (lex_token (lexer) != '.' && lex_token (lexer) != '/') + lex_match (lexer, T_EQUALS); + while (lex_token (lexer) != T_ENDCMD && lex_token (lexer) != T_SLASH) { if (lex_match_id (lexer, "CUTOFF")) { - lex_force_match (lexer, '('); + lex_force_match (lexer, T_LPAREN); if (lex_match_id (lexer, "INCLUDE")) { roc.exclude = MV_SYSTEM; @@ -209,11 +211,11 @@ cmd_roc (struct lexer *lexer, struct dataset *ds) lex_error (lexer, NULL); goto error; } - lex_force_match (lexer, ')'); + lex_force_match (lexer, T_RPAREN); } else if (lex_match_id (lexer, "TESTPOS")) { - lex_force_match (lexer, '('); + lex_force_match (lexer, T_LPAREN); if (lex_match_id (lexer, "LARGE")) { roc.invert = false; @@ -227,19 +229,19 @@ cmd_roc (struct lexer *lexer, struct dataset *ds) lex_error (lexer, NULL); goto error; } - lex_force_match (lexer, ')'); + lex_force_match (lexer, T_RPAREN); } else if (lex_match_id (lexer, "CI")) { - lex_force_match (lexer, '('); + lex_force_match (lexer, T_LPAREN); lex_force_num (lexer); roc.ci = lex_number (lexer); lex_get (lexer); - lex_force_match (lexer, ')'); + lex_force_match (lexer, T_RPAREN); } else if (lex_match_id (lexer, "DISTRIBUTION")) { - lex_force_match (lexer, '('); + lex_force_match (lexer, T_LPAREN); if (lex_match_id (lexer, "FREE")) { roc.bi_neg_exp = false; @@ -253,7 +255,7 @@ cmd_roc (struct lexer *lexer, struct dataset *ds) lex_error (lexer, NULL); goto error; } - lex_force_match (lexer, ')'); + lex_force_match (lexer, T_RPAREN); } else { @@ -272,13 +274,14 @@ cmd_roc (struct lexer *lexer, struct dataset *ds) if ( ! run_roc (ds, &roc)) goto error; - value_destroy (&roc.state_value, var_get_width (roc.state_var)); + if ( roc.state_var) + value_destroy (&roc.state_value, roc.state_var_width); free (roc.vars); return CMD_SUCCESS; error: if ( roc.state_var) - value_destroy (&roc.state_value, var_get_width (roc.state_var)); + value_destroy (&roc.state_value, roc.state_var_width); free (roc.vars); return CMD_FAILURE; } @@ -996,7 +999,7 @@ show_auc (struct roc_state *rs, const struct cmd_roc *roc) { tab_text (tbl, 0, 2 + i, TAT_TITLE, var_to_string (roc->vars[i])); - tab_double (tbl, n_cols - n_fields, 2 + i, 0, rs[i].auc, NULL); + tab_double (tbl, n_cols - n_fields, 2 + i, 0, rs[i].auc, NULL, RC_OTHER); if ( roc->print_se ) { @@ -1015,22 +1018,22 @@ show_auc (struct roc_state *rs, const struct cmd_roc *roc) tab_double (tbl, n_cols - 4, 2 + i, 0, se, - NULL); + NULL, RC_OTHER); ci = 1 - roc->ci / 100.0; yy = gsl_cdf_gaussian_Qinv (ci, se) ; tab_double (tbl, n_cols - 2, 2 + i, 0, rs[i].auc - yy, - NULL); + NULL, RC_OTHER); tab_double (tbl, n_cols - 1, 2 + i, 0, rs[i].auc + yy, - NULL); + NULL, RC_OTHER); tab_double (tbl, n_cols - 3, 2 + i, 0, 2.0 * gsl_cdf_ugaussian_Q (fabs ((rs[i].auc - 0.5 ) / sd_0_5)), - NULL); + NULL, RC_PVALUE); } } @@ -1077,11 +1080,11 @@ show_summary (const struct cmd_roc *roc) tab_text (tbl, 0, 3, TAB_LEFT, _("Negative")); - tab_double (tbl, 1, 2, 0, roc->pos, &F_8_0); - tab_double (tbl, 1, 3, 0, roc->neg, &F_8_0); + tab_double (tbl, 1, 2, 0, roc->pos, NULL, RC_INTEGER); + tab_double (tbl, 1, 3, 0, roc->neg, NULL, RC_INTEGER); - tab_double (tbl, 2, 2, 0, roc->pos_weighted, 0); - tab_double (tbl, 2, 3, 0, roc->neg_weighted, 0); + tab_double (tbl, 2, 2, 0, roc->pos_weighted, NULL, RC_OTHER); + tab_double (tbl, 2, 3, 0, roc->neg_weighted, NULL, RC_OTHER); tab_submit (tbl); } @@ -1158,10 +1161,10 @@ show_coords (struct roc_state *rs, const struct cmd_roc *roc) ); tab_double (tbl, n_cols - 3, x, 0, case_data_idx (cc, ROC_CUTPOINT)->f, - var_get_print_format (roc->vars[i])); + var_get_print_format (roc->vars[i]), RC_OTHER); - tab_double (tbl, n_cols - 2, x, 0, se, NULL); - tab_double (tbl, n_cols - 1, x, 0, 1 - sp, NULL); + tab_double (tbl, n_cols - 2, x, 0, se, NULL, RC_OTHER); + tab_double (tbl, n_cols - 1, x, 0, 1 - sp, NULL, RC_OTHER); } casereader_destroy (r);