1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include <data/procedure.h>
21 #include <language/lexer/variable-parser.h>
22 #include <language/lexer/value-parser.h>
23 #include <language/lexer/lexer.h>
25 #include <data/casegrouper.h>
26 #include <data/casereader.h>
29 #define _(msgid) gettext (msgid)
30 #define N_(msgid) msgid
35 const struct variable **vars;
37 struct variable *state_var ;
38 union value state_value;
40 /* Plot the roc curve */
42 /* Plot the reference line */
49 bool bi_neg_exp; /* True iff the bi-negative exponential critieria
51 enum mv_class exclude;
53 bool invert ; /* True iff a smaller test result variable indicates
58 static int run_roc (struct dataset *ds, struct cmd_roc *roc);
61 cmd_roc (struct lexer *lexer, struct dataset *ds)
64 const struct dictionary *dict = dataset_dict (ds);
69 roc.print_coords = false;
72 roc.reference = false;
74 roc.bi_neg_exp = false;
77 if (!parse_variables_const (lexer, dict, &roc.vars, &roc.n_vars,
78 PV_APPEND | PV_NO_DUPLICATE | PV_NUMERIC))
81 if ( ! lex_force_match (lexer, T_BY))
86 roc.state_var = parse_variable (lexer, dict);
88 if ( !lex_force_match (lexer, '('))
93 parse_value (lexer, &roc.state_value, var_get_width (roc.state_var));
96 if ( !lex_force_match (lexer, ')'))
102 while (lex_token (lexer) != '.')
104 lex_match (lexer, '/');
105 if (lex_match_id (lexer, "MISSING"))
107 lex_match (lexer, '=');
108 while (lex_token (lexer) != '.' && lex_token (lexer) != '/')
110 if (lex_match_id (lexer, "INCLUDE"))
112 roc.exclude = MV_SYSTEM;
114 else if (lex_match_id (lexer, "EXCLUDE"))
116 roc.exclude = MV_ANY;
120 lex_error (lexer, NULL);
125 else if (lex_match_id (lexer, "PLOT"))
127 lex_match (lexer, '=');
128 if (lex_match_id (lexer, "CURVE"))
131 if (lex_match (lexer, '('))
133 roc.reference = true;
134 lex_force_match_id (lexer, "REFERENCE");
135 lex_force_match (lexer, ')');
138 else if (lex_match_id (lexer, "NONE"))
144 lex_error (lexer, NULL);
148 else if (lex_match_id (lexer, "PRINT"))
150 lex_match (lexer, '=');
151 while (lex_token (lexer) != '.' && lex_token (lexer) != '/')
153 if (lex_match_id (lexer, "SE"))
157 else if (lex_match_id (lexer, "COORDINATES"))
159 roc.print_coords = true;
163 lex_error (lexer, NULL);
168 else if (lex_match_id (lexer, "CRITERIA"))
170 lex_match (lexer, '=');
171 while (lex_token (lexer) != '.' && lex_token (lexer) != '/')
173 if (lex_match_id (lexer, "CUTOFF"))
175 lex_force_match (lexer, '(');
176 if (lex_match_id (lexer, "INCLUDE"))
178 roc.exclude = MV_SYSTEM;
180 else if (lex_match_id (lexer, "EXCLUDE"))
182 roc.exclude = MV_USER | MV_SYSTEM;
186 lex_error (lexer, NULL);
189 lex_force_match (lexer, ')');
191 else if (lex_match_id (lexer, "TESTPOS"))
193 lex_force_match (lexer, '(');
194 if (lex_match_id (lexer, "LARGE"))
198 else if (lex_match_id (lexer, "SMALL"))
204 lex_error (lexer, NULL);
207 lex_force_match (lexer, ')');
209 else if (lex_match_id (lexer, "CI"))
211 lex_force_match (lexer, '(');
212 lex_force_num (lexer);
213 roc.ci = lex_number (lexer);
215 lex_force_match (lexer, ')');
217 else if (lex_match_id (lexer, "DISTRIBUTION"))
219 lex_force_match (lexer, '(');
220 if (lex_match_id (lexer, "FREE"))
222 roc.bi_neg_exp = false;
224 else if (lex_match_id (lexer, "NEGEXPO"))
226 roc.bi_neg_exp = true;
230 lex_error (lexer, NULL);
233 lex_force_match (lexer, ')');
237 lex_error (lexer, NULL);
244 lex_error (lexer, NULL);
258 do_roc (struct cmd_roc *roc, struct casereader *group, struct dictionary *dict);
262 run_roc (struct dataset *ds, struct cmd_roc *roc)
264 struct dictionary *dict = dataset_dict (ds);
266 struct casereader *group;
268 struct casegrouper *grouper = casegrouper_create_splits (proc_open (ds), dict);
269 while (casegrouper_get_next_group (grouper, &group))
271 do_roc (roc, group, dataset_dict (ds));
272 casereader_destroy (group);
274 ok = casegrouper_destroy (grouper);
275 ok = proc_commit (ds) && ok;
282 do_roc (struct cmd_roc *roc, struct casereader *group, struct dictionary *dict)