Return precision and recall when calculating rho

closes #12
parent 777c263f
Pipeline #147619939 canceled with stages
in 4 minutes and 14 seconds
......@@ -45,6 +45,7 @@ Collate:
'baserateCT.R'
'calcKappa.R'
'calcRho.R'
'calculations.R'
'checkBRPKcombo.R'
'contingencyTable.R'
'codeSet.R'
......
rating_set_recall <- function (x) {
if (!is(x, "contingency.table")) {
x <- as.contingency.table(x)
}
x$agreement$true_positive / (x$agreement$true_positive + x$agreement$false_negative)
}
rating_set_precision <- function (x) {
if (!is(x, "contingency.table")) {
x <- as.contingency.table(x)
}
x$agreement$true_positive / (x$agreement$true_positive + x$agreement$false_positive)
}
\ No newline at end of file
......@@ -46,6 +46,8 @@ rhoCT = function(
return(list(
rho = rho_result,
kappa = kappa
kappa = kappa,
recall = rating_set_recall(x),
precision = rating_set_precision(x)
))
}
\ No newline at end of file
......@@ -42,6 +42,8 @@ rhoSet = function(
replicates,
ScSKappaThreshold, ScSKappaMin, ScSPrecisionMin, ScSPrecisionMax
),
kappa = kappa
));
kappa = kappa,
recall = rating_set_recall(x),
precision = rating_set_precision(x)
))
}
\ No newline at end of file
......@@ -130,7 +130,7 @@ run.bench(0.8, 0.3, 20, 1000, times = 100)
run.bench(0.8, 0.3, 200, 10000, times = 10)
```
```{r }
run.bench(0.8, 0.3, 20, 100000, times = 10)
run.bench(0.8, 0.3, 200, 100000, times = 10)
```
library(testthat)
context("Testing rho returns precision and recall")
test_that("testing rho returns", {
rho_set <- matrix(c(rep(1, times = 80), rep(0, times=100)), byrow=T, ncol=2)
rho_set_1 <- rho(rho_set)
expect_equal(round(rho_set_1$recall, 2), 1)
expect_equal(round(rho_set_1$precision, 2), 1)
rho_ct <- matrix(c(30, 0, 0, 60), ncol=2)
rho_ct_1 <- rho(rho_ct)
expect_equal(round(rho_ct_1$recall, 2), 1)
expect_equal(round(rho_ct_1$precision, 2), 1)
})
test_that("testing precision/recall values", {
rho_ct <- matrix(c(5,2,3,3), ncol=2)
rho_ct_1 <- rho(rho_ct)
expect_equal(rho_ct_1$recall, (5 / (5 + 3)))
expect_equal(rho_ct_1$precision, (5 / (5 + 2)))
})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment