evalclass / precrec
Showing 32 of 83 files from the diff.
Other files ignored by Codecov
.gitignore has changed.
.Rbuildignore has changed.
tests/testthat.R has changed.
DESCRIPTION has changed.

@@ -66,8 +66,10 @@
Loading
66 66
#' @export
67 67
join_scores <- function(..., byrow = FALSE, chklen = TRUE) {
68 68
  # Call join datasets
69 -
  .join_datasets(..., efunc_vtype = .validate_scores, efunc_nrow = NULL,
70 -
                 byrow = byrow, chklen = chklen)
69 +
  .join_datasets(...,
70 +
    efunc_vtype = .validate_scores, efunc_nrow = NULL,
71 +
    byrow = byrow, chklen = chklen
72 +
  )
71 73
}
72 74
73 75
#' Join observed labels of multiple test datasets into a list
@@ -137,8 +139,10 @@
Loading
137 139
#' @export
138 140
join_labels <- function(..., byrow = FALSE, chklen = TRUE) {
139 141
  # Call join datasets
140 -
  .join_datasets(..., efunc_vtype = .validate_labels, efunc_nrow = NULL,
141 -
                 byrow = byrow, chklen = chklen)
142 +
  .join_datasets(...,
143 +
    efunc_vtype = .validate_labels, efunc_nrow = NULL,
144 +
    byrow = byrow, chklen = chklen
145 +
  )
142 146
}
143 147
144 148
#
@@ -148,9 +152,11 @@
Loading
148 152
                           byrow = FALSE, chklen = TRUE) {
149 153
150 154
  # Validate arguments
151 -
  .validate_join_datasets_args(..., efunc_vtype = efunc_vtype,
152 -
                               efunc_nrow = efunc_nrow, byrow = byrow,
153 -
                               chklen = chklen)
155 +
  .validate_join_datasets_args(...,
156 +
    efunc_vtype = efunc_vtype,
157 +
    efunc_nrow = efunc_nrow, byrow = byrow,
158 +
    chklen = chklen
159 +
  )
154 160
155 161
  # Set a default error function for checking values
156 162
  if (is.null(efunc_vtype)) {
@@ -243,25 +249,28 @@
Loading
243 249
  }
244 250
245 251
  # Check efunc_vtype
246 -
  if (!is.null(efunc_vtype)
247 -
      && (!methods::is(efunc_vtype, "function")
248 -
          || length(as.list(formals(efunc_vtype))) != 1)) {
252 +
  if (!is.null(efunc_vtype) &&
253 +
    (!methods::is(efunc_vtype, "function") ||
254 +
      length(as.list(formals(efunc_vtype))) != 1)) {
249 255
    stop("efunc_vtype must be a function with 1 argument", call. = FALSE)
250 256
  }
251 257
252 258
  # Check efunc_nrow
253 -
  if (!is.null(efunc_nrow)
254 -
      && (!methods::is(efunc_nrow, "function")
255 -
          || length(as.list(formals(efunc_nrow))) != 2)) {
259 +
  if (!is.null(efunc_nrow) &&
260 +
    (!methods::is(efunc_nrow, "function") ||
261 +
      length(as.list(formals(efunc_nrow))) != 2)) {
256 262
    stop("efunc_nrow must be a function with 2 arguments", call. = FALSE)
257 263
  }
258 264
259 265
  # Check byrow
260 -
  assertthat::assert_that(assertthat::is.flag(byrow),
261 -
                          assertthat::noNA(byrow))
266 +
  assertthat::assert_that(
267 +
    assertthat::is.flag(byrow),
268 +
    assertthat::noNA(byrow)
269 +
  )
262 270
263 271
  # Check chklen
264 -
  assertthat::assert_that(assertthat::is.flag(chklen),
265 -
                          assertthat::noNA(chklen))
266 -
272 +
  assertthat::assert_that(
273 +
    assertthat::is.flag(chklen),
274 +
    assertthat::noNA(chklen)
275 +
  )
267 276
}

@@ -5,12 +5,15 @@
Loading
5 5
  curve_df <- .prepare_autoplot(object)
6 6
7 7
  # === Create a ggplot object ===
8 -
  p <- ggplot2::ggplot(curve_df,
9 -
                       ggplot2::aes_string(x = 'x', y = 'y', color = 'x'))
8 +
  p <- ggplot2::ggplot(
9 +
    curve_df,
10 +
    ggplot2::aes_string(x = "x", y = "y", color = "x")
11 +
  )
10 12
  p <- p + ggplot2::geom_jitter()
11 13
  p <- p + ggplot2::coord_flip()
12 14
  p <- .geom_basic(p, "Score distributions by rank", NULL, "rank",
13 -
                   show_legend = FALSE)
15 +
    show_legend = FALSE
16 +
  )
14 17
}
15 18
16 19
#
@@ -20,11 +23,15 @@
Loading
20 23
  curve_df <- .prepare_autoplot(object)
21 24
22 25
  # === Create a ggplot object ===
23 -
  p <- ggplot2::ggplot(curve_df,
24 -
                       ggplot2::aes_string(x = 'x', y = 'y', color = 'group'))
26 +
  p <- ggplot2::ggplot(
27 +
    curve_df,
28 +
    ggplot2::aes_string(x = "x", y = "y", color = "group")
29 +
  )
25 30
  p <- p + ggplot2::geom_line()
26 31
  p <- .geom_basic(p, "TPs, FNs, FPs, and TNs by ranks",
27 -
                   "rank", "count", show_legend = TRUE)
32 +
    "rank", "count",
33 +
    show_legend = TRUE
34 +
  )
28 35
}
29 36
30 37
#
@@ -34,47 +41,50 @@
Loading
34 41
  curve_df <- .prepare_autoplot(object)
35 42
36 43
  # === Create a ggplot object ===
37 -
  p <- ggplot2::ggplot(curve_df,
38 -
                       ggplot2::aes_string(x = 'x', y = 'y'))
44 +
  p <- ggplot2::ggplot(
45 +
    curve_df,
46 +
    ggplot2::aes_string(x = "x", y = "y")
47 +
  )
39 48
  p <- p + ggplot2::geom_line()
40 -
  p <- p + ggplot2::facet_wrap(~ group, ncol = 2)
49 +
  p <- p + ggplot2::facet_wrap(~group, ncol = 2)
41 50
42 51
  p <- .geom_basic(p, "Evaluation measures by ranks",
43 -
                   "normalized rank", "evaluation value", show_legend = FALSE)
52 +
    "normalized rank", "evaluation value",
53 +
    show_legend = FALSE
54 +
  )
44 55
}
45 56
46 57
#' @rdname autoplot
47 58
#' @export
48 59
autoplot.sscurves <- function(object, curvetype = c("ROC", "PRC"), ...) {
49 -
50 60
  arglist <- .get_autoplot_arglist(attr(object, "args"),
51 -
                                   def_curvetype = curvetype, def_type = "l",
52 -
                                   def_show_cb = FALSE, def_raw_curves = TRUE,
53 -
                                   def_add_np_nn = TRUE,
54 -
                                   def_show_legend = FALSE,
55 -
                                   def_ret_grob = FALSE,
56 -
                                   def_reduce_points = TRUE,
57 -
                                   def_multiplot_lib = "patchwork", ...)
61 +
    def_curvetype = curvetype, def_type = "l",
62 +
    def_show_cb = FALSE, def_raw_curves = TRUE,
63 +
    def_add_np_nn = TRUE,
64 +
    def_show_legend = FALSE,
65 +
    def_ret_grob = FALSE,
66 +
    def_reduce_points = TRUE,
67 +
    def_multiplot_lib = "patchwork", ...
68 +
  )
58 69
  arglist[["raw_curves"]] <- TRUE
59 70
  arglist[["show_cb"]] <- FALSE
60 71
  arglist[["curvetype"]] <- .pmatch_curvetype_rocprc(arglist[["curvetype"]])
61 72
62 73
  .autoplot_multi(object, arglist)
63 -
64 74
}
65 75
66 76
#' @rdname autoplot
67 77
#' @export
68 78
autoplot.mscurves <- function(object, curvetype = c("ROC", "PRC"), ...) {
69 -
70 79
  arglist <- .get_autoplot_arglist(attr(object, "args"),
71 -
                                   def_curvetype = curvetype, def_type = "l",
72 -
                                   def_show_cb = FALSE, def_raw_curves = TRUE,
73 -
                                   def_add_np_nn = TRUE,
74 -
                                   def_show_legend = TRUE,
75 -
                                   def_ret_grob = FALSE,
76 -
                                   def_reduce_points = TRUE,
77 -
                                   def_multiplot_lib = "patchwork", ...)
80 +
    def_curvetype = curvetype, def_type = "l",
81 +
    def_show_cb = FALSE, def_raw_curves = TRUE,
82 +
    def_add_np_nn = TRUE,
83 +
    def_show_legend = TRUE,
84 +
    def_ret_grob = FALSE,
85 +
    def_reduce_points = TRUE,
86 +
    def_multiplot_lib = "patchwork", ...
87 +
  )
78 88
  arglist[["raw_curves"]] <- TRUE
79 89
  arglist[["show_cb"]] <- FALSE
80 90
  arglist[["curvetype"]] <- .pmatch_curvetype_rocprc(arglist[["curvetype"]])
@@ -85,15 +95,15 @@
Loading
85 95
#' @rdname autoplot
86 96
#' @export
87 97
autoplot.smcurves <- function(object, curvetype = c("ROC", "PRC"), ...) {
88 -
89 98
  arglist <- .get_autoplot_arglist(attr(object, "args"),
90 -
                                   def_curvetype = curvetype, def_type = "l",
91 -
                                   def_show_cb = TRUE, def_raw_curves = NULL,
92 -
                                   def_add_np_nn = TRUE,
93 -
                                   def_show_legend = FALSE,
94 -
                                   def_ret_grob = FALSE,
95 -
                                   def_reduce_points = TRUE,
96 -
                                   def_multiplot_lib = "patchwork", ...)
99 +
    def_curvetype = curvetype, def_type = "l",
100 +
    def_show_cb = TRUE, def_raw_curves = NULL,
101 +
    def_add_np_nn = TRUE,
102 +
    def_show_legend = FALSE,
103 +
    def_ret_grob = FALSE,
104 +
    def_reduce_points = TRUE,
105 +
    def_multiplot_lib = "patchwork", ...
106 +
  )
97 107
98 108
  arglist[["curvetype"]] <- .pmatch_curvetype_rocprc(arglist[["curvetype"]])
99 109
@@ -103,15 +113,15 @@
Loading
103 113
#' @rdname autoplot
104 114
#' @export
105 115
autoplot.mmcurves <- function(object, curvetype = c("ROC", "PRC"), ...) {
106 -
107 116
  arglist <- .get_autoplot_arglist(attr(object, "args"),
108 -
                                   def_curvetype = curvetype, def_type = "l",
109 -
                                   def_show_cb = FALSE, def_raw_curves = NULL,
110 -
                                   def_add_np_nn = TRUE,
111 -
                                   def_show_legend = TRUE,
112 -
                                   def_ret_grob = FALSE,
113 -
                                   def_reduce_points = TRUE,
114 -
                                   def_multiplot_lib = "patchwork", ...)
117 +
    def_curvetype = curvetype, def_type = "l",
118 +
    def_show_cb = FALSE, def_raw_curves = NULL,
119 +
    def_add_np_nn = TRUE,
120 +
    def_show_legend = TRUE,
121 +
    def_ret_grob = FALSE,
122 +
    def_reduce_points = TRUE,
123 +
    def_multiplot_lib = "patchwork", ...
124 +
  )
115 125
116 126
  arglist[["curvetype"]] <- .pmatch_curvetype_rocprc(arglist[["curvetype"]])
117 127
@@ -122,36 +132,35 @@
Loading
122 132
#' @export
123 133
autoplot.sspoints <- function(object, curvetype = .get_metric_names("basic"),
124 134
                              ...) {
125 -
126 135
  arglist <- .get_autoplot_arglist(attr(object, "args"),
127 -
                                   def_curvetype = curvetype, def_type = "p",
128 -
                                   def_show_cb = FALSE, def_raw_curves = TRUE,
129 -
                                   def_add_np_nn = TRUE,
130 -
                                   def_show_legend = FALSE,
131 -
                                   def_ret_grob = FALSE,
132 -
                                   def_reduce_points = FALSE,
133 -
                                   def_multiplot_lib = "patchwork", ...)
136 +
    def_curvetype = curvetype, def_type = "p",
137 +
    def_show_cb = FALSE, def_raw_curves = TRUE,
138 +
    def_add_np_nn = TRUE,
139 +
    def_show_legend = FALSE,
140 +
    def_ret_grob = FALSE,
141 +
    def_reduce_points = FALSE,
142 +
    def_multiplot_lib = "patchwork", ...
143 +
  )
134 144
  arglist[["raw_curves"]] <- TRUE
135 145
  arglist[["show_cb"]] <- FALSE
136 146
  arglist[["curvetype"]] <- .pmatch_curvetype_basic(arglist[["curvetype"]])
137 147
138 148
  .autoplot_multi(object, arglist)
139 -
140 149
}
141 150
142 151
#' @rdname autoplot
143 152
#' @export
144 153
autoplot.mspoints <- function(object, curvetype = .get_metric_names("basic"),
145 154
                              ...) {
146 -
147 155
  arglist <- .get_autoplot_arglist(attr(object, "args"),
148 -
                                   def_curvetype = curvetype, def_type = "p",
149 -
                                   def_show_cb = FALSE, def_raw_curves = TRUE,
150 -
                                   def_add_np_nn = TRUE,
151 -
                                   def_show_legend = TRUE,
152 -
                                   def_ret_grob = FALSE,
153 -
                                   def_reduce_points = FALSE,
154 -
                                   def_multiplot_lib = "patchwork", ...)
156 +
    def_curvetype = curvetype, def_type = "p",
157 +
    def_show_cb = FALSE, def_raw_curves = TRUE,
158 +
    def_add_np_nn = TRUE,
159 +
    def_show_legend = TRUE,
160 +
    def_ret_grob = FALSE,
161 +
    def_reduce_points = FALSE,
162 +
    def_multiplot_lib = "patchwork", ...
163 +
  )
155 164
  arglist[["raw_curves"]] <- TRUE
156 165
  arglist[["show_cb"]] <- FALSE
157 166
  arglist[["curvetype"]] <- .pmatch_curvetype_basic(arglist[["curvetype"]])
@@ -163,15 +172,15 @@
Loading
163 172
#' @export
164 173
autoplot.smpoints <- function(object, curvetype = .get_metric_names("basic"),
165 174
                              ...) {
166 -
167 175
  arglist <- .get_autoplot_arglist(attr(object, "args"),
168 -
                                   def_curvetype = curvetype, def_type = "p",
169 -
                                   def_show_cb = TRUE, def_raw_curves = NULL,
170 -
                                   def_add_np_nn = TRUE,
171 -
                                   def_show_legend = FALSE,
172 -
                                   def_ret_grob = FALSE,
173 -
                                   def_reduce_points = FALSE,
174 -
                                   def_multiplot_lib = "patchwork", ...)
176 +
    def_curvetype = curvetype, def_type = "p",
177 +
    def_show_cb = TRUE, def_raw_curves = NULL,
178 +
    def_add_np_nn = TRUE,
179 +
    def_show_legend = FALSE,
180 +
    def_ret_grob = FALSE,
181 +
    def_reduce_points = FALSE,
182 +
    def_multiplot_lib = "patchwork", ...
183 +
  )
175 184
176 185
  arglist[["curvetype"]] <- .pmatch_curvetype_basic(arglist[["curvetype"]])
177 186
@@ -182,15 +191,15 @@
Loading
182 191
#' @export
183 192
autoplot.mmpoints <- function(object, curvetype = .get_metric_names("basic"),
184 193
                              ...) {
185 -
186 194
  arglist <- .get_autoplot_arglist(attr(object, "args"),
187 -
                                   def_curvetype = curvetype, def_type = "p",
188 -
                                   def_show_cb = FALSE, def_raw_curves = NULL,
189 -
                                   def_add_np_nn = TRUE,
190 -
                                   def_show_legend = TRUE,
191 -
                                   def_ret_grob = FALSE,
192 -
                                   def_reduce_points = FALSE,
193 -
                                   def_multiplot_lib = "patchwork", ...)
195 +
    def_curvetype = curvetype, def_type = "p",
196 +
    def_show_cb = FALSE, def_raw_curves = NULL,
197 +
    def_add_np_nn = TRUE,
198 +
    def_show_legend = TRUE,
199 +
    def_ret_grob = FALSE,
200 +
    def_reduce_points = FALSE,
201 +
    def_multiplot_lib = "patchwork", ...
202 +
  )
194 203
195 204
  arglist[["curvetype"]] <- .pmatch_curvetype_basic(arglist[["curvetype"]])
196 205

@@ -43,8 +43,9 @@
Loading
43 43
#' ## Create sample datasets with 100 positives and 100 negatives
44 44
#' samps <- create_sim_samples(4, 100, 100, "good_er")
45 45
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
46 -
#'                modnames = samps[["modnames"]],
47 -
#'                dsids = samps[["dsids"]])
46 +
#'   modnames = samps[["modnames"]],
47 +
#'   dsids = samps[["dsids"]]
48 +
#' )
48 49
#'
49 50
#' ## Generate an smcurve object that contains ROC and Precision-Recall curves
50 51
#' smcurves <- evalmod(mdat)
@@ -62,8 +63,9 @@
Loading
62 63
#' ## Create sample datasets with 100 positives and 100 negatives
63 64
#' samps <- create_sim_samples(4, 100, 100, "all")
64 65
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
65 -
#'                modnames = samps[["modnames"]],
66 -
#'                dsids = samps[["dsids"]])
66 +
#'   modnames = samps[["modnames"]],
67 +
#'   dsids = samps[["dsids"]]
68 +
#' )
67 69
#'
68 70
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
69 71
#' mmcurves <- evalmod(mdat)
@@ -75,10 +77,12 @@
Loading
75 77
#' mm_auc_ci
76 78
#'
77 79
#' @export
78 -
auc_ci <- function(curves, alpha=NULL, dtype=NULL) UseMethod("auc_ci", curves)
80 +
auc_ci <- function(curves, alpha = NULL, dtype = NULL) {
81 +
  UseMethod("auc_ci", curves)
82 +
}
79 83
80 84
#' @export
81 -
auc_ci.default <- function(curves, alpha=NULL, dtype=NULL) {
85 +
auc_ci.default <- function(curves, alpha = NULL, dtype = NULL) {
82 86
  stop("An object of unknown class is specified")
83 87
}
84 88
@@ -87,13 +91,16 @@
Loading
87 91
#
88 92
#' @rdname auc_ci
89 93
#' @export
90 -
auc_ci.aucs <- function(curves, alpha=0.05, dtype="normal") {
94 +
auc_ci.aucs <- function(curves, alpha = 0.05, dtype = "normal") {
91 95
  # Validation
92 96
  .validate(curves)
93 97
  assertthat::assert_that(attr(curves, "dataset_type") == "multiple",
94 -
                          msg = "'curves' must contain multiple datasets.")
95 -
  assertthat::assert_that(assertthat::is.number(alpha),
96 -
                          alpha >= 0 && alpha <= 1)
98 +
    msg = "'curves' must contain multiple datasets."
99 +
  )
100 +
  assertthat::assert_that(
101 +
    assertthat::is.number(alpha),
102 +
    alpha >= 0 && alpha <= 1
103 +
  )
97 104
  assertthat::assert_that(assertthat::is.string(dtype))
98 105
99 106
  # Check type of distribution
@@ -102,7 +109,10 @@
Loading
102 109
  if (!is.na(dype_match)) {
103 110
    dtype <- dtype_tab[dype_match]
104 111
  }
105 -
  err_msg = paste0("'dtype' must be one of ", paste(dtype_tab, collapse = ", "))
112 +
  err_msg <- paste0(
113 +
    "'dtype' must be one of ",
114 +
    paste(dtype_tab, collapse = ", ")
115 +
  )
106 116
  assertthat::assert_that(dtype %in% dtype_tab, msg = err_msg)
107 117
108 118
  # Get AUC scores
@@ -122,14 +132,18 @@
Loading
122 132
      aucs_mean <- mean(aucs_subset$aucs)
123 133
      aucs_n <- length(aucs_subset$aucs)
124 134
      if (aucs_n < 2) {
125 -
        ci_df <- rbind(ci_df,
126 -
                       data.frame(modnames = modname,
127 -
                                  curvetypes = curvetype,
128 -
                                  mean = aucs_mean,
129 -
                                  error = 0,
130 -
                                  lower_bound = aucs_mean,
131 -
                                  upper_bound = aucs_mean,
132 -
                                  n = aucs_n))
135 +
        ci_df <- rbind(
136 +
          ci_df,
137 +
          data.frame(
138 +
            modnames = modname,
139 +
            curvetypes = curvetype,
140 +
            mean = aucs_mean,
141 +
            error = 0,
142 +
            lower_bound = aucs_mean,
143 +
            upper_bound = aucs_mean,
144 +
            n = aucs_n
145 +
          )
146 +
        )
133 147
        next
134 148
      }
135 149
      aucs_sd <- sd(aucs_subset$aucs)
@@ -145,16 +159,19 @@
Loading
145 159
      acus_lower <- max(aucs_mean - aucs_error, 0.0)
146 160
      acus_upper <- min(aucs_mean + aucs_error, 1.0)
147 161
148 -
      ci_df <- rbind(ci_df,
149 -
                     data.frame(modnames = modname,
150 -
                                curvetypes = curvetype,
151 -
                                mean = aucs_mean,
152 -
                                error = aucs_error,
153 -
                                lower_bound = acus_lower,
154 -
                                upper_bound = acus_upper,
155 -
                                n = aucs_n))
162 +
      ci_df <- rbind(
163 +
        ci_df,
164 +
        data.frame(
165 +
          modnames = modname,
166 +
          curvetypes = curvetype,
167 +
          mean = aucs_mean,
168 +
          error = aucs_error,
169 +
          lower_bound = acus_lower,
170 +
          upper_bound = acus_upper,
171 +
          n = aucs_n
172 +
        )
173 +
      )
156 174
    }
157 -
158 175
  }
159 176
160 177
  ci_df

@@ -103,7 +103,6 @@
Loading
103 103
#'   with \pkg{ggplot2}.
104 104
#'
105 105
#' @examples
106 -
#'
107 106
#' \dontrun{
108 107
#' ##################################################
109 108
#' ### Single model & single test dataset
@@ -125,8 +124,10 @@
Loading
125 124
#' plot(sscurves, curvetype = "PRC")
126 125
#'
127 126
#' ## Generate an sspoints object that contains basic evaluation measures
128 -
#' sspoints <- evalmod(mode = "basic", scores = P10N10$scores,
129 -
#'                     labels = P10N10$labels)
127 +
#' sspoints <- evalmod(
128 +
#'   mode = "basic", scores = P10N10$scores,
129 +
#'   labels = P10N10$labels
130 +
#' )
130 131
#'
131 132
#' ## Plot normalized ranks vs. basic evaluation measures
132 133
#' plot(sspoints)
@@ -142,7 +143,8 @@
Loading
142 143
#' ## Create sample datasets with 100 positives and 100 negatives
143 144
#' samps <- create_sim_samples(1, 100, 100, "all")
144 145
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
145 -
#'                modnames = samps[["modnames"]])
146 +
#'   modnames = samps[["modnames"]]
147 +
#' )
146 148
#'
147 149
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
148 150
#' mscurves <- evalmod(mdat)
@@ -170,8 +172,9 @@
Loading
170 172
#' ## Create sample datasets with 100 positives and 100 negatives
171 173
#' samps <- create_sim_samples(10, 100, 100, "good_er")
172 174
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
173 -
#'                modnames = samps[["modnames"]],
174 -
#'                dsids = samps[["dsids"]])
175 +
#'   modnames = samps[["modnames"]],
176 +
#'   dsids = samps[["dsids"]]
177 +
#' )
175 178
#'
176 179
#' ## Generate an smcurve object that contains ROC and Precision-Recall curves
177 180
#' smcurves <- evalmod(mdat, raw_curves = TRUE)
@@ -199,8 +202,9 @@
Loading
199 202
#' ## Create sample datasets with 100 positives and 100 negatives
200 203
#' samps <- create_sim_samples(10, 100, 100, "all")
201 204
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
202 -
#'                modnames = samps[["modnames"]],
203 -
#'                dsids = samps[["dsids"]])
205 +
#'   modnames = samps[["modnames"]],
206 +
#'   dsids = samps[["dsids"]]
207 +
#' )
204 208
#'
205 209
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
206 210
#' mmcurves <- evalmod(mdat, raw_curves = TRUE)
@@ -229,9 +233,11 @@
Loading
229 233
#' data(M2N50F5)
230 234
#'
231 235
#' ## Speficy nessesary columns to create mdat
232 -
#' cvdat <- mmdata(nfold_df = M2N50F5, score_cols = c(1, 2),
233 -
#'                 lab_col = 3, fold_col = 4,
234 -
#'                 modnames = c("m1", "m2"), dsids = 1:5)
236 +
#' cvdat <- mmdata(
237 +
#'   nfold_df = M2N50F5, score_cols = c(1, 2),
238 +
#'   lab_col = 3, fold_col = 4,
239 +
#'   modnames = c("m1", "m2"), dsids = 1:5
240 +
#' )
235 241
#'
236 242
#' ## Generate an mmcurve object that contains ROC and Precision-Recall curves
237 243
#' cvcurves <- evalmod(cvdat)
@@ -247,8 +253,7 @@
Loading
247 253
#'
248 254
#' ## Normalized ranks vs. average basic evaluation measures
249 255
#' plot(cvpoints)
250 -
#'
251 -
#'}
256 +
#' }
252 257
#' @name plot
253 258
NULL
254 259
@@ -279,7 +284,6 @@
Loading
279 284
# Check partial match - Basic evaluation measures
280 285
#
281 286
.pmatch_curvetype_basic <- function(vals) {
282 -
283 287
  pfunc <- function(val) {
284 288
    if (assertthat::is.string(val)) {
285 289
      sval <- tolower(val)
@@ -296,8 +300,8 @@
Loading
296 300
        return("specificity")
297 301
      }
298 302
299 -
      if (!is.na(pmatch(sval, "sensitivity"))
300 -
          || !is.na(pmatch(sval, "recall")) || sval == "tpr" || sval == "sn") {
303 +
      if (!is.na(pmatch(sval, "sensitivity")) ||
304 +
        !is.na(pmatch(sval, "recall")) || sval == "tpr" || sval == "sn") {
301 305
        return("sensitivity")
302 306
      }
303 307
@@ -305,8 +309,8 @@
Loading
305 309
        return("precision")
306 310
      }
307 311
308 -
      if (!is.na(pmatch(sval, "matthews correlation coefficient"))
309 -
          || sval == "mcc") {
312 +
      if (!is.na(pmatch(sval, "matthews correlation coefficient")) ||
313 +
        sval == "mcc") {
310 314
        return("mcc")
311 315
      }
312 316
@@ -355,7 +359,8 @@
Loading
355 359
  }
356 360
  if (!evalmod_args[["calc_avg"]] && arglist[["show_cb"]]) {
357 361
    stop("Invalid show_cb. Inconsistent with calc_avg of evalmod.",
358 -
         call. = FALSE)
362 +
      call. = FALSE
363 +
    )
359 364
  }
360 365
361 366
  if (is.null(arglist[["raw_curves"]])) {
@@ -369,7 +374,8 @@
Loading
369 374
  }
370 375
  if (!evalmod_args[["raw_curves"]] && arglist[["raw_curves"]]) {
371 376
    stop("Invalid raw_curves. Inconsistent with the value of evalmod.",
372 -
         call. = FALSE)
377 +
      call. = FALSE
378 +
    )
373 379
  }
374 380
375 381
  if (is.null(arglist[["add_np_nn"]])) {
@@ -381,7 +387,6 @@
Loading
381 387
  }
382 388
383 389
  arglist
384 -
385 390
}
386 391
387 392
#
@@ -396,12 +401,12 @@
Loading
396 401
397 402
  show_cb <- arglist[["show_cb"]]
398 403
  if (!attr(x, "args")$calc_avg) {
399 -
    show_cb = FALSE
404 +
    show_cb <- FALSE
400 405
  }
401 406
402 407
  raw_curves <- arglist[["raw_curves"]]
403 408
  if (show_cb) {
404 -
    raw_curves = FALSE
409 +
    raw_curves <- FALSE
405 410
  }
406 411
407 412
  # === Validate input arguments ===
@@ -422,9 +427,11 @@
Loading
422 427
  }
423 428
424 429
  for (ct in curvetype) {
425 -
    .plot_single(x, ct, type = type, show_cb = show_cb,
426 -
                 raw_curves = raw_curves, add_np_nn = add_np_nn,
427 -
                 show_legend = show_legend2)
430 +
    .plot_single(x, ct,
431 +
      type = type, show_cb = show_cb,
432 +
      raw_curves = raw_curves, add_np_nn = add_np_nn,
433 +
      show_legend = show_legend2
434 +
    )
428 435
  }
429 436
  if (length(curvetype) > 4 && length(curvetype) %% 3 == 2) {
430 437
    graphics::plot(1, type = "n", axes = FALSE, xlab = "", ylab = "")
@@ -443,14 +450,13 @@
Loading
443 450
# Set layout
444 451
#
445 452
.set_layout <- function(ctype_len, show_legend) {
446 -
447 453
  if (ctype_len == 1) {
448 454
    nrow1 <- 2
449 455
    ncol1 <- 1
450 456
    mat1 <- c(1, 2)
451 457
    mat2 <- 1
452 458
    heights <- c(0.85, 0.15)
453 -
  } else  if (ctype_len == 2) {
459 +
  } else if (ctype_len == 2) {
454 460
    nrow1 <- 2
455 461
    ncol1 <- 2
456 462
    mat1 <- c(1, 2, 3, 3)
@@ -512,9 +518,11 @@
Loading
512 518
  xlim <- .get_xlim(obj, curvetype)
513 519
  ylim <- .get_ylim(obj, curvetype)
514 520
  mats <- .make_matplot_mats(obj[[curvetype]])
515 -
  graphics::matplot(mats[["x"]], mats[["y"]], type = type, lty = 1, pch = 19,
516 -
                    col = line_col, main = main, xlab = xlab, ylab = ylab,
517 -
                    ylim = ylim, xlim = xlim)
521 +
  graphics::matplot(mats[["x"]], mats[["y"]],
522 +
    type = type, lty = 1, pch = 19,
523 +
    col = line_col, main = main, xlab = xlab, ylab = ylab,
524 +
    ylim = ylim, xlim = xlim
525 +
  )
518 526
}
519 527
520 528
#
@@ -558,8 +566,10 @@
Loading
558 566
559 567
  xlim <- .get_xlim(obj, curvetype)
560 568
  ylim <- .get_ylim(obj, curvetype)
561 -
  graphics::plot(1, type = "n", main = main, xlab = xlab, ylab = ylab,
562 -
                 ylim = ylim, xlim = xlim)
569 +
  graphics::plot(1,
570 +
    type = "n", main = main, xlab = xlab, ylab = ylab,
571 +
    ylim = ylim, xlim = xlim
572 +
  )
563 573
564 574
  if (length(avgcurves) == 1) {
565 575
    lcols <- "blue"
@@ -594,15 +604,21 @@
Loading
594 604
    }
595 605
596 606
    g <- grDevices::col2rgb(pcol)
597 -
    graphics::polygon(c(x, rev(x)), c(ymin, rev(ymax)), border = FALSE,
598 -
                      col = grDevices::rgb(g[1], g[2], g[3], 180,
599 -
                                           maxColorValue = 255))
607 +
    graphics::polygon(c(x, rev(x)), c(ymin, rev(ymax)),
608 +
      border = FALSE,
609 +
      col = grDevices::rgb(g[1], g[2], g[3], 180,
610 +
        maxColorValue = 255
611 +
      )
612 +
    )
600 613
  }
601 614
602 615
  b <- grDevices::col2rgb(lcol)
603 -
  graphics::lines(x, y, type = type, lty = 1, pch = 19,
604 -
                  col = grDevices::rgb(b[1], b[2], b[3], 200,
605 -
                                       maxColorValue = 255))
616 +
  graphics::lines(x, y,
617 +
    type = type, lty = 1, pch = 19,
618 +
    col = grDevices::rgb(b[1], b[2], b[3], 200,
619 +
      maxColorValue = 255
620 +
    )
621 +
  )
606 622
}
607 623
608 624
#
@@ -611,7 +627,6 @@
Loading
611 627
.plot_single <- function(x, curvetype, type = type, show_cb = FALSE,
612 628
                         raw_curves = FALSE, add_np_nn = TRUE,
613 629
                         show_legend = TRUE) {
614 -
615 630
  tlist <- .get_titiles(curvetype)
616 631
  main <- tlist[["main"]]
617 632
@@ -630,19 +645,24 @@
Loading
630 645
631 646
  # === Create a plot ===
632 647
  if (show_cb) {
633 -
    .plot_avg(x, type, tlist[["ctype"]], main, tlist[["xlab"]],
634 -
              tlist[["ylab"]], show_cb)
648 +
    .plot_avg(
649 +
      x, type, tlist[["ctype"]], main, tlist[["xlab"]],
650 +
      tlist[["ylab"]], show_cb
651 +
    )
635 652
  } else if (raw_curves) {
636 -
    .matplot_wrapper(x, type, tlist[["ctype"]], main, tlist[["xlab"]],
637 -
                     tlist[["ylab"]])
653 +
    .matplot_wrapper(
654 +
      x, type, tlist[["ctype"]], main, tlist[["xlab"]],
655 +
      tlist[["ylab"]]
656 +
    )
638 657
  } else {
639 -
    .plot_avg(x, type, tlist[["ctype"]], main, tlist[["xlab"]],
640 -
              tlist[["ylab"]], show_cb)
658 +
    .plot_avg(
659 +
      x, type, tlist[["ctype"]], main, tlist[["xlab"]],
660 +
      tlist[["ylab"]], show_cb
661 +
    )
641 662
  }
642 663
643 664
  if (curvetype == "ROC") {
644 665
    graphics::abline(a = 0, b = 1, col = "grey", lty = 3)
645 -
646 666
  } else if (curvetype == "PRC") {
647 667
    graphics::abline(h = pn_info$prc_base, col = "grey", lty = 3)
648 668
  }
@@ -654,7 +674,7 @@
Loading
654 674
# Get title and subtitles
655 675
#
656 676
.get_titiles <- function(curvetype) {
657 -
  tlist = list()
677 +
  tlist <- list()
658 678
659 679
  if (curvetype == "ROC") {
660 680
    tlist[["main"]] <- "ROC"
@@ -667,15 +687,20 @@
Loading
667 687
    tlist[["ylab"]] <- "Precision"
668 688
    tlist[["ctype"]] <- "prcs"
669 689
  } else {
670 -
    mnames <- list(score = "score", label = "label", error = "err",
671 -
                   accuracy = "acc", specificity = "sp", sensitivity = "sn",
672 -
                   precision = "prec", mcc = "mcc", fscore = "fscore")
690 +
    mnames <- list(
691 +
      score = "score", label = "label", error = "err",
692 +
      accuracy = "acc", specificity = "sp", sensitivity = "sn",
693 +
      precision = "prec", mcc = "mcc", fscore = "fscore"
694 +
    )
673 695
    if (curvetype == "mcc") {
674 696
      main <- "MCC"
675 697
    } else if (curvetype == "label") {
676 698
      main <- "Label (1:pos, -1:neg)"
677 699
    } else {
678 -
      main <- paste0(toupper(substring(curvetype, 1, 1)), substring(curvetype, 2))
700 +
      main <- paste0(
701 +
        toupper(substring(curvetype, 1, 1)),
702 +
        substring(curvetype, 2)
703 +
      )
679 704
    }
680 705
    tlist[["main"]] <- main
681 706
    tlist[["xlab"]] <- "normalized rank"
@@ -694,10 +719,12 @@
Loading
694 719
    withr::local_par(list(mar = c(0, 0, 0, 0), pty = "m"))
695 720
    gnames <- attr(obj, paste0("uniq_", gnames))
696 721
    graphics::plot(1, type = "n", axes = FALSE, xlab = "", ylab = "")
697 -
    graphics::legend(x = "top", lty = 1,
698 -
                     legend = gnames,
699 -
                     col = grDevices::rainbow(length(gnames), alpha = 1),
700 -
                     horiz = TRUE)
722 +
    graphics::legend(
723 +
      x = "top", lty = 1,
724 +
      legend = gnames,
725 +
      col = grDevices::rainbow(length(gnames), alpha = 1),
726 +
      horiz = TRUE
727 +
    )
701 728
  }
702 729
}
703 730
@@ -715,16 +742,20 @@
Loading
715 742
  if (!all(is.na(avgcurves))) {
716 743
    for (i in seq_len(length(avgcurves))) {
717 744
      max_score <- max(max_score, max(avgcurves[[i]][["y_ci_h"]], na.rm = TRUE),
718 -
                       na.rm = TRUE)
745 +
        na.rm = TRUE
746 +
      )
719 747
      min_score <- min(min_score, min(avgcurves[[i]][["y_ci_l"]], na.rm = TRUE),
720 -
                       na.rm = TRUE)
748 +
        na.rm = TRUE
749 +
      )
721 750
    }
722 751
  } else {
723 752
    for (i in seq_len(length(curves))) {
724 753
      max_score <- max(max_score, max(curves[[i]][["y"]], na.rm = TRUE),
725 -
                       na.rm = TRUE)
754 +
        na.rm = TRUE
755 +
      )
726 756
      min_score <- min(min_score, min(curves[[i]][["y"]], na.rm = TRUE),
727 -
                       na.rm = TRUE)
757 +
        na.rm = TRUE
758 +
      )
728 759
    }
729 760
  }
730 761
@@ -744,6 +775,8 @@
Loading
744 775
  } else {
745 776
    xlim <- c(0, 1)
746 777
  }
778 +
779 +
  xlim
747 780
}
748 781
749 782
#
@@ -759,4 +792,6 @@
Loading
759 792
  } else {
760 793
    ylim <- c(0, 1)
761 794
  }
795 +
796 +
  ylim
762 797
}

@@ -91,8 +91,10 @@
Loading
91 91
#' p_prc
92 92
#'
93 93
#' ## Generate an sspoints object that contains basic evaluation measures
94 -
#' sspoints <- evalmod(mode = "basic", scores = P10N10$scores,
95 -
#'                     labels = P10N10$labels)
94 +
#' sspoints <- evalmod(
95 +
#'   mode = "basic", scores = P10N10$scores,
96 +
#'   labels = P10N10$labels
97 +
#' )
96 98
#' ## Fortify sspoints
97 99
#' ssdf <- fortify(sspoints)
98 100
#'
@@ -109,7 +111,8 @@
Loading
109 111
#' ## Create sample datasets with 10 positives and 10 negatives
110 112
#' samps <- create_sim_samples(1, 10, 10, "all")
111 113
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
112 -
#'                modnames = samps[["modnames"]])
114 +
#'   modnames = samps[["modnames"]]
115 +
#' )
113 116
#'
114 117
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
115 118
#' mscurves <- evalmod(mdat)
@@ -155,8 +158,9 @@
Loading
155 158
#' ## Create sample datasets with 10 positives and 10 negatives
156 159
#' samps <- create_sim_samples(5, 10, 10, "good_er")
157 160
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
158 -
#'                modnames = samps[["modnames"]],
159 -
#'                dsids = samps[["dsids"]])
161 +
#'   modnames = samps[["modnames"]],
162 +
#'   dsids = samps[["dsids"]]
163 +
#' )
160 164
#'
161 165
#' ## Generate an smcurve object that contains ROC and Precision-Recall curves
162 166
#' smcurves <- evalmod(mdat, raw_curves = TRUE)
@@ -192,8 +196,9 @@
Loading
192 196
#' df_prec <- subset(smdf, curvetype == "precision")
193 197
#' p_prec <- ggplot(df_prec, aes(x = x, y = y, ymin = ymin, ymax = ymax))
194 198
#' p_prec <- p_prec + geom_ribbon(aes(min = ymin, ymax = ymax),
195 -
#'                                stat = "identity", alpha = 0.25,
196 -
#'                                fill = "grey25")
199 +
#'   stat = "identity", alpha = 0.25,
200 +
#'   fill = "grey25"
201 +
#' )
197 202
#' p_prec <- p_prec + geom_point(aes(x = x, y = y))
198 203
#' p_prec
199 204
#'
@@ -205,8 +210,9 @@
Loading
205 210
#' ## Create sample datasets with 10 positives and 10 negatives
206 211
#' samps <- create_sim_samples(5, 10, 10, "all")
207 212
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
208 -
#'                modnames = samps[["modnames"]],
209 -
#'                dsids = samps[["dsids"]])
213 +
#'   modnames = samps[["modnames"]],
214 +
#'   dsids = samps[["dsids"]]
215 +
#' )
210 216
#'
211 217
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
212 218
#' mmcurves <- evalmod(mdat, raw_curves = TRUE)
@@ -242,8 +248,9 @@
Loading
242 248
#' df_prec <- subset(mmdf, curvetype == "precision")
243 249
#' p_prec <- ggplot(df_prec, aes(x = x, y = y, ymin = ymin, ymax = ymax))
244 250
#' p_prec <- p_prec + geom_ribbon(aes(min = ymin, ymax = ymax, group = modname),
245 -
#'                                stat = "identity", alpha = 0.25,
246 -
#'                                fill = "grey25")
251 +
#'   stat = "identity", alpha = 0.25,
252 +
#'   fill = "grey25"
253 +
#' )
247 254
#' p_prec <- p_prec + geom_point(aes(x = x, y = y, color = modname))
248 255
#' p_prec
249 256
#' }
@@ -256,7 +263,6 @@
Loading
256 263
# Process ... for curve objects
257 264
#
258 265
.get_fortify_arglist <- function(evalmod_args, def_raw_curves, ...) {
259 -
260 266
  arglist <- list(...)
261 267
262 268
  if (!is.null(def_raw_curves)) {

@@ -10,10 +10,12 @@
Loading
10 10
  new_ties_method <- .pmatch_tiesmethod(ties_method, ...)
11 11
  new_na_worst <- .get_new_naworst(na_worst, ...)
12 12
  new_mode <- .pmatch_mode(mode)
13 -
  .validate_reformat_data_args(scores, labels, modname = modname, dsid = dsid,
14 -
                               posclass = posclass, na_worst = new_na_worst,
15 -
                               ties_method = new_ties_method, mode = new_mode,
16 -
                               ...)
13 +
  .validate_reformat_data_args(scores, labels,
14 +
    modname = modname, dsid = dsid,
15 +
    posclass = posclass, na_worst = new_na_worst,
16 +
    ties_method = new_ties_method, mode = new_mode,
17 +
    ...
18 +
  )
17 19
18 20
  # === Reformat input data ===
19 21
  # Get a factor with "positive" and "negative"
@@ -21,22 +23,29 @@
Loading
21 23
22 24
  if (mode == "aucroc") {
23 25
    # === Create an S3 object ===
24 -
    s3obj <- structure(list(scores = scores,
25 -
                            labels = fmtlabs[["labels"]]),
26 -
                       class = "sdat")
26 +
    s3obj <- structure(list(
27 +
      scores = scores,
28 +
      labels = fmtlabs[["labels"]]
29 +
    ),
30 +
    class = "sdat"
31 +
    )
27 32
  } else {
28 33
    # Get score ranks and sorted indices
29 34
    sranks <- .rank_scores(scores, new_na_worst, new_ties_method,
30 -
                           validate = FALSE)
35 +
      validate = FALSE
36 +
    )
31 37
    ranks <- sranks[["ranks"]]
32 38
    rank_idx <- sranks[["rank_idx"]]
33 39
34 40
    # === Create an S3 object ===
35 -
    s3obj <- structure(list(scores = scores,
36 -
                            labels = fmtlabs[["labels"]],
37 -
                            ranks = ranks,
38 -
                            rank_idx = rank_idx),
39 -
                       class = "fmdat")
41 +
    s3obj <- structure(list(
42 +
      scores = scores,
43 +
      labels = fmtlabs[["labels"]],
44 +
      ranks = ranks,
45 +
      rank_idx = rank_idx
46 +
    ),
47 +
    class = "fmdat"
48 +
    )
40 49
  }
41 50
42 51
  # Set attributes
@@ -44,9 +53,11 @@
Loading
44 53
  attr(s3obj, "dsid") <- dsid
45 54
  attr(s3obj, "nn") <- fmtlabs[["nn"]]
46 55
  attr(s3obj, "np") <- fmtlabs[["np"]]
47 -
  attr(s3obj, "args") <- list(posclass = posclass, na_worst = new_na_worst,
48 -
                              ties_method = new_ties_method,
49 -
                              modname = modname, dsid = dsid)
56 +
  attr(s3obj, "args") <- list(
57 +
    posclass = posclass, na_worst = new_na_worst,
58 +
    ties_method = new_ties_method,
59 +
    modname = modname, dsid = dsid
60 +
  )
50 61
  attr(s3obj, "validated") <- FALSE
51 62
52 63
  # Call .validate.fmdat() / .validate.sdat()
@@ -97,7 +108,6 @@
Loading
97 108
  }
98 109
99 110
  # === Create ranks ===
100 -
  #   ranks <- rank(scores, na_worst, ties_method)
101 111
  sranks <- get_score_ranks(scores, na_worst, ties_method)
102 112
  .check_cpp_func_error(sranks, "get_score_ranks")
103 113
@@ -115,7 +125,8 @@
Loading
115 125
  arglist <- list(...)
116 126
  if (!is.null(names(arglist))) {
117 127
    stop(paste0("Invalid arguments: ", paste(names(arglist), collapse = ", ")),
118 -
         call. = FALSE)
128 +
      call. = FALSE
129 +
    )
119 130
  }
120 131
121 132
  # Check scores and labels
@@ -138,7 +149,6 @@
Loading
138 149
139 150
  # Check mode
140 151
  .validate_mode(mode)
141 -
142 152
}
143 153
144 154
#
@@ -154,30 +164,38 @@
Loading
154 164
  item_names <- c("scores", "labels", "ranks", "rank_idx")
155 165
  attr_names <- c("modname", "dsid", "nn", "np", "args", "validated")
156 166
  arg_names <- c("posclass", "na_worst", "ties_method", "modname", "dsid")
157 -
  .validate_basic(fmdat, "fmdat", "reformat_data", item_names, attr_names,
158 -
                  arg_names)
167 +
  .validate_basic(
168 +
    fmdat, "fmdat", "reformat_data", item_names, attr_names,
169 +
    arg_names
170 +
  )
159 171
160 172
  # Check values of class items
161 -
  if (length(fmdat[["labels"]]) == 0
162 -
      || length(fmdat[["labels"]]) != length(fmdat[["ranks"]])
163 -
      || length(fmdat[["labels"]]) != length(fmdat[["rank_idx"]])) {
173 +
  if (length(fmdat[["labels"]]) == 0 ||
174 +
    length(fmdat[["labels"]]) != length(fmdat[["ranks"]]) ||
175 +
    length(fmdat[["labels"]]) != length(fmdat[["rank_idx"]])) {
164 176
    stop("List items in fmdat must be all the same lengths", call. = FALSE)
165 177
  }
166 178
167 179
  # Labels
168 -
  assertthat::assert_that(is.atomic(fmdat[["labels"]]),
169 -
                          is.vector(fmdat[["labels"]]),
170 -
                          is.numeric(fmdat[["labels"]]))
180 +
  assertthat::assert_that(
181 +
    is.atomic(fmdat[["labels"]]),
182 +
    is.vector(fmdat[["labels"]]),
183 +
    is.numeric(fmdat[["labels"]])
184 +
  )
171 185
172 186
  # Ranks
173 -
  assertthat::assert_that(is.atomic(fmdat[["ranks"]]),
174 -
                          is.vector(fmdat[["ranks"]]),
175 -
                          is.numeric(fmdat[["ranks"]]))
187 +
  assertthat::assert_that(
188 +
    is.atomic(fmdat[["ranks"]]),
189 +
    is.vector(fmdat[["ranks"]]),
190 +
    is.numeric(fmdat[["ranks"]])
191 +
  )
176 192
177 193
  # Rank index
178 -
  assertthat::assert_that(is.atomic(fmdat[["rank_idx"]]),
179 -
                          is.vector(fmdat[["rank_idx"]]),
180 -
                          is.integer(fmdat[["rank_idx"]]))
194 +
  assertthat::assert_that(
195 +
    is.atomic(fmdat[["rank_idx"]]),
196 +
    is.vector(fmdat[["rank_idx"]]),
197 +
    is.integer(fmdat[["rank_idx"]])
198 +
  )
181 199
182 200
  attr(fmdat, "validated") <- TRUE
183 201
  fmdat
@@ -196,21 +214,24 @@
Loading
196 214
  item_names <- c("scores", "labels")
197 215
  attr_names <- c("modname", "dsid", "nn", "np", "args", "validated")
198 216
  arg_names <- c("posclass", "na_worst", "ties_method", "modname", "dsid")
199 -
  .validate_basic(sdat, "sdat", "reformat_data", item_names, attr_names,
200 -
                  arg_names)
217 +
  .validate_basic(
218 +
    sdat, "sdat", "reformat_data", item_names, attr_names,
219 +
    arg_names
220 +
  )
201 221
202 222
  # Check values of class items
203 -
  if (length(sdat[["labels"]]) == 0
204 -
      || length(sdat[["labels"]]) != length(sdat[["scores"]])) {
223 +
  if (length(sdat[["labels"]]) == 0 ||
224 +
    length(sdat[["labels"]]) != length(sdat[["scores"]])) {
205 225
    stop("List items in sdat must be all the same lengths", call. = FALSE)
206 226
  }
207 227
208 228
  # Labels
209 -
  assertthat::assert_that(is.atomic(sdat[["labels"]]),
210 -
                          is.vector(sdat[["labels"]]),
211 -
                          is.numeric(sdat[["labels"]]))
229 +
  assertthat::assert_that(
230 +
    is.atomic(sdat[["labels"]]),
231 +
    is.vector(sdat[["labels"]]),
232 +
    is.numeric(sdat[["labels"]])
233 +
  )
212 234
213 235
  attr(sdat, "validated") <- TRUE
214 236
  sdat
215 237
}
216 -

@@ -8,7 +8,8 @@
Loading
8 8
#
9 9
.validate.default <- function(x) {
10 10
  stop(paste0("Unrecognized class for .validate(): '", class(x), "'"),
11 -
       call. = FALSE)
11 +
    call. = FALSE
12 +
  )
12 13
}
13 14
14 15
#
@@ -18,32 +19,44 @@
Loading
18 19
                            arg_names) {
19 20
  # Check class
20 21
  if (!methods::is(obj, class_name)) {
21 -
    stop(paste0("Expected ", class_name, " created by ", func_name, "(): ",
22 -
                class(obj)),
23 -
         call. = FALSE)
22 +
    stop(paste0(
23 +
      "Expected ", class_name, " created by ", func_name, "(): ",
24 +
      class(obj)
25 +
    ),
26 +
    call. = FALSE
27 +
    )
24 28
  }
25 29
26 30
  # Check class items
27 31
  ditems <- setdiff(item_names, names(obj))
28 32
  if (!is.null(item_names) && length(ditems) > 0) {
29 -
    stop(paste0("Invalid list items in ", class_name, ": ",
30 -
                paste(ditems, collapse = ", ")),
31 -
         call. = FALSE)
33 +
    stop(paste0(
34 +
      "Invalid list items in ", class_name, ": ",
35 +
      paste(ditems, collapse = ", ")
36 +
    ),
37 +
    call. = FALSE
38 +
    )
32 39
  }
33 40
34 41
  # Check attributes
35 42
  ditems <- setdiff(attr_names, names(attributes(obj)))
36 43
  if (!is.null(attr_names) && length(ditems) > 0) {
37 -
    stop(paste0("Invalid attributes in ", class_name, ": ",
38 -
                paste(ditems, collapse = ", ")),
39 -
         call. = FALSE)
44 +
    stop(paste0(
45 +
      "Invalid attributes in ", class_name, ": ",
46 +
      paste(ditems, collapse = ", ")
47 +
    ),
48 +
    call. = FALSE
49 +
    )
40 50
  }
41 51
42 52
  # Check args
43 53
  ditems <- setdiff(names(attr(obj, "args")), arg_names)
44 54
  if (!is.null(arg_names) && length(ditems) > 0) {
45 -
    stop(paste0("Invalid args attribute in ", class_name, ": ",
46 -
                paste(ditems, collapse = ", ")),
47 -
         call. = FALSE)
55 +
    stop(paste0(
56 +
      "Invalid args in ", class_name, ": ",
57 +
      paste(ditems, collapse = ", ")
58 +
    ),
59 +
    call. = FALSE
60 +
    )
48 61
  }
49 62
}

@@ -2,9 +2,9 @@
Loading
2 2
#' @export
3 3
as.data.frame.sscurves <- function(x, row.names = NULL, optional = FALSE,
4 4
                                   raw_curves = NULL, ...) {
5 -
6 5
  arglist <- .get_dataframe_arglist(attr(x, "args"),
7 -
                                    def_raw_curves = TRUE, ...)
6 +
    def_raw_curves = TRUE, ...
7 +
  )
8 8
9 9
  .dataframe_common(x, raw_curves = arglist[["raw_curves"]], ...)
10 10
}
@@ -13,9 +13,9 @@
Loading
13 13
#' @export
14 14
as.data.frame.mscurves <- function(x, row.names = NULL, optional = FALSE,
15 15
                                   raw_curves = NULL, ...) {
16 -
17 16
  arglist <- .get_dataframe_arglist(attr(x, "args"),
18 -
                                    def_raw_curves = TRUE, ...)
17 +
    def_raw_curves = TRUE, ...
18 +
  )
19 19
20 20
  .dataframe_common(x, raw_curves = arglist[["raw_curves"]], ...)
21 21
}
@@ -24,9 +24,9 @@
Loading
24 24
#' @export
25 25
as.data.frame.smcurves <- function(x, row.names = NULL, optional = FALSE,
26 26
                                   raw_curves = NULL, ...) {
27 -
28 27
  arglist <- .get_dataframe_arglist(attr(x, "args"),
29 -
                                    def_raw_curves = raw_curves, ...)
28 +
    def_raw_curves = raw_curves, ...
29 +
  )
30 30
31 31
  .dataframe_common(x, raw_curves = arglist[["raw_curves"]], ...)
32 32
}
@@ -35,9 +35,9 @@
Loading
35 35
#' @export
36 36
as.data.frame.mmcurves <- function(x, row.names = NULL, optional = FALSE,
37 37
                                   raw_curves = NULL, ...) {
38 -
39 38
  arglist <- .get_dataframe_arglist(attr(x, "args"),
40 -
                                    def_raw_curves = raw_curves, ...)
39 +
    def_raw_curves = raw_curves, ...
40 +
  )
41 41
42 42
  .dataframe_common(x, raw_curves = arglist[["raw_curves"]], ...)
43 43
}
@@ -46,48 +46,56 @@
Loading
46 46
#' @export
47 47
as.data.frame.sspoints <- function(x, row.names = NULL, optional = FALSE,
48 48
                                   raw_curves = NULL, ...) {
49 -
50 49
  arglist <- .get_dataframe_arglist(attr(x, "args"),
51 -
                                    def_raw_curves = TRUE, ...)
50 +
    def_raw_curves = TRUE, ...
51 +
  )
52 52
53 -
  .dataframe_common(x, mode = "basic", raw_curves = arglist[["raw_curves"]],
54 -
                    ...)
53 +
  .dataframe_common(x,
54 +
    mode = "basic", raw_curves = arglist[["raw_curves"]],
55 +
    ...
56 +
  )
55 57
}
56 58
57 59
#' @rdname as.data.frame
58 60
#' @export
59 61
as.data.frame.mspoints <- function(x, row.names = NULL, optional = FALSE,
60 62
                                   raw_curves = NULL, ...) {
61 -
62 63
  arglist <- .get_dataframe_arglist(attr(x, "args"),
63 -
                                    def_raw_curves = TRUE, ...)
64 +
    def_raw_curves = TRUE, ...
65 +
  )
64 66
65 -
  .dataframe_common(x, mode = "basic", raw_curves = arglist[["raw_curves"]],
66 -
                    ...)
67 +
  .dataframe_common(x,
68 +
    mode = "basic", raw_curves = arglist[["raw_curves"]],
69 +
    ...
70 +
  )
67 71
}
68 72
69 73
#' @rdname as.data.frame
70 74
#' @export
71 75
as.data.frame.smpoints <- function(x, row.names = NULL, optional = FALSE,
72 76
                                   raw_curves = NULL, ...) {
73 -
74 77
  arglist <- .get_dataframe_arglist(attr(x, "args"),
75 -
                                    def_raw_curves = raw_curves, ...)
78 +
    def_raw_curves = raw_curves, ...
79 +
  )
76 80
77 -
  .dataframe_common(x, mode = "basic", raw_curves = arglist[["raw_curves"]],
78 -
                    ...)
81 +
  .dataframe_common(x,
82 +
    mode = "basic", raw_curves = arglist[["raw_curves"]],
83 +
    ...
84 +
  )
79 85
}
80 86
81 87
#' @rdname as.data.frame
82 88
#' @export
83 89
as.data.frame.mmpoints <- function(x, row.names = NULL, optional = FALSE,
84 90
                                   raw_curves = NULL, ...) {
85 -
86 91
  arglist <- .get_dataframe_arglist(attr(x, "args"),
87 -
                                    def_raw_curves = raw_curves, ...)
92 +
    def_raw_curves = raw_curves, ...
93 +
  )
88 94
89 -
  .dataframe_common(x, mode = "basic", raw_curves = arglist[["raw_curves"]],
90 -
                    ...)
95 +
  .dataframe_common(x,
96 +
    mode = "basic", raw_curves = arglist[["raw_curves"]],
97 +
    ...
98 +
  )
91 99
}
92 100
93 101
#' @rdname as.data.frame
@@ -95,4 +103,3 @@
Loading
95 103
as.data.frame.aucroc <- function(x, row.names = NULL, optional = FALSE, ...) {
96 104
  x$uaucs
97 105
}
98 -

@@ -40,8 +40,8 @@
Loading
40 40
#'   input with calculated pAUCs and standardized pAUCs.
41 41
#'
42 42
#' @seealso \code{\link{evalmod}} for generating \code{S3} objects with
43 -
#'   performance evaluation measures. \code{\link{pauc}} for retrieving a dataset
44 -
#'   of pAUCs.
43 +
#'   performance evaluation measures. \code{\link{pauc}} for retrieving
44 +
#'   a dataset of pAUCs.
45 45
#'
46 46
#' @examples
47 47
#' \dontrun{
@@ -79,7 +79,8 @@
Loading
79 79
#' ## Create sample datasets with 100 positives and 100 negatives
80 80
#' samps <- create_sim_samples(1, 100, 100, "all")
81 81
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
82 -
#'                modnames = samps[["modnames"]])
82 +
#'   modnames = samps[["modnames"]]
83 +
#' )
83 84
#'
84 85
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
85 86
#' mscurves <- evalmod(mdat)
@@ -104,8 +105,9 @@
Loading
104 105
#' ## Create sample datasets with 100 positives and 100 negatives
105 106
#' samps <- create_sim_samples(4, 100, 100, "good_er")
106 107
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
107 -
#'                modnames = samps[["modnames"]],
108 -
#'                dsids = samps[["dsids"]])
108 +
#'   modnames = samps[["modnames"]],
109 +
#'   dsids = samps[["dsids"]]
110 +
#' )
109 111
#'
110 112
#' ## Generate an smcurve object that contains ROC and Precision-Recall curves
111 113
#' smcurves <- evalmod(mdat)
@@ -130,8 +132,9 @@
Loading
130 132
#' ## Create sample datasets with 100 positives and 100 negatives
131 133
#' samps <- create_sim_samples(4, 100, 100, "all")
132 134
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
133 -
#'                modnames = samps[["modnames"]],
134 -
#'                dsids = samps[["dsids"]])
135 +
#'   modnames = samps[["modnames"]],
136 +
#'   dsids = samps[["dsids"]]
137 +
#' )
135 138
#'
136 139
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
137 140
#' mmcurves <- evalmod(mdat, raw_curves = TRUE)
@@ -150,10 +153,12 @@
Loading
150 153
#' }
151 154
#'
152 155
#' @export
153 -
part <- function(curves, xlim=NULL, ylim=NULL, curvetype=NULL) UseMethod("part", curves)
156 +
part <- function(curves, xlim = NULL, ylim = NULL, curvetype = NULL) {
157 +
  UseMethod("part", curves)
158 +
}
154 159
155 160
#' @export
156 -
part.default <- function(curves, xlim=NULL, ylim=NULL, curvetype=NULL) {
161 +
part.default <- function(curves, xlim = NULL, ylim = NULL, curvetype = NULL) {
157 162
  stop("An object of unknown class is specified")
158 163
}
159 164
@@ -206,9 +211,13 @@
Loading
206 211
  # Calculate partial AUC scores for ROC
207 212
  if ("ROC" %in% new_curvetype) {
208 213
    if (avg_only) {
209 -
      attr(curves, "grp_avg")[["rocs"]] <- .calc_pauc(attr(curves,
210 -
                                                           "grp_avg")[["rocs"]],
211 -
                                                      xlim, ylim, avg_only)
214 +
      attr(curves, "grp_avg")[["rocs"]] <- .calc_pauc(
215 +
        attr(
216 +
          curves,
217 +
          "grp_avg"
218 +
        )[["rocs"]],
219 +
        xlim, ylim, avg_only
220 +
      )
212 221
    } else {
213 222
      curves[["rocs"]] <- .calc_pauc(curves[["rocs"]], xlim, ylim, avg_only)
214 223
    }
@@ -219,9 +228,13 @@
Loading
219 228
  # Calculate partial AUC scores for precision-recall
220 229
  if ("PRC" %in% new_curvetype) {
221 230
    if (avg_only) {
222 -
      attr(curves, "grp_avg")[["prcs"]] <- .calc_pauc(attr(curves,
223 -
                                                           "grp_avg")[["prcs"]],
224 -
                                                      xlim, ylim, avg_only)
231 +
      attr(curves, "grp_avg")[["prcs"]] <- .calc_pauc(
232 +
        attr(
233 +
          curves,
234 +
          "grp_avg"
235 +
        )[["prcs"]],
236 +
        xlim, ylim, avg_only
237 +
      )
225 238
    } else {
226 239
      curves[["prcs"]] <- .calc_pauc(curves[["prcs"]], xlim, ylim, avg_only)
227 240
    }
@@ -243,7 +256,6 @@
Loading
243 256
# Calculate partial AUC scores
244 257
#
245 258
.calc_pauc <- function(curves, xlim, ylim, avg_only) {
246 -
247 259
  for (i in seq_along(curves)) {
248 260
    # Trim x
249 261
    x <- curves[[i]][["x"]]
@@ -279,11 +291,11 @@
Loading
279 291
280 292
    # Max 1
281 293
    if (pauc > 1) {
282 -
      pauc = 1
294 +
      pauc <- 1
283 295
    }
284 296
285 297
    if (spauc > 1) {
286 -
      spauc = 1
298 +
      spauc <- 1
287 299
    }
288 300
289 301
    attr(curves[[i]], "pauc") <- pauc
@@ -304,19 +316,25 @@
Loading
304 316
  # Collect AUCs of ROC or PRC curves
305 317
  ct_len <- 2
306 318
  aucs <- attr(curves, "aucs")
307 -
  paucs <- data.frame(modnames = aucs$modnames,
308 -
                      dsids = aucs$dsids,
309 -
                      curvetypes = aucs$curvetypes,
310 -
                      paucs = rep(NA, length(aucs$modnames)),
311 -
                      spaucs = rep(NA, length(aucs$modnames)),
312 -
                      stringsAsFactors = FALSE)
319 +
  paucs <- data.frame(
320 +
    modnames = aucs$modnames,
321 +
    dsids = aucs$dsids,
322 +
    curvetypes = aucs$curvetypes,
323 +
    paucs = rep(NA, length(aucs$modnames)),
324 +
    spaucs = rep(NA, length(aucs$modnames)),
325 +
    stringsAsFactors = FALSE
326 +
  )
313 327
314 328
  for (i in seq_along(curves[["rocs"]])) {
315 329
    idx <- ct_len * i - 1
316 -
    paucs[["paucs"]][idx:(idx + 1)] <- c(attr(curves[["rocs"]][[i]], "pauc"),
317 -
                                         attr(curves[["prcs"]][[i]], "pauc"))
318 -
    paucs[["spaucs"]][idx:(idx + 1)] <- c(attr(curves[["rocs"]][[i]], "spauc"),
319 -
                                          attr(curves[["prcs"]][[i]], "spauc"))
330 +
    paucs[["paucs"]][idx:(idx + 1)] <- c(
331 +
      attr(curves[["rocs"]][[i]], "pauc"),
332 +
      attr(curves[["prcs"]][[i]], "pauc")
333 +
    )
334 +
    paucs[["spaucs"]][idx:(idx + 1)] <- c(
335 +
      attr(curves[["rocs"]][[i]], "spauc"),
336 +
      attr(curves[["prcs"]][[i]], "spauc")
337 +
    )
320 338
  }
321 339
322 340
  paucs
@@ -326,25 +344,30 @@
Loading
326 344
# Get pAUCs of average curves
327 345
#
328 346
.gather_paucs_avg <- function(curves) {
329 -
330 347
  avg_crvs <- attr(curves, "grp_avg")
331 348
332 349
  # Collect AUCs of ROC or PRC curves
333 350
  ct_len <- 2
334 351
  modnames <- attr(avg_crvs[["rocs"]], "uniq_modnames")
335 -
  paucs <- data.frame(modnames = rep(modnames, each = ct_len),
336 -
                      curvetypes = rep(c("ROC", "PRC"), length(modnames)),
337 -
                      paucs = rep(NA, length(modnames) * ct_len),
338 -
                      spaucs = rep(NA, length(modnames) * ct_len),
339 -
                      stringsAsFactors = FALSE)
352 +
  paucs <- data.frame(
353 +
    modnames = rep(modnames, each = ct_len),
354 +
    curvetypes = rep(c("ROC", "PRC"), length(modnames)),
355 +
    paucs = rep(NA, length(modnames) * ct_len),
356 +
    spaucs = rep(NA, length(modnames) * ct_len),
357 +
    stringsAsFactors = FALSE
358 +
  )
340 359
341 360
  for (i in seq_along(avg_crvs[["rocs"]])) {
342 361
    idx <- ct_len * i - 1
343 362
    idx2 <- idx + 1
344 -
    paucs[["paucs"]][idx:idx2] <- c(attr(avg_crvs[["rocs"]][[i]], "pauc"),
345 -
                                    attr(avg_crvs[["prcs"]][[i]], "pauc"))
346 -
    paucs[["spaucs"]][idx:idx2] <- c(attr(avg_crvs[["rocs"]][[i]], "spauc"),
347 -
                                     attr(avg_crvs[["prcs"]][[i]], "spauc"))
363 +
    paucs[["paucs"]][idx:idx2] <- c(
364 +
      attr(avg_crvs[["rocs"]][[i]], "pauc"),
365 +
      attr(avg_crvs[["prcs"]][[i]], "pauc")
366 +
    )
367 +
    paucs[["spaucs"]][idx:idx2] <- c(
368 +
      attr(avg_crvs[["rocs"]][[i]], "spauc"),
369 +
      attr(avg_crvs[["prcs"]][[i]], "spauc")
370 +
    )
348 371
  }
349 372
350 373
  paucs

@@ -3,16 +3,20 @@
Loading
3 3
#
4 4
calc_avg_rocprc <- function(curves, modnames, uniq_modnames, cb_alpha,
5 5
                            x_bins) {
6 -
  .calc_avg_common(curves, "curve", "avgcurves", modnames, uniq_modnames,
7 -
                   cb_alpha, x_bins)
6 +
  .calc_avg_common(
7 +
    curves, "curve", "avgcurves", modnames, uniq_modnames,
8 +
    cb_alpha, x_bins
9 +
  )
8 10
}
9 11
10 12
#
11 13
# Calculate the average points for a model
12 14
#
13 15
calc_avg_basic <- function(epoints, modnames, uniq_modnames, cb_alpha) {
14 -
  .calc_avg_common(epoints, "point", "avgpoints", modnames, uniq_modnames,
15 -
                   cb_alpha, NULL)
16 +
  .calc_avg_common(
17 +
    epoints, "point", "avgpoints", modnames, uniq_modnames,
18 +
    cb_alpha, NULL
19 +
  )
16 20
}
17 21
18 22
#
@@ -43,7 +47,6 @@
Loading
43 47
    if (mode == "curve") {
44 48
      avgs <- calc_avg_curve(obj_by_model[[i]], x_bins, cb_zval)
45 49
      .check_cpp_func_error(avgs, "calc_avg_curve")
46 -
47 50
    } else if (mode == "point") {
48 51
      avgs <- calc_avg_points(obj_by_model[[i]], cb_zval)
49 52
      .check_cpp_func_error(avgs, "calc_avg_basic")
@@ -60,8 +63,10 @@
Loading
60 63
  attr(s3obj, "cb_zval") <- cb_zval
61 64
  attr(s3obj, "pauc") <- NA
62 65
  attr(s3obj, "spauc") <- NA
63 -
  attr(s3obj, "args") <- list(cb_alpha = cb_alpha,
64 -
                              x_bins = x_bins)
66 +
  attr(s3obj, "args") <- list(
67 +
    cb_alpha = cb_alpha,
68 +
    x_bins = x_bins
69 +
  )
65 70
  attr(s3obj, "validated") <- FALSE
66 71
67 72
  # Call .validate()
@@ -81,8 +86,10 @@
Loading
81 86
  item_names <- NULL
82 87
  attr_names <- c("uniq_modnames", "cb_zval", "args", "validated")
83 88
  arg_names <- c("cb_alpha", "x_bins")
84 -
  .validate_basic(avgobj, class_name, func_name, item_names, attr_names,
85 -
                  arg_names)
89 +
  .validate_basic(
90 +
    avgobj, class_name, func_name, item_names, attr_names,
91 +
    arg_names
92 +
  )
86 93
87 94
  attr(avgobj, "validated") <- TRUE
88 95
  avgobj

@@ -15,22 +15,29 @@
Loading
15 15
      } else {
16 16
        cl <- "negative"
17 17
      }
18 -
      err_msg <- paste0("AUCs with the U statistic cannot be calculated. ",
19 -
                        "Only a single class (", cl, ") ",
20 -
                        "found in dataset (modname: ", attr(mdat[[s]], "modname"),
21 -
                        ", dsid: ",attr(mdat[[s]], "dsid"), ").")
18 +
      err_msg <- paste0(
19 +
        "AUCs with the U statistic cannot be calculated. ",
20 +
        "Only a single class (", cl, ") ",
21 +
        "found in dataset (modname: ",
22 +
        attr(mdat[[s]], "modname"),
23 +
        ", dsid: ", attr(mdat[[s]], "dsid"), ")."
24 +
      )
22 25
      stop(err_msg, call. = FALSE)
23 26
    }
24 -
    uauc <- calc_auc_with_u(mdat[[s]], na_worst = na_worst,
25 -
                            ties_method = ties_method)
27 +
    calc_auc_with_u(mdat[[s]],
28 +
      na_worst = na_worst,
29 +
      ties_method = ties_method
30 +
    )
26 31
  }
27 32
  aucrocs <- lapply(seq_along(mdat), plfunc)
28 -
  auc.df <- .summarize_uauc_results(aucrocs, attr(mdat, "uniq_modnames"),
29 -
                                    attr(mdat, "uniq_dsids"), calc_avg,
30 -
                                    cb_alpha, raw_curves)
33 +
  auc_df <- .summarize_uauc_results(
34 +
    aucrocs, attr(mdat, "uniq_modnames"),
35 +
    attr(mdat, "uniq_dsids"), calc_avg,
36 +
    cb_alpha, raw_curves
37 +
  )
31 38
32 39
  # === Create an S3 object ===
33 -
  s3obj <- structure(auc.df, class = "aucroc")
40 +
  s3obj <- structure(auc_df, class = "aucroc")
34 41
35 42
  # Set attributes
36 43
  attr(s3obj, "data_info") <- attr(mdat, "data_info")
@@ -38,12 +45,14 @@
Loading
38 45
  attr(s3obj, "uniq_dsids") <- attr(mdat, "uniq_dsids")
39 46
  attr(s3obj, "model_type") <- model_type
40 47
  attr(s3obj, "dataset_type") <- dataset_type
41 -
  attr(s3obj, "args") <- list(mode = "aucroc",
42 -
                              calc_avg = calc_avg,
43 -
                              cb_alpha = cb_alpha,
44 -
                              raw_curves = raw_curves,
45 -
                              na_worst = na_worst,
46 -
                              ties_method = ties_method)
48 +
  attr(s3obj, "args") <- list(
49 +
    mode = "aucroc",
50 +
    calc_avg = calc_avg,
51 +
    cb_alpha = cb_alpha,
52 +
    raw_curves = raw_curves,
53 +
    na_worst = na_worst,
54 +
    ties_method = ties_method
55 +
  )
47 56
  attr(s3obj, "validated") <- FALSE
48 57
49 58
  # Call .validate.class_name()
@@ -61,12 +70,18 @@
Loading
61 70
62 71
  # Validate class items and attributes
63 72
  item_names <- NULL
64 -
  attr_names <- c("data_info", "uniq_modnames", "uniq_dsids",
65 -
                  "model_type", "dataset_type", "args", "validated")
66 -
  arg_names <- c("mode", "calc_avg", "cb_alpha", "raw_curves", "na_worst",
67 -
                 "ties_method")
68 -
  .validate_basic(aucroc, "aucroc", ".pl_main_aucroc", item_names,
69 -
                  attr_names, arg_names)
73 +
  attr_names <- c(
74 +
    "data_info", "uniq_modnames", "uniq_dsids",
75 +
    "model_type", "dataset_type", "args", "validated"
76 +
  )
77 +
  arg_names <- c(
78 +
    "mode", "calc_avg", "cb_alpha", "raw_curves", "na_worst",
79 +
    "ties_method"
80 +
  )
81 +
  .validate_basic(
82 +
    aucroc, "aucroc", ".pl_main_aucroc", item_names,
83 +
    attr_names, arg_names
84 +
  )
70 85
71 86
  attr(aucroc, "validated") <- TRUE
72 87
  aucroc
@@ -93,12 +108,13 @@
Loading
93 108
      vustat[i] <- aucs[[i]]$ustat
94 109
    }
95 110
96 -
    auc_df <- data.frame(modnames = vmodname,
97 -
                         dsids = vdsid,
98 -
                         aucs = vaucs,
99 -
                         ustats = vustat)
111 +
    auc_df <- data.frame(
112 +
      modnames = vmodname,
113 +
      dsids = vdsid,
114 +
      aucs = vaucs,
115 +
      ustats = vustat
116 +
    )
100 117
  }
101 118
102 119
  list(uaucs = auc_df)
103 120
}
104 -

@@ -68,13 +68,15 @@
Loading
68 68
69 69
  # === Validate input arguments ===
70 70
  choices <- c("random", "poor_er", "good_er", "excel", "perf")
71 -
  if (assertthat::see_if(assertthat::is.string(score_names))
72 -
      && any(score_names == "all")) {
71 +
  if (assertthat::see_if(assertthat::is.string(score_names)) &&
72 +
    any(score_names == "all")) {
73 73
    score_names <- choices
74 -
  } else if (!is.atomic(score_names) || !is.character(score_names)
75 -
             || !(all(score_names %in% choices))) {
76 -
    stop(gettextf("'score_names' must be one of %s",
77 -
                  paste(dQuote(choices), collapse = ", ")), call. = FALSE)
74 +
  } else if (!is.atomic(score_names) || !is.character(score_names) ||
75 +
    !(all(score_names %in% choices))) {
76 +
    stop(gettextf(
77 +
      "'score_names' must be one of %s",
78 +
      paste(dQuote(choices), collapse = ", ")
79 +
    ), call. = FALSE)
78 80
  }
79 81
  snames <- paste0(score_names, "_scores")
80 82
@@ -97,10 +99,12 @@
Loading
97 99
  labels <- c(rep(1, np), rep(0, nn))
98 100
99 101
  # === Make a list ===
100 -
  list(scores = scores,
101 -
       labels = labels,
102 -
       modnames = rep(score_names, n_repeat),
103 -
       dsids = rep(seq(n_repeat), each = length(score_names)))
102 +
  list(
103 +
    scores = scores,
104 +
    labels = labels,
105 +
    modnames = rep(score_names, n_repeat),
106 +
    dsids = rep(seq(n_repeat), each = length(score_names))
107 +
  )
104 108
}
105 109
106 110
#
@@ -115,13 +119,14 @@
Loading
115 119
  excel_scores <- c(stats::rnorm(np, 3, 1), stats::rnorm(nn, 0, 1))
116 120
  perf_scores <- c(rep(1, np), rep(0, nn))
117 121
118 -
  list(np = np,
119 -
       nn = nn,
120 -
       labels = labels,
121 -
       random_scores = random_scores,
122 -
       poor_er_scores = poor_er_scores,
123 -
       good_er_scores = good_er_scores,
124 -
       excel_scores = excel_scores,
125 -
       perf_scores = perf_scores
122 +
  list(
123 +
    np = np,
124 +
    nn = nn,
125 +
    labels = labels,
126 +
    random_scores = random_scores,
127 +
    poor_er_scores = poor_er_scores,
128 +
    good_er_scores = good_er_scores,
129 +
    excel_scores = excel_scores,
130 +
    perf_scores = perf_scores
126 131
  )
127 132
}

@@ -11,10 +11,14 @@
Loading
11 11
  cat("    === Input data ===\n\n")
12 12
13 13
  data_info <- attr(x, "data_info")
14 -
  rownames(data_info) <- format(rownames(data_info), width = 4,
15 -
                                justify = "right")
16 -
  colnames(data_info) <- c("Model name", "Dataset ID", "# of negatives",
17 -
                           "# of positives")
14 +
  rownames(data_info) <- format(rownames(data_info),
15 +
    width = 4,
16 +
    justify = "right"
17 +
  )
18 +
  colnames(data_info) <- c(
19 +
    "Model name", "Dataset ID", "# of negatives",
20 +
    "# of positives"
21 +
  )
18 22
19 23
  print.data.frame(data_info, print.gap = 1)
20 24
@@ -51,8 +55,10 @@
Loading
51 55
      colnames(paucs) <- c("Model name", "Curve type", "pAUC", "Standardized")
52 56
    } else {
53 57
      cat("    === partial AUCs ===\n")
54 -
      colnames(paucs) <- c("Model name", "Dataset ID", "Curve type", "pAUC",
55 -
                           "Standardized")
58 +
      colnames(paucs) <- c(
59 +
        "Model name", "Dataset ID", "Curve type", "pAUC",
60 +
        "Standardized"
61 +
      )
56 62
    }
57 63
58 64
    cat("\n")
@@ -88,12 +94,18 @@
Loading
88 94
  cat("\n\n")
89 95
90 96
  eval_summary <- attr(x, "eval_summary")
91 -
  rownames(eval_summary) <- format(rownames(eval_summary), width = 4,
92 -
                                   justify = "right")
93 -
  colnames(eval_summary) <- c("Model", "ID", "Meas.", "Min.",
94 -
                              "1st Qu.", "Median", "Mean", "3rd Qu.", "Max.")
95 -
  evaltypes <- c("rank", "score", "label", "err", "acc", "sp", "sn", "prec",
96 -
                 "mcc", "fscore")
97 +
  rownames(eval_summary) <- format(rownames(eval_summary),
98 +
    width = 4,
99 +
    justify = "right"
100 +
  )
101 +
  colnames(eval_summary) <- c(
102 +
    "Model", "ID", "Meas.", "Min.",
103 +
    "1st Qu.", "Median", "Mean", "3rd Qu.", "Max."
104 +
  )
105 +
  evaltypes <- c(
106 +
    "rank", "score", "label", "err", "acc", "sp", "sn", "prec",
107 +
    "mcc", "fscore"
108 +
  )
97 109
  eval_summary[, "Meas."] <- evaltypes
98 110
99 111
  print.data.frame(eval_summary, print.gap = 1)
@@ -115,10 +127,14 @@
Loading
115 127
  cat("    === Input data ===\n\n")
116 128
117 129
  data_info <- attr(x, "data_info")
118 -
  rownames(data_info) <- format(rownames(data_info), width = 4,
119 -
                                justify = "right")
120 -
  colnames(data_info) <- c("Model name", "Dataset ID", "# of negatives",
121 -
                           "# of positives")
130 +
  rownames(data_info) <- format(rownames(data_info),
131 +
    width = 4,
132 +
    justify = "right"
133 +
  )
134 +
  colnames(data_info) <- c(
135 +
    "Model name", "Dataset ID", "# of negatives",
136 +
    "# of positives"
137 +
  )
122 138
123 139
  print.data.frame(data_info, print.gap = 1)
124 140
  cat("\n\n")

@@ -4,7 +4,8 @@
Loading
4 4
#'   \code{\link{evalmod}} to a data frame.
5 5
#'
6 6
#' @param x An \code{S3} object generated by \code{\link{evalmod}}.
7 -
#'   The \code{as.data.frame} function takes one of the following \code{S3} objects.
7 +
#'   The \code{as.data.frame} function takes
8 +
#'     one of the following \code{S3} objects.
8 9
#'
9 10
#' \enumerate{
10 11
#'
@@ -63,7 +64,6 @@
Loading
63 64
#'   performance evaluation measures.
64 65
#'
65 66
#' @examples
66 -
#'
67 67
#' \dontrun{
68 68
#' ##################################################
69 69
#' ### Single model & single test dataset
@@ -82,8 +82,10 @@
Loading
82 82
#' head(sscurves.df)
83 83
#'
84 84
#' ## Generate an sspoints object that contains basic evaluation measures
85 -
#' sspoints <- evalmod(mode = "basic", scores = P10N10$scores,
86 -
#'                     labels = P10N10$labels)
85 +
#' sspoints <- evalmod(
86 +
#'   mode = "basic", scores = P10N10$scores,
87 +
#'   labels = P10N10$labels
88 +
#' )
87 89
#' ## Convert sspoints to a data frame
88 90
#' sspoints.df <- as.data.frame(sspoints)
89 91
#'
@@ -98,7 +100,8 @@
Loading
98 100
#' ## Create sample datasets with 100 positives and 100 negatives
99 101
#' samps <- create_sim_samples(1, 100, 100, "all")
100 102
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
101 -
#'                modnames = samps[["modnames"]])
103 +
#'   modnames = samps[["modnames"]]
104 +
#' )
102 105
#'
103 106
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
104 107
#' mscurves <- evalmod(mdat)
@@ -126,8 +129,9 @@
Loading
126 129
#' ## Create sample datasets with 100 positives and 100 negatives
127 130
#' samps <- create_sim_samples(10, 100, 100, "good_er")
128 131
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
129 -
#'                modnames = samps[["modnames"]],
130 -
#'                dsids = samps[["dsids"]])
132 +
#'   modnames = samps[["modnames"]],
133 +
#'   dsids = samps[["dsids"]]
134 +
#' )
131 135
#'
132 136
#' ## Generate an smcurve object that contains ROC and Precision-Recall curves
133 137
#' smcurves <- evalmod(mdat, raw_curves = TRUE)
@@ -155,8 +159,9 @@
Loading
155 159
#' ## Create sample datasets with 100 positives and 100 negatives
156 160
#' samps <- create_sim_samples(10, 100, 100, "all")
157 161
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
158 -
#'                modnames = samps[["modnames"]],
159 -
#'                dsids = samps[["dsids"]])
162 +
#'   modnames = samps[["modnames"]],
163 +
#'   dsids = samps[["dsids"]]
164 +
#' )
160 165
#'
161 166
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
162 167
#' mmcurves <- evalmod(mdat, raw_curves = TRUE)
@@ -185,9 +190,11 @@
Loading
185 190
#' data(M2N50F5)
186 191
#'
187 192
#' ## Speficy nessesary columns to create mdat
188 -
#' cvdat <- mmdata(nfold_df = M2N50F5, score_cols = c(1, 2),
189 -
#'                 lab_col = 3, fold_col = 4,
190 -
#'                 modnames = c("m1", "m2"), dsids = 1:5)
193 +
#' cvdat <- mmdata(
194 +
#'   nfold_df = M2N50F5, score_cols = c(1, 2),
195 +
#'   lab_col = 3, fold_col = 4,
196 +
#'   modnames = c("m1", "m2"), dsids = 1:5
197 +
#' )
191 198
#'
192 199
#' ## Generate an mmcurve object that contains ROC and Precision-Recall curves
193 200
#' cvcurves <- evalmod(cvdat)
@@ -214,8 +221,10 @@
Loading
214 221
#'
215 222
#' ## mode = "aucroc"
216 223
#' data(P10N10)
217 -
#' uauc1 <- evalmod(scores = P10N10$scores, labels = P10N10$labels,
218 -
#'                  mode="aucroc")
224 +
#' uauc1 <- evalmod(
225 +
#'   scores = P10N10$scores, labels = P10N10$labels,
226 +
#'   mode = "aucroc"
227 +
#' )
219 228
#'
220 229
#' # as.data.frame 'aucroc'
221 230
#' as.data.frame(uauc1)
@@ -223,9 +232,10 @@
Loading
223 232
#' ## mode = "aucroc"
224 233
#' samps <- create_sim_samples(10, 100, 100, "all")
225 234
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
226 -
#'                modnames = samps[["modnames"]],
227 -
#'                dsids = samps[["dsids"]])
228 -
#' uauc2 <- evalmod(mdat, mode="aucroc")
235 +
#'   modnames = samps[["modnames"]],
236 +
#'   dsids = samps[["dsids"]]
237 +
#' )
238 +
#' uauc2 <- evalmod(mdat, mode = "aucroc")
229 239
#'
230 240
#' # as.data.frame 'aucroc'
231 241
#' head(as.data.frame(uauc2))
@@ -271,51 +281,61 @@
Loading
271 281
    } else {
272 282
      x_bins <- 0
273 283
    }
274 -
275 284
  } else if (new_mode == "basic") {
276 -
    curvetype_names <- list(score = "score", label = "label", error = "err",
277 -
                            accuracy = "acc", specificity = "sp",
278 -
                            sensitivity = "sn", precision = "prec", mcc = "mcc",
279 -
                            fscore = "fscore")
285 +
    curvetype_names <- list(
286 +
      score = "score", label = "label", error = "err",
287 +
      accuracy = "acc", specificity = "sp",
288 +
      sensitivity = "sn", precision = "prec", mcc = "mcc",
289 +
      fscore = "fscore"
290 +
    )
280 291
    x_bins <- 0
281 292
  }
282 293
283 294
  # Make dsis-modname pairs
284 295
  dsid_modnames <- paste(attr(obj, "data_info")$modnames,
285 -
                         attr(obj, "data_info")$dsids, sep = ":")
296 +
    attr(obj, "data_info")$dsids,
297 +
    sep = ":"
298 +
  )
286 299
287 300
  # Create curve_df
288 301
  if (raw_curves) {
289 302
    if (use_rcpp) {
290 -
      list_df <- convert_curve_df(obj, uniq_modnames, as.character(uniq_dsids),
291 -
                                  match(modnames, uniq_modnames),
292 -
                                  match(dsids, uniq_dsids),
293 -
                                  dsid_modnames, curvetype_names, x_bins)
303 +
      list_df <- convert_curve_df(
304 +
        obj, uniq_modnames, as.character(uniq_dsids),
305 +
        match(modnames, uniq_modnames),
306 +
        match(dsids, uniq_dsids),
307 +
        dsid_modnames, curvetype_names, x_bins
308 +
      )
294 309
      .check_cpp_func_error(list_df, "convert_curve_df")
295 310
      curve_df <- list_df[["df"]]
296 311
    } else {
297 -
      curve_df <- .dataframe_curve(obj, uniq_modnames, uniq_dsids, modnames,
298 -
                                   dsids, dsid_modnames, curvetype_names)
312 +
      curve_df <- .dataframe_curve(
313 +
        obj, uniq_modnames, uniq_dsids, modnames,
314 +
        dsids, dsid_modnames, curvetype_names
315 +
      )
299 316
      warning("R version of .dataframe_common is used")
300 317
    }
301 318
  } else {
302 319
    if (use_rcpp) {
303 -
      list_df <- convert_curve_avg_df(attr(obj, "grp_avg"), uniq_modnames,
304 -
                                      match(modnames, uniq_modnames),
305 -
                                      curvetype_names, x_bins)
320 +
      list_df <- convert_curve_avg_df(
321 +
        attr(obj, "grp_avg"), uniq_modnames,
322 +
        match(modnames, uniq_modnames),
323 +
        curvetype_names, x_bins
324 +
      )
306 325
      .check_cpp_func_error(list_df, "convert_curve_avg_df")
307 326
      curve_df <- list_df[["df"]]
308 327
    } else {
309 -
      curve_df <- .dataframe_curve_avg(obj, uniq_modnames, uniq_dsids, modnames,
310 -
                                       dsids, dsid_modnames, curvetype_names)
328 +
      curve_df <- .dataframe_curve_avg(
329 +
        obj, uniq_modnames, uniq_dsids, modnames,
330 +
        dsids, dsid_modnames, curvetype_names
331 +
      )
311 332
      warning("R version of .dataframe_common is used")
312 333
    }
313 -
314 334
  }
315 335
316 336
  if (!check_ggplot) {
317 337
    if ("dsid_modname" %in% names(curve_df)) {
318 -
      curve_df <- with(curve_df, subset(curve_df, select = -dsid_modname))
338 +
      curve_df[["dsid_modname"]] <- NULL
319 339
    }
320 340
    colnum <- ncol(curve_df)
321 341
    names(curve_df) <- c(names(curve_df)[1:(colnum - 1)], "type")
@@ -329,7 +349,6 @@
Loading
329 349
#
330 350
.dataframe_curve <- function(obj, uniq_modnames, uniq_dsids, modnames, dsids,
331 351
                             dsid_modnames, curvetype_names) {
332 -
333 352
  curve_df <- NULL
334 353
  for (curvetype in names(curvetype_names)) {
335 354
    curves <- obj[[curvetype_names[[curvetype]]]]
@@ -339,15 +358,21 @@
Loading
339 358
340 359
      modname <- factor(rep(modnames[i], length(x)), levels = uniq_modnames)
341 360
      dsid <- factor(rep(dsids[i], length(x)), levels = uniq_dsids)
342 -
      dsid_modname <- factor(rep(paste(modnames[i], dsids[i], sep = ":"),
343 -
                                 length(x)),
344 -
                             levels = dsid_modnames)
361 +
      dsid_modname <- factor(rep(
362 +
        paste(modnames[i], dsids[i], sep = ":"),
363 +
        length(x)
364 +
      ),
365 +
      levels = dsid_modnames
366 +
      )
345 367
      curvename <- factor(rep(curvetype, length(x)),
346 -
                          levels = names(curvetype_names))
347 -
      curve_df <- rbind(curve_df, data.frame(x = x, y = y, modname = modname,
348 -
                                             dsid = dsid,
349 -
                                             dsid_modname = dsid_modname,
350 -
                                             curvetype = curvename))
368 +
        levels = names(curvetype_names)
369 +
      )
370 +
      curve_df <- rbind(curve_df, data.frame(
371 +
        x = x, y = y, modname = modname,
372 +
        dsid = dsid,
373 +
        dsid_modname = dsid_modname,
374 +
        curvetype = curvename
375 +
      ))
351 376
    }
352 377
  }
353 378
@@ -357,9 +382,8 @@
Loading
357 382
#
358 383
# Make a dataframe for plotting with average curves
359 384
#
360 -
.dataframe_curve_avg <- function(obj, uniq_modnames, uniq_dsids, modnames, dsids,
361 -
                               dsid_modnames, curvetype_names) {
362 -
385 +
.dataframe_curve_avg <- function(obj, uniq_modnames, uniq_dsids, modnames,
386 +
                                 dsids, dsid_modnames, curvetype_names) {
363 387
  grp_avg <- attr(obj, "grp_avg")
364 388
  curve_df <- NULL
365 389
  for (curvetype in names(curvetype_names)) {
@@ -372,13 +396,17 @@
Loading
372 396
      ymax <- avgcurves[[i]][["y_ci_h"]]
373 397
374 398
      modname <- factor(rep(uniq_modnames[i], length(x)),
375 -
                        levels = uniq_modnames)
399 +
        levels = uniq_modnames
400 +
      )
376 401
      curvename <- factor(rep(curvetype, length(x)),
377 -
                          levels = names(curvetype_names))
378 -
      curve_df <- rbind(curve_df, data.frame(x = x, y = y,
379 -
                                             ymin = ymin, ymax = ymax,
380 -
                                             modname = modname,
381 -
                                             curvetype = curvename))
402 +
        levels = names(curvetype_names)
403 +
      )
404 +
      curve_df <- rbind(curve_df, data.frame(
405 +
        x = x, y = y,
406 +
        ymin = ymin, ymax = ymax,
407 +
        modname = modname,
408 +
        curvetype = curvename
409 +
      ))
382 410
    }
383 411
  }
384 412
@@ -389,7 +417,6 @@
Loading
389 417
# Process ... for curve objects
390 418
#
391 419
.get_dataframe_arglist <- function(evalmod_args, def_raw_curves, ...) {
392 -
393 420
  arglist <- list(...)
394 421
395 422
  if (is.null(arglist[["raw_curves"]])) {
@@ -404,4 +431,3 @@
Loading
404 431
405 432
  arglist
406 433
}
407 -

@@ -97,11 +97,12 @@
Loading
97 97
#'   the supporting points are calculated. \code{x_bins} is effective only
98 98
#'   when \code{mode} is set to \code{rocprc} or \code{prcroc}.
99 99
#'
100 -
#' @param interpolate A Boolean value to specify whether or not interpolation of
101 -
#'   ROC and precision-recall curves are performed. \code{x_bins} and \code{calc_avg} are
102 -
#'    ignored and  when \code{x_bins} is set to \code{FALSE}.
103 -
#'    \code{interpolate} is effective only when \code{mode} is set
104 -
#'    to \code{rocprc} or \code{prcroc}.
100 +
#' @param interpolate A Boolean value to specify whether or not
101 +
#'   interpolation of ROC and precision-recall curves are
102 +
#'   performed. \code{x_bins} and \code{calc_avg} are
103 +
#'   ignored and  when \code{x_bins} is set to \code{FALSE}.
104 +
#'   \code{interpolate} is effective only when \code{mode} is set
105 +
#'   to \code{rocprc} or \code{prcroc}.
105 106
#'
106 107
#' @param ... These additional arguments are passed to \code{\link{mmdata}}
107 108
#'   for data preparation.
@@ -151,7 +152,8 @@
Loading
151 152
#'   }
152 153
#'
153 154
#'   \item The \code{evalmod} function returns the \code{aucroc} S3 object
154 -
#'   when \code{mode} is "aucroc", which can be used with 'print' and 'as.data.frame'.
155 +
#'   when \code{mode} is "aucroc", which can be used with 'print'
156 +
#'   and 'as.data.frame'.
155 157
#'
156 158
#' }
157 159
#'
@@ -179,8 +181,10 @@
Loading
179 181
#' sscurves
180 182
#'
181 183
#' ## Generate an sspoints object that contains basic evaluation measures
182 -
#' sspoints <- evalmod(mode = "basic", scores = P10N10$scores,
183 -
#'                     labels = P10N10$labels)
184 +
#' sspoints <- evalmod(
185 +
#'   mode = "basic", scores = P10N10$scores,
186 +
#'   labels = P10N10$labels
187 +
#' )
184 188
#' sspoints
185 189
#'
186 190
#'
@@ -191,7 +195,8 @@
Loading
191 195
#' ## Create sample datasets with 100 positives and 100 negatives
192 196
#' samps <- create_sim_samples(1, 100, 100, "all")
193 197
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
194 -
#'                modnames = samps[["modnames"]])
198 +
#'   modnames = samps[["modnames"]]
199 +
#' )
195 200
#'
196 201
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
197 202
#' mscurves <- evalmod(mdat)
@@ -209,8 +214,9 @@
Loading
209 214
#' ## Create sample datasets with 100 positives and 100 negatives
210 215
#' samps <- create_sim_samples(4, 100, 100, "good_er")
211 216
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
212 -
#'                modnames = samps[["modnames"]],
213 -
#'                dsids = samps[["dsids"]])
217 +
#'   modnames = samps[["modnames"]],
218 +
#'   dsids = samps[["dsids"]]
219 +
#' )
214 220
#'
215 221
#' ## Generate an smcurve object that contains ROC and Precision-Recall curves
216 222
#' smcurves <- evalmod(mdat)
@@ -228,8 +234,9 @@
Loading
228 234
#' ## Create sample datasets with 100 positives and 100 negatives
229 235
#' samps <- create_sim_samples(4, 100, 100, "all")
230 236
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
231 -
#'                modnames = samps[["modnames"]],
232 -
#'                dsids = samps[["dsids"]])
237 +
#'   modnames = samps[["modnames"]],
238 +
#'   dsids = samps[["dsids"]]
239 +
#' )
233 240
#'
234 241
#' ## Generate an mmcurve object that contains ROC and Precision-Recall curves
235 242
#' mmcurves <- evalmod(mdat)
@@ -248,9 +255,11 @@
Loading
248 255
#' data(M2N50F5)
249 256
#'
250 257
#' ## Speficy nessesary columns to create mdat
251 -
#' cvdat <- mmdata(nfold_df = M2N50F5, score_cols = c(1, 2),
252 -
#'                 lab_col = 3, fold_col = 4,
253 -
#'                 modnames = c("m1", "m2"), dsids = 1:5)
258 +
#' cvdat <- mmdata(
259 +
#'   nfold_df = M2N50F5, score_cols = c(1, 2),
260 +
#'   lab_col = 3, fold_col = 4,
261 +
#'   modnames = c("m1", "m2"), dsids = 1:5
262 +
#' )
254 263
#'
255 264
#' ## Generate an mmcurve object that contains ROC and Precision-Recall curves
256 265
#' cvcurves <- evalmod(cvdat)
@@ -261,9 +270,11 @@
Loading
261 270
#' cvpoints
262 271
#'
263 272
#' ## Specify mmdata arguments from evalmod
264 -
#' cvcurves2 <- evalmod(nfold_df = M2N50F5, score_cols = c(1, 2),
265 -
#'                      lab_col = 3, fold_col = 4,
266 -
#'                      modnames = c("m1", "m2"), dsids = 1:5)
273 +
#' cvcurves2 <- evalmod(
274 +
#'   nfold_df = M2N50F5, score_cols = c(1, 2),
275 +
#'   lab_col = 3, fold_col = 4,
276 +
#'   modnames = c("m1", "m2"), dsids = 1:5
277 +
#' )
267 278
#' cvcurves2
268 279
#'
269 280
#'
@@ -275,8 +286,10 @@
Loading
275 286
#' data(P10N10)
276 287
#'
277 288
#' # 'aucroc' S3 object
278 -
#' uauc1 <- evalmod(scores = P10N10$scores, labels = P10N10$labels,
279 -
#'                  mode="aucroc")
289 +
#' uauc1 <- evalmod(
290 +
#'   scores = P10N10$scores, labels = P10N10$labels,
291 +
#'   mode = "aucroc"
292 +
#' )
280 293
#'
281 294
#' # print 'aucroc'
282 295
#' uauc1
@@ -290,13 +303,13 @@
Loading
290 303
#'
291 304
#' # a function to test mode = "rocprc"
292 305
#' func_evalmod_rocprc <- function(samp) {
293 -
#'    curves <- evalmod(scores = samp$scores, labels = samp$labels)
294 -
#'    aucs <- auc(curves)
306 +
#'   curves <- evalmod(scores = samp$scores, labels = samp$labels)
307 +
#'   aucs <- auc(curves)
295 308
#' }
296 309
#'
297 310
#' # a function to test mode = "aucroc"
298 311
#' func_evalmod_aucroc <- function(samp) {
299 -
#'   uaucs <- evalmod(scores = samp$scores, labels = samp$labels, mode="aucroc")
312 +
#'   uaucs <- evalmod(scores = samp$scores, labels = samp$labels, mode = "aucroc")
300 313
#'   as.data.frame(uaucs)
301 314
#' }
302 315
#'
@@ -322,25 +335,29 @@
Loading
322 335
  if (x_bins == 0) {
323 336
    x_bins <- 1
324 337
  }
325 -
  .validate_evalmod_args(new_mode, modnames, dsids, posclass, new_na_worst,
326 -
                         new_ties_method, calc_avg, cb_alpha, raw_curves,
327 -
                         x_bins, interpolate)
338 +
  .validate_evalmod_args(
339 +
    new_mode, modnames, dsids, posclass, new_na_worst,
340 +
    new_ties_method, calc_avg, cb_alpha, raw_curves,
341 +
    x_bins, interpolate
342 +
  )
328 343
329 344
  # Create mdat if not provided
330 345
  if (missing(mdat)) {
331 346
    mdat <- mmdata(scores, labels,
332 -
                   modnames = modnames, dsids = dsids, posclass = posclass,
333 -
                   na_worst = new_na_worst, ties_method = new_ties_method,
334 -
                   mode = new_mode, ...)
347 +
      modnames = modnames, dsids = dsids, posclass = posclass,
348 +
      na_worst = new_na_worst, ties_method = new_ties_method,
349 +
      mode = new_mode, ...
350 +
    )
335 351
  }
336 352
  .validate(mdat)
337 353
338 354
  # Call pipeline controller
339 -
  pl_main(mdat, mode = new_mode, calc_avg = calc_avg, cb_alpha = cb_alpha,
340 -
          raw_curves = raw_curves, x_bins = x_bins, interpolate = interpolate,
341 -
          na_worst = new_na_worst,ties_method = new_ties_method,
342 -
          validate = FALSE)
343 -
355 +
  pl_main(mdat,
356 +
    mode = new_mode, calc_avg = calc_avg, cb_alpha = cb_alpha,
357 +
    raw_curves = raw_curves, x_bins = x_bins, interpolate = interpolate,
358 +
    na_worst = new_na_worst, ties_method = new_ties_method,
359 +
    validate = FALSE
360 +
  )
344 361
}
345 362
346 363
#
@@ -356,10 +373,13 @@
Loading
356 373
  new_mode <- NA
357 374
  if (!is.null(mode)) {
358 375
    new_mode <- .pmatch_mode(mode)
359 -
    if (new_mode != "aucroc" && !is.na(mdat_mode) &&  mdat_mode == "aucroc") {
360 -
      stop(paste0("Invalid 'mode': evalmod <- '", new_mode,
361 -
                  "'', mmdata <- '", mdat_mode, "'"),
362 -
           call. = FALSE)
376 +
    if (new_mode != "aucroc" && !is.na(mdat_mode) && mdat_mode == "aucroc") {
377 +
      stop(paste0(
378 +
        "Invalid 'mode': evalmod <- '", new_mode,
379 +
        "'', mmdata <- '", mdat_mode, "'"
380 +
      ),
381 +
      call. = FALSE
382 +
      )
363 383
    }
364 384
  } else if (!is.na(mdat_mode)) {
365 385
    new_mode <- mdat_mode
@@ -414,5 +434,4 @@
Loading
414 434
415 435
  # Check interpolate
416 436
  .validate_interpolate(interpolate)
417 -
418 437
}

@@ -6,8 +6,10 @@
Loading
6 6
7 7
  # === Validate input arguments ===
8 8
  # Create pevals from scores and labels if pevals is missing
9 -
  pevals <- .create_src_obj(pevals, "pevals", calc_measures, scores, labels,
10 -
                                 ...)
9 +
  pevals <- .create_src_obj(
10 +
    pevals, "pevals", calc_measures, scores, labels,
11 +
    ...
12 +
  )
11 13
12 14
  if (is.null(x_bins) || any(is.na(x_bins))) {
13 15
    x_bins <- 1
@@ -16,10 +18,14 @@
Loading
16 18
  .validate(pevals)
17 19
18 20
  # === Create ROC and Precision-Recall curves ===
19 -
  roc_curve <- create_roc(pevals, x_bins = x_bins,
20 -
                          keep_pevals = keep_pevals, ...)
21 -
  prc_curve <- create_prc(pevals, x_bins = x_bins,
22 -
                          keep_pevals = keep_pevals, ...)
21 +
  roc_curve <- create_roc(pevals,
22 +
    x_bins = x_bins,
23 +
    keep_pevals = keep_pevals, ...
24 +
  )
25 +
  prc_curve <- create_prc(pevals,
26 +
    x_bins = x_bins,
27 +
    keep_pevals = keep_pevals, ...
28 +
  )
23 29
24 30
  curves <- list(roc = roc_curve, prc = prc_curve)
25 31
@@ -50,9 +56,11 @@
Loading
50 56
                       keep_pevals = FALSE, ...) {
51 57
52 58
  # === Create a ROC curve ===
53 -
  .create_curve("specificity", "sensitivity", create_roc_curve,
54 -
                "create_roc_curve", "roc_curve", pevals, scores, labels,
55 -
                x_bins, keep_pevals, ...)
59 +
  .create_curve(
60 +
    "specificity", "sensitivity", create_roc_curve,
61 +
    "create_roc_curve", "roc_curve", pevals, scores, labels,
62 +
    x_bins, keep_pevals, ...
63 +
  )
56 64
}
57 65
58 66
#
@@ -62,9 +70,11 @@
Loading
62 70
                       keep_pevals = FALSE, ...) {
63 71
64 72
  # === Create a Precision-Recall curve ===
65 -
  .create_curve("sensitivity", "precision", create_prc_curve,
66 -
                "create_prc_curve", "prc_curve", pevals, scores, labels,
67 -
                x_bins, keep_pevals, ...)
73 +
  .create_curve(
74 +
    "sensitivity", "precision", create_prc_curve,
75 +
    "create_prc_curve", "prc_curve", pevals, scores, labels,
76 +
    x_bins, keep_pevals, ...
77 +
  )
68 78
}
69 79
70 80
#
@@ -76,23 +86,29 @@
Loading
76 86
77 87
  # === Validate input arguments ===
78 88
  # Create pevals from scores and labels if pevals is missing
79 -
  pevals <- .create_src_obj(pevals, "pevals", calc_measures, scores, labels,
80 -
                            ...)
89 +
  pevals <- .create_src_obj(
90 +
    pevals, "pevals", calc_measures, scores, labels,
91 +
    ...
92 +
  )
81 93
  .validate_x_bins(x_bins, allow_zero = TRUE)
82 94
  .validate(pevals)
83 95
84 96
  # === Create a curve ===
85 97
  # Calculate a curve
86 98
  pb <- pevals[["basic"]]
87 -
  crv <- func(attr(pevals, "src")[["tp"]], attr(pevals, "src")[["fp"]],
88 -
              pb[[x_name]], pb[[y_name]], x_bins)
99 +
  crv <- func(
100 +
    attr(pevals, "src")[["tp"]], attr(pevals, "src")[["fp"]],
101 +
    pb[[x_name]], pb[[y_name]], x_bins
102 +
  )
89 103
  .check_cpp_func_error(crv, func_name)
90 104
91 105
  # Calculate AUC
92 106
  auc <- calc_auc(crv[["curve"]][["x"]], crv[["curve"]][["y"]])
93 107
  if (auc[["errmsg"]] == "invalid-x-vals") {
94 -
    warning(paste0("Invalid ", x_name,
95 -
                   " values detected. AUC can be inaccurate."))
108 +
    warning(paste0(
109 +
      "Invalid ", x_name,
110 +
      " values detected. AUC can be inaccurate."
111 +
    ))
96 112
  } else {
97 113
    .check_cpp_func_error(auc, "calc_auc")
98 114
  }
@@ -163,26 +179,32 @@
Loading
163 179
.validate_curve <- function(obj, class_name, func_name) {
164 180
  # Validate class items and attributes
165 181
  item_names <- c("x", "y", "orig_points")
166 -
  attr_names <- c("modname", "dsid", "nn", "np", "auc", "args",
167 -
                  "cpp_errmsg1", "cpp_errmsg2", "src", "validated")
168 -
  arg_names <- c("x_bins", "na_worst", "na.last", "ties_method", "ties.method",
169 -
                 "modname", "dsid", "keep_fmdat", "keep_cmats")
170 -
  .validate_basic(obj, class_name, func_name, item_names, attr_names,
171 -
                  arg_names)
182 +
  attr_names <- c(
183 +
    "modname", "dsid", "nn", "np", "auc", "args",
184 +
    "cpp_errmsg1", "cpp_errmsg2", "src", "validated"
185 +
  )
186 +
  arg_names <- c(
187 +
    "x_bins", "na_worst", "na.last", "ties_method", "ties.method",
188 +
    "modname", "dsid", "keep_fmdat", "keep_cmats"
189 +
  )
190 +
  .validate_basic(
191 +
    obj, class_name, func_name, item_names, attr_names,
192 +
    arg_names
193 +
  )
172 194
173 195
  # Check values of class items
174 -
  if ((length(obj[["x"]]) != length(obj[["y"]]))
175 -
      || (length(obj[["x"]]) != length(obj[["orig_points"]]))) {
196 +
  if ((length(obj[["x"]]) != length(obj[["y"]])) ||
197 +
    (length(obj[["x"]]) != length(obj[["orig_points"]]))) {
176 198
    stop("x, y, and orig_points must be all the same lengths", call. = FALSE)
177 199
  } else if (!(length(obj[["x"]]) > 2)) {
178 200
    stop("The minimum length of x, y, and orig_points must be 3",
179 -
         call. = FALSE)
201 +
      call. = FALSE
202 +
    )
180 203
  }
181 204
182 205
  # Check values of class attributes
183 206
  # AUC
184 207
  assertthat::assert_that((attr(obj, "auc") >= 0) && (attr(obj, "auc") <= 1))
185 -
186 208
}
187 209
188 210
#
@@ -196,12 +218,18 @@
Loading
196 218
197 219
  # Validate class items and attributes
198 220
  item_names <- c("roc", "prc")
199 -
  attr_names <- c("modname", "dsid", "nn", "np", "args", "src",
200 -
                  "validated")
201 -
  arg_names <- c("x_bins", "na_worst", "na.last", "ties_method", "ties.method",
202 -
                 "modname", "dsid", "keep_fmdat", "keep_cmats")
203 -
  .validate_basic(curves, "curves", "calc_measures", item_names, attr_names,
204 -
                  arg_names)
221 +
  attr_names <- c(
222 +
    "modname", "dsid", "nn", "np", "args", "src",
223 +
    "validated"
224 +
  )
225 +
  arg_names <- c(
226 +
    "x_bins", "na_worst", "na.last", "ties_method", "ties.method",
227 +
    "modname", "dsid", "keep_fmdat", "keep_cmats"
228 +
  )
229 +
  .validate_basic(
230 +
    curves, "curves", "calc_measures", item_names, attr_names,
231 +
    arg_names
232 +
  )
205 233
206 234
  # Check values of class items
207 235
  curves[["roc"]] <- .validate(curves[["roc"]])

@@ -2,10 +2,11 @@
Loading
2 2
# Check if an internal Rcpp function returns en error
3 3
#
4 4
.check_cpp_func_error <- function(obj, func_name) {
5 -
6 5
  if (obj[["errmsg"]] != "") {
7 -
    stop(paste0("Internal cpp function (", func_name, "()) failed: ",
8 -
                obj[["errmsg"]]), call. = FALSE)
6 +
    stop(paste0(
7 +
      "Internal cpp function (", func_name, "()) failed: ",
8 +
      obj[["errmsg"]]
9 +
    ), call. = FALSE)
9 10
  }
10 11
}
11 12
@@ -39,7 +40,7 @@
Loading
39 40
# Use scores and labels to create obj
40 41
#
41 42
.create_src_obj <- function(obj, obj_name, func, scores, labels,
42 -
                                         ...) {
43 +
                            ...) {
43 44
  if (missing(obj)) {
44 45
    if (!is.null(scores) && !is.null(labels)) {
45 46
      obj <- func(scores = scores, labels = labels, ...)
@@ -58,8 +59,10 @@
Loading
58 59
  if (mode == "rocprc" || mode == "prcroc") {
59 60
    mnames <- c("ROC", "PRC")
60 61
  } else if (mode == "basic") {
61 -
    mnames <- c("score", "label", "error", "accuracy", "specificity",
62 -
                "sensitivity", "precision", "mcc", "fscore")
62 +
    mnames <- c(
63 +
      "score", "label", "error", "accuracy", "specificity",
64 +
      "sensitivity", "precision", "mcc", "fscore"
65 +
    )
63 66
  }
64 67
65 68
  mnames
@@ -93,8 +96,8 @@
Loading
93 96
    np <- nps[i]
94 97
    nn <- nns[i]
95 98
96 -
    if ((!is.na(prev_np) && np != prev_np)
97 -
        ||  (!is.na(prev_nn) && nn != prev_nn)) {
99 +
    if ((!is.na(prev_np) && np != prev_np) ||
100 +
      (!is.na(prev_nn) && nn != prev_nn)) {
98 101
      is_consistant <- FALSE
99 102
    }
100 103
@@ -110,8 +113,8 @@
Loading
110 113
111 114
  prc_base <- avg_np / (avg_np + avg_nn)
112 115
113 -
  list(avg_np = avg_np, avg_nn = avg_nn, is_consistant = is_consistant,
114 -
       prc_base = prc_base)
115 -
116 +
  list(
117 +
    avg_np = avg_np, avg_nn = avg_nn, is_consistant = is_consistant,
118 +
    prc_base = prc_base
119 +
  )
116 120
}
117 -

@@ -53,18 +53,20 @@
Loading
53 53
#'  five different performance levels.
54 54
#'
55 55
#' @section Data visualization:
56 -
#' \code{\link{plot}} takes an \code{S3} object generated by \code{\link{evalmod}} as input
57 -
#' and plot corresponding curves.
56 +
#' \code{\link{plot}} takes an \code{S3} object generated
57 +
#' by \code{\link{evalmod}} as input and plot corresponding curves.
58 58
#'
59 59
#' \code{\link{autoplot}} uses \code{ggplot} to plot curves.
60 60
#'
61 61
#' @section Result retrieval:
62 -
#' \code{\link{as.data.frame}} takes an \code{S3} object generated by \code{\link{evalmod}}
63 -
#' as input and and returns a data frame with calculated curve points.
62 +
#' \code{\link{as.data.frame}} takes an \code{S3} object generated
63 +
#' by \code{\link{evalmod}} as input and and returns a data frame
64 +
#' with calculated curve points.
64 65
#'
65 66
#' \code{\link{auc}} and \code{\link{pauc}} returns a data frame with AUC scores
66 -
#' and partial AUC scores, respectively. \code{\link{auc_ci}} returns confidence intervals
67 -
#' of AUCs for both ROC and precision-recall curves.
67 +
#' and partial AUC scores, respectively. \code{\link{auc_ci}}
68 +
#' returns confidence intervals of AUCs for both ROC
69 +
#' and precision-recall curves.
68 70
#'
69 71
#'
70 72
#' @docType package
@@ -75,7 +77,8 @@
Loading
75 77
#' @importFrom ggplot2 autoplot
76 78
#' @importFrom ggplot2 fortify
77 79
#' @importFrom grDevices col2rgb rainbow rgb
78 -
#' @importFrom graphics abline layout legend lines matplot par plot plot.new polygon
80 +
#' @importFrom graphics abline layout legend lines
81 +
#' @importFrom matplot par plot plot.new polygon
79 82
#' @importFrom methods is
80 83
#' @importFrom stats qnorm rbeta rnorm sd qt
81 84
#' @importFrom data.table frank

@@ -24,13 +24,22 @@
Loading
24 24
25 25
  # === Prepare a data frame for ggplot2 ===
26 26
  n <- length(model[["ranks"]])
27 -
  data.frame(x = rep(seq_len(length(model[["ranks"]])), 4),
28 -
             y = c(model[["tp"]], model[["fn"]],
29 -
                   model[["fp"]], model[["tn"]]),
30 -
             group = factor(c(rep("TPs", n), rep("FNs", n),
31 -
                              rep("FPs", n), rep("TNs", n)),
32 -
                            levels = c("TPs", "FNs",
33 -
                                       "FPs", "TNs")))
27 +
  data.frame(
28 +
    x = rep(seq_len(length(model[["ranks"]])), 4),
29 +
    y = c(
30 +
      model[["tp"]], model[["fn"]],
31 +
      model[["fp"]], model[["tn"]]
32 +
    ),
33 +
    group = factor(c(
34 +
      rep("TPs", n), rep("FNs", n),
35 +
      rep("FPs", n), rep("TNs", n)
36 +
    ),
37 +
    levels = c(
38 +
      "TPs", "FNs",
39 +
      "FPs", "TNs"
40 +
    )
41 +
    )
42 +
  )
34 43
}
35 44
36 45
#
@@ -46,108 +55,133 @@
Loading
46 55
  # === Prepare a data frame for ggplot2 ===
47 56
  pb <- model[["basic"]]
48 57
  n <- length(pb[["error"]])
49 -
  data.frame(x = rep(1:n, 10),
50 -
             y = c(pb[["score"]], pb[["label"]],
51 -
                   pb[["error"]], pb[["accuracy"]],
52 -
                   pb[["specificity"]], pb[["sensitivity"]],
53 -
                   1 - pb[["specificity"]], pb[["precision"]],
54 -
                   pb[["mcc"]], pb[["fscore"]]),
55 -
             group = factor(c(rep("score", n),
56 -
                              rep("label", n),
57 -
                              rep("error", n),
58 -
                              rep("accuracy", n),
59 -
                              rep("specificity", n),
60 -
                              rep("sensitivity", n),
61 -
                              rep("1 - specificity", n),
62 -
                              rep("precision", n),
63 -
                              rep("mcc", n),
64 -
                              rep("fscore", n)),
65 -
                            levels = c("score", "label",
66 -
                                       "error", "accuracy",
67 -
                                       "specificity",
68 -
                                       "sensitivity",
69 -
                                       "1 - specificity",
70 -
                                       "precision",
71 -
                                       "mcc",
72 -
                                       "fscore")))
58 +
  data.frame(
59 +
    x = rep(1:n, 10),
60 +
    y = c(
61 +
      pb[["score"]], pb[["label"]],
62 +
      pb[["error"]], pb[["accuracy"]],
63 +
      pb[["specificity"]], pb[["sensitivity"]],
64 +
      1 - pb[["specificity"]], pb[["precision"]],
65 +
      pb[["mcc"]], pb[["fscore"]]
66 +
    ),
67 +
    group = factor(c(
68 +
      rep("score", n),
69 +
      rep("label", n),
70 +
      rep("error", n),
71 +
      rep("accuracy", n),
72 +
      rep("specificity", n),
73 +
      rep("sensitivity", n),
74 +
      rep("1 - specificity", n),
75 +
      rep("precision", n),
76 +
      rep("mcc", n),
77 +
      rep("fscore", n)
78 +
    ),
79 +
    levels = c(
80 +
      "score", "label",
81 +
      "error", "accuracy",
82 +
      "specificity",
83 +
      "sensitivity",
84 +
      "1 - specificity",
85 +
      "precision",
86 +
      "mcc",
87 +
      "fscore"
88 +
    )
89 +
    )
90 +
  )
73 91
}
74 92
75 93
#' @rdname fortify
76 94
#' @export
77 95
fortify.sscurves <- function(model, raw_curves = NULL, reduce_points = FALSE,
78 96
                             ...) {
79 -
  .dataframe_common(model, raw_curves = TRUE, reduce_points = reduce_points,
80 -
                    check_ggplot = TRUE, ...)
97 +
  .dataframe_common(model,
98 +
    raw_curves = TRUE, reduce_points = reduce_points,
99 +
    check_ggplot = TRUE, ...
100 +
  )
81 101
}
82 102
83 103
#' @rdname fortify
84 104
#' @export
85 105
fortify.mscurves <- function(model, raw_curves = NULL, reduce_points = FALSE,
86 106
                             ...) {
87 -
  .dataframe_common(model, raw_curves = TRUE, reduce_points = reduce_points,
88 -
                    check_ggplot = TRUE, ...)
107 +
  .dataframe_common(model,
108 +
    raw_curves = TRUE, reduce_points = reduce_points,
109 +
    check_ggplot = TRUE, ...
110 +
  )
89 111
}
90 112
91 113
#' @rdname fortify
92 114
#' @export
93 115
fortify.smcurves <- function(model, raw_curves = NULL, reduce_points = FALSE,
94 116
                             ...) {
95 -
96 117
  arglist <- .get_fortify_arglist(attr(model, "args"),
97 -
                                  def_raw_curves = raw_curves, ...)
118 +
    def_raw_curves = raw_curves, ...
119 +
  )
98 120
99 -
  .dataframe_common(model, raw_curves = arglist[["raw_curves"]],
100 -
                    reduce_points = reduce_points, check_ggplot = TRUE, ...)
121 +
  .dataframe_common(model,
122 +
    raw_curves = arglist[["raw_curves"]],
123 +
    reduce_points = reduce_points, check_ggplot = TRUE, ...
124 +
  )
101 125
}
102 126
103 127
#' @rdname fortify
104 128
#' @export
105 129
fortify.mmcurves <- function(model, raw_curves = NULL, reduce_points = FALSE,
106 130
                             ...) {
107 -
108 131
  arglist <- .get_fortify_arglist(attr(model, "args"),
109 -
                                  def_raw_curves = raw_curves, ...)
132 +
    def_raw_curves = raw_curves, ...
133 +
  )
110 134
111 -
  .dataframe_common(model, raw_curves = arglist[["raw_curves"]],
112 -
                    reduce_points = reduce_points, check_ggplot = TRUE, ...)
135 +
  .dataframe_common(model,
136 +
    raw_curves = arglist[["raw_curves"]],
137 +
    reduce_points = reduce_points, check_ggplot = TRUE, ...
138 +
  )
113 139
}
114 140
115 141
#' @rdname fortify
116 142
#' @export
117 143
fortify.sspoints <- function(model, raw_curves = NULL, reduce_points = FALSE,
118 144
                             ...) {
119 -
  .dataframe_common(model, mode = "basic", raw_curves = TRUE,
120 -
                    check_ggplot = TRUE, reduce_points = FALSE, ...)
145 +
  .dataframe_common(model,
146 +
    mode = "basic", raw_curves = TRUE,
147 +
    check_ggplot = TRUE, reduce_points = FALSE, ...
148 +
  )
121 149
}
122 150
123 151
#' @rdname fortify
124 152
#' @export
125 153
fortify.mspoints <- function(model, raw_curves = NULL, reduce_points = FALSE,
126 154
                             ...) {
127 -
  .dataframe_common(model, mode = "basic", raw_curves = TRUE,
128 -
                    check_ggplot = TRUE, reduce_points = FALSE, ...)
155 +
  .dataframe_common(model,
156 +
    mode = "basic", raw_curves = TRUE,
157 +
    check_ggplot = TRUE, reduce_points = FALSE, ...
158 +
  )
129 159
}
130 160
131 161
#' @rdname fortify
132 162
#' @export
133 163
fortify.smpoints <- function(model, raw_curves = NULL, reduce_points = FALSE,
134 164
                             ...) {
135 -
136 165
  arglist <- .get_fortify_arglist(attr(model, "args"),
137 -
                                  def_raw_curves = raw_curves, ...)
166 +
    def_raw_curves = raw_curves, ...
167 +
  )
138 168
139 -
  .dataframe_common(model, mode = "basic", raw_curves = arglist[["raw_curves"]],
140 -
                    check_ggplot = TRUE, reduce_points = FALSE, ...)
169 +
  .dataframe_common(model,
170 +
    mode = "basic", raw_curves = arglist[["raw_curves"]],
171 +
    check_ggplot = TRUE, reduce_points = FALSE, ...
172 +
  )
141 173
}
142 174
143 175
#' @rdname fortify
144 176
#' @export
145 177
fortify.mmpoints <- function(model, raw_curves = NULL, reduce_points = FALSE,
146 178
                             ...) {
147 -
148 179
  arglist <- .get_fortify_arglist(attr(model, "args"),
149 -
                                  def_raw_curves = raw_curves, ...)
180 +
    def_raw_curves = raw_curves, ...
181 +
  )
150 182
151 -
  .dataframe_common(model, mode = "basic", raw_curves = arglist[["raw_curves"]],
152 -
                    check_ggplot = TRUE, reduce_points = FALSE, ...)
183 +
  .dataframe_common(model,
184 +
    mode = "basic", raw_curves = arglist[["raw_curves"]],
185 +
    check_ggplot = TRUE, reduce_points = FALSE, ...
186 +
  )
153 187
}

@@ -23,8 +23,8 @@
Loading
23 23
#' @return The \code{auc} function returns a data frame with AUC scores.
24 24
#'
25 25
#' @seealso \code{\link{evalmod}} for generating \code{S3} objects with
26 -
#'   performance evaluation measures. \code{\link{pauc}} for retrieving a dataset
27 -
#'   of pAUCs.
26 +
#'   performance evaluation measures. \code{\link{pauc}} for retrieving
27 +
#'   a dataset of pAUCs.
28 28
#'
29 29
#' @examples
30 30
#'
@@ -49,7 +49,8 @@
Loading
49 49
#' ## Create sample datasets with 100 positives and 100 negatives
50 50
#' samps <- create_sim_samples(1, 100, 100, "all")
51 51
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
52 -
#'                modnames = samps[["modnames"]])
52 +
#'   modnames = samps[["modnames"]]
53 +
#' )
53 54
#'
54 55
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
55 56
#' mscurves <- evalmod(mdat)
@@ -65,8 +66,9 @@
Loading
65 66
#' ## Create sample datasets with 100 positives and 100 negatives
66 67
#' samps <- create_sim_samples(4, 100, 100, "good_er")
67 68
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
68 -
#'                modnames = samps[["modnames"]],
69 -
#'                dsids = samps[["dsids"]])
69 +
#'   modnames = samps[["modnames"]],
70 +
#'   dsids = samps[["dsids"]]
71 +
#' )
70 72
#'
71 73
#' ## Generate an smcurve object that contains ROC and Precision-Recall curves
72 74
#' smcurves <- evalmod(mdat, raw_curves = TRUE)
@@ -90,8 +92,9 @@
Loading
90 92
#' ## Create sample datasets with 100 positives and 100 negatives
91 93
#' samps <- create_sim_samples(4, 100, 100, "all")
92 94
#' mdat <- mmdata(samps[["scores"]], samps[["labels"]],
93 -
#'                modnames = samps[["modnames"]],
94 -
#'                dsids = samps[["dsids"]])
95 +
#'   modnames = samps[["modnames"]],
96 +
#'   dsids = samps[["dsids"]]
97 +
#' )
95 98
#'
96 99
#' ## Generate an mscurve object that contains ROC and Precision-Recall curves
97 100
#' mmcurves <- evalmod(mdat, raw_curves = TRUE)

@@ -2,7 +2,6 @@
Loading
2 2
# Validate scores and labels
3 3
#
4 4
.validate_scores_and_labels <- function(obj, obj_name, scores, labels, ...) {
5 -
6 5
  if (missing(obj) || is.null(obj)) {
7 6
8 7
    # Check if scores and labels are specified
@@ -11,11 +10,7 @@
Loading
11 10
    } else if (!is.null(scores) && is.null(labels)) {
12 11
      stop("Invalid labels", call. = FALSE)
13 12
    } else if (is.null(scores) && is.null(labels)) {
14 -
      if (is.null(obj)) {
15 -
        stop("Invalid scores & labels", call. = FALSE)
16 -
      } else {
17 -
        stop(paste0(obj_name, " must be specified"), call. = FALSE)
18 -
      }
13 +
      stop("Invalid scores & labels", call. = FALSE)
19 14
    }
20 15
21 16
    # Check scores
@@ -28,7 +23,6 @@
Loading
28 23
    if (length(labels) != length(scores)) {
29 24
      stop("scores and labels must be the same lengths", call. = FALSE)
30 25
    }
31 -
32 26
  } else if (!is.null(obj)) {
33 27
    # Validate the first argument
34 28
    obj <- .validate(obj)
@@ -39,29 +33,35 @@
Loading
39 33
40 34
# Check mode
41 35
.validate_mode <- function(mode) {
42 -
  assertthat::assert_that(assertthat::is.string(mode),
43 -
                          (mode == "rocprc"
44 -
                           || mode == "basic"
45 -
                           || mode == "aucroc"))
36 +
  assertthat::assert_that(
37 +
    assertthat::is.string(mode),
38 +
    (mode == "rocprc" ||
39 +
      mode == "basic" ||
40 +
      mode == "aucroc")
41 +
  )
46 42
}
47 43
48 44
#
49 45
# Validate scores
50 46
#
51 47
.validate_scores <- function(scores) {
52 -
  assertthat::assert_that(is.atomic(scores),
53 -
                          is.vector(scores),
54 -
                          is.numeric(scores),
55 -
                          length(scores) > 0L)
48 +
  assertthat::assert_that(
49 +
    is.atomic(scores),
50 +
    is.vector(scores),
51 +
    is.numeric(scores),
52 +
    length(scores) > 0L
53 +
  )
56 54
}
57 55
58 56
#
59 57
# Validate labels
60 58
#
61 59
.validate_labels <- function(labels) {
62 -
  assertthat::assert_that(is.atomic(labels),
63 -
                          (is.vector(labels) || is.factor(labels)),
64 -
                          length(labels) > 0L)
60 +
  assertthat::assert_that(
61 +
    is.atomic(labels),
62 +
    (is.vector(labels) || is.factor(labels)),
63 +
    length(labels) > 0L
64 +
  )
65 65
}
66 66
67 67
#
@@ -78,10 +78,11 @@
Loading
78 78
#
79 79
.validate_modnames <- function(modnames, datalen) {
80 80
  if (!is.null(modnames)) {
81 -
82 -
    assertthat::assert_that(is.vector(modnames),
83 -
                            is.character(modnames),
84 -
                            length(modnames) == datalen)
81 +
    assertthat::assert_that(
82 +
      is.vector(modnames),
83 +
      is.character(modnames),
84 +
      length(modnames) == datalen
85 +
    )
85 86
86 87
    for (i in seq_len(length(modnames))) {
87 88
      .validate_modname(modnames[i])
@@ -103,10 +104,11 @@
Loading
103 104
#
104 105
.validate_dsids <- function(dsids, datalen) {
105 106
  if (!is.null(dsids)) {
106 -
107 -
    assertthat::assert_that(is.vector(dsids),
108 -
                            is.numeric(dsids),
109 -
                            length(dsids) == datalen)
107 +
    assertthat::assert_that(
108 +
      is.vector(dsids),
109 +
      is.numeric(dsids),
110 +
      length(dsids) == datalen
111 +
    )
110 112
111 113
    for (i in seq_len(length(dsids))) {
112 114
      .validate_dsid(dsids[i])
@@ -119,9 +121,11 @@
Loading
119 121
#
120 122
.validate_posclass <- function(posclass) {
121 123
  if (!is.null(posclass)) {
122 -
    assertthat::assert_that(is.atomic(posclass),
123 -
                            (is.vector(posclass) || is.factor(posclass)),
124 -
                            length(posclass) == 1L)
124 +
    assertthat::assert_that(
125 +
      is.atomic(posclass),
126 +
      (is.vector(posclass) || is.factor(posclass)),
127 +
      length(posclass) == 1L
128 +
    )
125 129
  }
126 130
}
127 131
@@ -131,8 +135,10 @@
Loading
131 135
#
132 136
.validate_na_worst <- function(na_worst) {
133 137
  if (!is.null(na_worst)) {
134 -
    assertthat::assert_that(assertthat::is.flag(na_worst),
135 -
                            assertthat::noNA(na_worst))
138 +
    assertthat::assert_that(
139 +
      assertthat::is.flag(na_worst),
140 +
      assertthat::noNA(na_worst)
141 +
    )
136 142
  }
137 143
}
138 144
@@ -143,10 +149,12 @@
Loading
143 149
  if (!is.null(ties_method)) {
144 150
    assertthat::assert_that(assertthat::is.string(ties_method))
145 151
146 -
    choices = c("equiv", "random", "first")
152 +
    choices <- c("equiv", "random", "first")
147 153
    if (!(ties_method %in% choices)) {
148 -
      stop(gettextf("ties_method must be one of %s",
149 -
                    paste(dQuote(choices), collapse = ", ")), call. = FALSE)
154 +
      stop(gettextf(
155 +
        "ties_method must be one of %s",
156 +
        paste(dQuote(choices), collapse = ", ")
157 +
      ), call. = FALSE)
150 158
    }
151 159
  }
152 160
}
@@ -156,31 +164,11 @@
Loading
156 164
#
157 165
.validate_expd_first <- function(expd_first) {
158 166
  if (!is.null(expd_first)) {
159 -
    assertthat::assert_that(assertthat::is.string(expd_first),
160 -
                            (expd_first == "modnames"
161 -
                             || expd_first == "dsids"))
162 -
  }
163 -
}
164 -
165 -
#
166 -
# Validate model type
167 -
#
168 -
.validate_model_type <- function(model_type) {
169 -
  if (!is.null(model_type)) {
170 -
    assertthat::assert_that(assertthat::is.string(model_type),
171 -
                            (model_type == "single"
172 -
                             || model_type == "multiple"))
173 -
  }
174 -
}
175 -
176 -
#
177 -
# Validate data type
178 -
#
179 -
.validate_data_type <- function(data_type) {
180 -
  if (!is.null(data_type)) {
181 -
    assertthat::assert_that(assertthat::is.string(data_type),
182 -
                            (data_type == "single"
183 -
                             || data_type == "multiple"))
167 +
    assertthat::assert_that(
168 +
      assertthat::is.string(expd_first),
169 +
      (expd_first == "modnames" ||
170 +
        expd_first == "dsids")
171 +
    )
184 172
  }
185 173
}
186 174
@@ -189,8 +177,10 @@
Loading
189 177
#
190 178
.validate_calc_avg <- function(calc_avg) {
191 179
  if (!is.null(calc_avg)) {
192 -
    assertthat::assert_that(assertthat::is.flag(calc_avg),
193 -
                            assertthat::noNA(calc_avg))
180 +
    assertthat::assert_that(
181 +
      assertthat::is.flag(calc_avg),
182 +
      assertthat::noNA(calc_avg)
183 +
    )
194 184
  }
195 185
}
196 186
@@ -199,8 +189,10 @@
Loading
199 189
#
200 190
.validate_cb_alpha <- function(cb_alpha, calc_avg = NULL) {
201 191
  if (!is.null(cb_alpha)) {
202 -
    assertthat::assert_that(assertthat::is.number(cb_alpha),
203 -
                            cb_alpha >= 0 && cb_alpha <= 1)
192 +
    assertthat::assert_that(
193 +
      assertthat::is.number(cb_alpha),
194 +
      cb_alpha >= 0 && cb_alpha <= 1
195 +
    )
204 196
    if (!is.null(calc_avg)) {
205 197
      if (!calc_avg && cb_alpha) {
206 198
        warning("cb_alpha is ignored when calc_avg = FALSE", call. = FALSE)
@@ -214,8 +206,10 @@
Loading
214 206
#
215 207
.validate_raw_curves <- function(raw_curves, calc_avg = NULL) {
216 208
  if (!is.null(raw_curves)) {
217 -
    assertthat::assert_that(assertthat::is.flag(raw_curves),
218 -
                            assertthat::noNA(raw_curves))
209 +
    assertthat::assert_that(
210 +
      assertthat::is.flag(raw_curves),
211 +
      assertthat::noNA(raw_curves)
212 +
    )
219 213
    if (!is.null(calc_avg)) {
220 214
      if (!calc_avg && raw_curves) {
221 215
        warning("raw_curves is ignored when calc_avg = FALSE", call. = FALSE)
@@ -227,7 +221,7 @@
Loading
227 221
#
228 222
# Validate x_bins
229 223
#
230 -
.validate_x_bins <- function(x_bins, allow_zero=FALSE) {
224 +
.validate_x_bins <- function(x_bins, allow_zero = FALSE) {
231 225
  if (allow_zero) {
232 226
    min_x_bin <- 0
233 227
  } else {
@@ -235,9 +229,11 @@
Loading
235 229
  }
236 230
237 231
  if (!is.null(x_bins) && all(!is.na(x_bins))) {
238 -
    assertthat::assert_that(assertthat::is.number(x_bins),
239 -
                            x_bins %% 1 == 0,
240 -
                            x_bins >= min_x_bin)
232 +
    assertthat::assert_that(
233 +
      assertthat::is.number(x_bins),
234 +
      x_bins %% 1 == 0,
235 +
      x_bins >= min_x_bin
236 +
    )
241 237
  }
242 238
}
243 239
@@ -253,46 +249,50 @@
Loading
253 249
# Check score column names
254 250
.validate_score_cols <- function(score_cols, nfold_df) {
255 251
  assertthat::assert_that(is.vector(score_cols))
256 -
  assertthat::assert_that(is.numeric(score_cols)
257 -
                          || is.character(score_cols))
252 +
  assertthat::assert_that(is.numeric(score_cols) ||
253 +
    is.character(score_cols))
258 254
259 255
  if (is.numeric(score_cols)) {
260 256
    assertthat::assert_that(all(score_cols <= ncol(nfold_df)),
261 -
                            msg = "Invalid score_cols")
257 +
      msg = "Invalid score_cols"
258 +
    )
262 259
  } else if (is.character(score_cols)) {
263 260
    assertthat::assert_that(all(score_cols %in% colnames(nfold_df)),
264 -
                            msg = "Invalid score_cols")
261 +
      msg = "Invalid score_cols"
262 +
    )
265 263
  }
266 -
267 264
}
268 265
269 266
# Check label column name
270 267
.validate_lab_col <- function(lab_col, nfold_df) {
271 -
  assertthat::assert_that(assertthat::see_if(assertthat::is.number(lab_col))
272 -
                          || assertthat::see_if(assertthat::is.string(lab_col)))
268 +
  assertthat::assert_that(assertthat::see_if(assertthat::is.number(lab_col)) ||
269 +
    assertthat::see_if(assertthat::is.string(lab_col)))
273 270
274 271
  if (assertthat::see_if(assertthat::is.number(lab_col))) {
275 272
    assertthat::assert_that(lab_col <= ncol(nfold_df),
276 -
                            msg = "Invalid lab_col")
273 +
      msg = "Invalid lab_col"
274 +
    )
277 275
  } else if (assertthat::see_if(assertthat::is.string(lab_col))) {
278 276
    assertthat::assert_that(lab_col %in% colnames(nfold_df),
279 -
                            msg = "Invalid lab_col")
277 +
      msg = "Invalid lab_col"
278 +
    )
280 279
  }
281 280
}
282 281
283 282
# Check fold column name
284 283
.validate_fold_col <- function(fold_col, nfold_df) {
285 -
  assertthat::assert_that(assertthat::see_if(assertthat::is.number(fold_col))
286 -
                          || assertthat::see_if(assertthat::is.string(fold_col)))
284 +
  assertthat::assert_that(assertthat::see_if(assertthat::is.number(fold_col)) ||
285 +
    assertthat::see_if(assertthat::is.string(fold_col)))
287 286
288 287
  if (assertthat::see_if(assertthat::is.number(fold_col))) {
289 288
    assertthat::assert_that(fold_col <= ncol(nfold_df),
290 -
                            msg = "Invalid fold_col")
289 +
      msg = "Invalid fold_col"
290 +
    )
291 291
  } else if (assertthat::see_if(assertthat::is.string(fold_col))) {
292 292
    assertthat::assert_that(fold_col %in% colnames(nfold_df),
293 -
                            msg = "Invalid fold_col")
293 +
      msg = "Invalid fold_col"
294 +
    )
294 295
  }
295 -
296 296
}
297 297
298 298
# Check mode
@@ -312,19 +312,23 @@
Loading
312 312
  basic_eval <- TRUE
313 313
314 314
  cfunc <- function(curvetype, all_types, all_len) {
315 -
    if (!is.atomic(curvetype) || !is.character(curvetype)
316 -
        || length(curvetype) > all_len
317 -
        || length(setdiff(curvetype, all_types)) != 0) {
315 +
    if (!is.atomic(curvetype) || !is.character(curvetype) ||
316 +
      length(curvetype) > all_len ||
317 +
      length(setdiff(curvetype, all_types)) != 0) {
318 318
      FALSE
319 319
    } else {
320 320
      TRUE
321 321
    }
322 322
  }
323 323
  roc_prc <- cfunc(curvetype, c("ROC", "PRC"), 2)
324 -
  basic_eval <- cfunc(curvetype, c("score", "label", "error", "accuracy",
325 -
                                   "specificity", "sensitivity", "precision",
326 -
                                   "mcc", "fscore"),
327 -
                      9)
324 +
  basic_eval <- cfunc(
325 +
    curvetype, c(
326 +
      "score", "label", "error", "accuracy",
327 +
      "specificity", "sensitivity", "precision",
328 +
      "mcc", "fscore"
329 +
    ),
330 +
    9
331 +
  )
328 332
329 333
  if (!roc_prc && !basic_eval) {
330 334
    stop("Invalid curvetype", call. = FALSE)
@@ -332,12 +336,11 @@
Loading
332 336
333 337
  if (!is.null(obj)) {
334 338
    obj_mode <- attr(obj, "args")[["mode"]]
335 -
    if (((obj_mode == "rocprc") && !roc_prc)
336 -
        || ((obj_mode == "basic") && !basic_eval)) {
339 +
    if (((obj_mode == "rocprc") && !roc_prc) ||
340 +
      ((obj_mode == "basic") && !basic_eval)) {
337 341
      stop("Invalid curvetype", call. = FALSE)
338 342
    }
339 343
  }
340 -
341 344
}
342 345
343 346
#
@@ -345,27 +348,33 @@
Loading
345 348
#
346 349
.check_type <- function(type) {
347 350
  if (!is.null(type)) {
348 -
    assertthat::assert_that(assertthat::is.string(type),
349 -
                            (type == "l" || type == "p" || type == "b"))
351 +
    assertthat::assert_that(
352 +
      assertthat::is.string(type),
353 +
      (type == "l" || type == "p" || type == "b")
354 +
    )
350 355
  }
351 -
352 356
}
353 357
354 358
#
355 359
# Check show_cb
356 360
#
357 361
.check_show_cb <- function(show_cb, obj = NULL) {
358 -
  assertthat::assert_that(is.atomic(show_cb),
359 -
                          assertthat::is.flag(show_cb),
360 -
                          assertthat::noNA(show_cb))
362 +
  assertthat::assert_that(
363 +
    is.atomic(show_cb),
364 +
    assertthat::is.flag(show_cb),
365 +
    assertthat::noNA(show_cb)
366 +
  )
361 367
362 368
  if (!is.null(obj) && (attr(obj, "dataset_type") == "multiple")) {
363 369
    obj_calc_avg <- attr(obj, "args")[["calc_avg"]]
364 -
    if (show_cb && !obj_calc_avg ) {
365 -
      stop(paste0("calc_avg of the evalmod function",
366 -
                  " must be set as TRUE before using show_cb",
367 -
                  " of this function"),
368 -
           call. = FALSE)
370 +
    if (show_cb && !obj_calc_avg) {
371 +
      stop(paste0(
372 +
        "calc_avg of the evalmod function",
373 +
        " must be set as TRUE before using show_cb",
374 +
        " of this function"
375 +
      ),
376 +
      call. = FALSE
377 +
      )
369 378
    }
370 379
  }
371 380
}
@@ -374,18 +383,23 @@
Loading
374 383
# Check raw_curves
375 384
#
376 385
.check_raw_curves <- function(raw_curves, obj = NULL) {
377 -
  assertthat::assert_that(is.atomic(raw_curves),
378 -
                          assertthat::is.flag(raw_curves),
379 -
                          assertthat::noNA(raw_curves))
386 +
  assertthat::assert_that(
387 +
    is.atomic(raw_curves),
388 +
    assertthat::is.flag(raw_curves),
389 +
    assertthat::noNA(raw_curves)
390 +
  )
380 391
381 392
  if (!is.null(obj) && (attr(obj, "dataset_type") == "multiple")) {
382 393
    obj_calc_avg <- attr(obj, "args")[["calc_avg"]]
383 394
    obj_raw_curves <- attr(obj, "args")[["raw_curves"]]
384 395
    if (raw_curves && (!obj_calc_avg || !obj_raw_curves)) {
385 -
      stop(paste0("Both calc_avg and raw_curves of the evalmod function",
386 -
                  " must be set as TRUE before using raw_curves",
387 -
                  " of this function"),
388 -
           call. = FALSE)
396 +
      stop(paste0(
397 +
        "Both calc_avg and raw_curves of the evalmod function",
398 +
        " must be set as TRUE before using raw_curves",
399 +
        " of this function"
400 +
      ),
401 +
      call. = FALSE
402 +
      )
389 403
    }
390 404
  }
391 405
}
@@ -394,51 +408,63 @@
Loading
394 408
# Check show_legend
395 409
#
396 410
.check_show_legend <- function(show_legend) {
397 -
  assertthat::assert_that(is.atomic(show_legend),
398 -
                          assertthat::is.flag(show_legend),
399 -
                          assertthat::noNA(show_legend))
411 +
  assertthat::assert_that(
412 +
    is.atomic(show_legend),
413 +
    assertthat::is.flag(show_legend),
414 +
    assertthat::noNA(show_legend)
415 +
  )