xrobin / pROC

Compare 758f799 ... +25 ... 496e09f

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 2 of 10 files from the diff.
Other files ignored by Codecov
man/roc.Rd has changed.
codecov.yml has changed.
man/roc.test.Rd has changed.
DESCRIPTION has changed.
NEWS has changed.
.travis.yml has changed.
README.md has changed.

@@ -18,31 +18,15 @@
Loading
18 18
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 19
20 20
# Delong's test paired, used by roc.test.roc
21 -
delong.paired.test <- function(roc1, roc2) {
22 -
  n <- length(roc1$controls)
23 -
  m <- length(roc1$cases)
24 -
25 -
  VR <- delongPlacements(roc1)
26 -
  VS <- delongPlacements(roc2)
27 -
28 -
  SX <- matrix(NA, ncol=2, nrow=2)
29 -
  SX[1,1] <- sum((VR$X - VR$theta) * (VR$X - VR$theta))/(m-1)
30 -
  SX[1,2] <- sum((VR$X - VR$theta) * (VS$X - VS$theta))/(m-1)
31 -
  SX[2,1] <- sum((VS$X - VS$theta) * (VR$X - VR$theta))/(m-1)
32 -
  SX[2,2] <- sum((VS$X - VS$theta) * (VS$X - VS$theta))/(m-1)
33 -
34 -
  SY <- matrix(NA, ncol=2, nrow=2)
35 -
  SY[1,1] <- sum((VR$Y - VR$theta) * (VR$Y - VR$theta))/(n-1)
36 -
  SY[1,2] <- sum((VR$Y - VR$theta) * (VS$Y - VS$theta))/(n-1)
37 -
  SY[2,1] <- sum((VS$Y - VS$theta) * (VR$Y - VR$theta))/(n-1)
38 -
  SY[2,2] <- sum((VS$Y - VS$theta) * (VS$Y - VS$theta))/(n-1)
39 -
40 -
  S <- SX/m + SY/n
41 -
  L <- c(1,-1)
42 -
  sig <- sqrt(L%*%S%*%L)
43 -
  zscore <- (VR$theta-VS$theta)/sig[1]
44 -
  if (is.nan(zscore) && VR$theta == VR$theta && sig[1] == 0)
45 -
    zscore <- 0 # special case: no difference between theta's produces a NaN
21 +
delong.paired.test <- function(calcs) {
22 +
	
23 +
	# Input calcs is a list returned by delong.paired.calculations().
24 +
	
25 +
	zscore <- with(calcs, d/sig)
26 +
	
27 +
	if (is.nan(zscore) && calc$d == 0 && calcs$sig == 0)
28 +
		zscore <- 0 # special case: no difference between theta's produces a NaN
29 +
	
46 30
  return(zscore)
47 31
}
48 32
@@ -111,6 +95,49 @@
Loading
111 95
  return(ci)
112 96
}
113 97
98 +
# function to calculate the CI
99 +
ci.delong.paired <- function(calcs, conf.level) {
100 +
	
101 +
	# Input calcs is a list generated by delong.paired.calculations().
102 +
	# CI is calculated using the normally distributed pivot given in
103 +
	# DeLong's 1988 paper.
104 +
	
105 +
	crit_z <- qnorm(1 - ((1 - conf.level)/2))
106 +
	out <- list()
107 +
	out$upper <- with(calcs, d + crit_z * sig)
108 +
	out$lower <- with(calcs, d - crit_z * sig)
109 +
	out$level <- conf.level
110 +
	return(out)
111 +
}
112 +
113 +
# Runs the placements and main calculations for the paired DeLong's test
114 +
#  so that they can be easily used by both the test and CI functions.
115 +
delong.paired.calculations <- function(roc1, roc2) {
116 +
	n <- length(roc1$controls)
117 +
	m <- length(roc1$cases)
118 +
	
119 +
	VR <- delongPlacements(roc1)
120 +
	VS <- delongPlacements(roc2)
121 +
	
122 +
	SX <- matrix(NA, ncol=2, nrow=2)
123 +
	SX[1,1] <- sum((VR$X - VR$theta) * (VR$X - VR$theta))/(m-1)
124 +
	SX[1,2] <- sum((VR$X - VR$theta) * (VS$X - VS$theta))/(m-1)
125 +
	SX[2,1] <- sum((VS$X - VS$theta) * (VR$X - VR$theta))/(m-1)
126 +
	SX[2,2] <- sum((VS$X - VS$theta) * (VS$X - VS$theta))/(m-1)
127 +
	
128 +
	SY <- matrix(NA, ncol=2, nrow=2)
129 +
	SY[1,1] <- sum((VR$Y - VR$theta) * (VR$Y - VR$theta))/(n-1)
130 +
	SY[1,2] <- sum((VR$Y - VR$theta) * (VS$Y - VS$theta))/(n-1)
131 +
	SY[2,1] <- sum((VS$Y - VS$theta) * (VR$Y - VR$theta))/(n-1)
132 +
	SY[2,2] <- sum((VS$Y - VS$theta) * (VS$Y - VS$theta))/(n-1)
133 +
	
134 +
	S <- SX/m + SY/n
135 +
	L <- c(1,-1)
136 +
	sig <- sqrt(L%*%S%*%L)
137 +
	d <- VR$theta - VS$theta
138 +
	return(list("d" = d, "sig" = sig[[1]]))
139 +
}
140 +
114 141
# Calls delongPlacementsCpp safely
115 142
# Ensures that the theta value calculated is correct
116 143
delongPlacements <- function(roc) {

@@ -116,6 +116,7 @@
Loading
116 116
						 ties.method="first",
117 117
						 progress=getOption("pROCProgress")$name,
118 118
						 parallel=FALSE,
119 +
						 conf.level=0.95,
119 120
						 ...) {
120 121
	alternative <- match.arg(alternative)
121 122
	data.names <- paste(deparse(substitute(roc1)), "and", deparse(substitute(roc2)))
@@ -249,6 +250,15 @@
Loading
249 250
			}
250 251
			if (roc1$direction != roc2$direction)
251 252
				warning("DeLong's test should not be applied to ROC curves with a different direction.")
253 +
			
254 +
			# Check if conf.level is specified correctly. This is currently
255 +
			# only used for the delong paired method, which is why it lives 
256 +
			# here for now.
257 +
			if (!is.numeric(conf.level)) {
258 +
				stop("conf.level must be numeric between 0 and 1.")
259 +
			} else if (0 > conf.level | 1 < conf.level) {
260 +
				stop("conf.level must be between 0 and 1.")
261 +
			}
252 262
		}
253 263
		else if (method == "venkatraman") {
254 264
			if (has.partial.auc(roc1))
@@ -304,10 +314,14 @@
Loading
304 314
	
305 315
	if (method == "delong") {
306 316
		if (paired) {
307 -
			stat <- delong.paired.test(roc1, roc2)
317 +
			delong.calcs <- delong.paired.calculations(roc1, roc2)
318 +
			stat <- delong.paired.test(delong.calcs)
319 +
			stat.ci <- ci.delong.paired(delong.calcs, conf.level)
308 320
			names(stat) <- "Z"
309 321
			htest$statistic <- stat
310 322
			htest$method <- "DeLong's test for two correlated ROC curves"
323 +
			htest$conf.int <- c(stat.ci$lower, stat.ci$upper)
324 +
			attr(htest$conf.int, "conf.level") <- stat.ci$level
311 325
			
312 326
			if (alternative == "two.sided")
313 327
				pval <- 2*pnorm(-abs(stat))

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.

27 Commits

Hiding 2 contexual commits
+4
+4
Hiding 17 contexual commits
+16
+13
+3
+623
-623
-623
+623
-4
-4
Files Coverage
R -0.02% 86.05%
src 100.00%
Project Totals (33 files) 86.45%
Loading