1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2009, 2011 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/>. */
19 #include "output/charts/roc-chart.h"
21 #include "data/case.h"
22 #include "data/casereader.h"
23 #include "language/commands/roc.h"
24 #include "output/cairo-chart.h"
27 #define _(msgid) gettext (msgid)
30 xrchart_draw_roc (const struct chart *chart, cairo_t *cr,
31 struct xrchart_geometry *geom)
33 const struct roc_chart *rc = to_roc_chart (chart);
36 xrchart_write_title (cr, geom, _("ROC Curve"));
37 xrchart_write_xlabel (cr, geom, _("1 - Specificity"));
38 xrchart_write_ylabel (cr, geom, _("Sensitivity"));
40 if (! xrchart_write_xscale (cr, geom, 0, 1))
42 if (! xrchart_write_yscale (cr, geom, 0, 1))
47 xrchart_line (cr, geom, 1.0, 0,
52 for (i = 0; i < rc->n_vars; ++i)
54 const struct roc_var *rv = &rc->vars[i];
55 struct casereader *r = casereader_clone (rv->cutpoint_reader);
58 xrchart_vector_start (cr, geom, rv->name);
59 for (; (cc = casereader_read (r)) != NULL; case_unref (cc))
61 double se = case_num_idx (cc, ROC_TP);
62 double sp = case_num_idx (cc, ROC_TN);
64 se /= case_num_idx (cc, ROC_FN) + case_num_idx (cc, ROC_TP);
65 sp /= case_num_idx (cc, ROC_TN) + case_num_idx (cc, ROC_FP);
67 xrchart_vector (cr, geom, 1 - sp, se);
69 xrchart_vector_end (cr, geom);
70 casereader_destroy (r);
73 xrchart_write_legend (cr, geom);