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/stats/roc.h"
24 #include "output/cairo-chart.h"
27 #define _(msgid) gettext (msgid)
30 xrchart_draw_roc (const struct chart_item *chart_item, cairo_t *cr,
31 struct xrchart_geometry *geom)
33 const struct roc_chart *rc = to_roc_chart (chart_item);
36 xrchart_write_title (cr, geom, _("ROC Curve"));
37 xrchart_write_xlabel (cr, geom, _("1 - Specificity"));
38 xrchart_write_ylabel (cr, geom, _("Sensitivity"));
40 xrchart_write_xscale (cr, geom, 0, 1, 5);
41 xrchart_write_yscale (cr, geom, 0, 1, 5);
45 xrchart_line (cr, geom, 1.0, 0,
50 for (i = 0; i < rc->n_vars; ++i)
52 const struct roc_var *rv = &rc->vars[i];
53 struct casereader *r = casereader_clone (rv->cutpoint_reader);
56 xrchart_vector_start (cr, geom, rv->name);
57 for (; (cc = casereader_read (r)) != NULL; case_unref (cc))
59 double se = case_data_idx (cc, ROC_TP)->f;
60 double sp = case_data_idx (cc, ROC_TN)->f;
62 se /= case_data_idx (cc, ROC_FN)->f + case_data_idx (cc, ROC_TP)->f ;
63 sp /= case_data_idx (cc, ROC_TN)->f + case_data_idx (cc, ROC_FP)->f ;
65 xrchart_vector (cr, geom, 1 - sp, se);
67 xrchart_vector_end (cr, geom);
68 casereader_destroy (r);
71 xrchart_write_legend (cr, geom);