Skip to content

Commit

Permalink
Merge pull request #35 from gorkang/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
gorkang authored Jul 3, 2020
2 parents caeac28 + 6fef637 commit 47936b5
Show file tree
Hide file tree
Showing 86 changed files with 827 additions and 382 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ cran-comments.md
^cran-comments\.md$
^CRAN-RELEASE$
^codecov\.yml$
^_pkgdown\.yml$
^docs$
^pkgdown$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ inst/doc
DEV/
.binder/
google-analytics.html
docs
11 changes: 5 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: BayesianReasoning
Type: Package
Title: Plot Positive and Negative Predictive Values for Medical Tests
Version: 0.3.1
Date: 2020-06-29
Version: 0.3.2
Date: 2020-07-03
Authors@R: c(person("Gorka", "Navarrete", email = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7678-8656")))
Maintainer: Gorka Navarrete <[email protected]>
Description: Functions to plot and help understand positive and negative predictive values (PPV and NPV), and their relationship with sensitivity, specificity, and prevalence. See Akobeng, A.K. (2007) <doi:10.1111/j.1651-2227.2006.00180.x> for a theoretical overview of the technical concepts and Navarrete et al. (2015) for a practical explanation about the importance of their understanding <doi:10.3389/fpsyg.2015.01327>.
Expand All @@ -14,9 +14,7 @@ Imports: dplyr,
tidyr,
magrittr,
tibble,
ggforce,
shinythemes,
shinyjs
ggforce
License: CC0
RoxygenNote: 7.1.1
URL: https://github.com/gorkang/BayesianReasoning
Expand All @@ -26,5 +24,6 @@ Suggests:
testthat,
knitr,
rmarkdown,
covr
covr,
patchwork
VignetteBuilder: knitr
13 changes: 12 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# README

### v0.3.2 Clean up, test, rinse and repeat

Clean up old comments, add more tests...

* 100% code coverage
* min_possible_prevalence() is now much more efficient
* Improvements to overlay = "line" en PPV_heatmap(), now using {ggforce} for labels
* Changed color palette for NPV
* Tweaked color palette for PPV


### v0.3.1 Testing, testing

Corrected issues raised in CRAN revision
Expand All @@ -8,7 +19,7 @@ Corrected issues raised in CRAN revision
* Do not capitalize things in the Description text
* Added references to Description explaining main concepts
* Replaced cat() with message()
* Aded folder parameter to PPV_diagnostic_vs_screening() and PPV_heatmap() functions
* Added folder parameter to PPV_diagnostic_vs_screening() and PPV_heatmap() functions

Added tests

Expand Down
8 changes: 1 addition & 7 deletions R/PPV_diagnostic_vs_screening.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ PPV_diagnostic_vs_screening <- function(Max_FP = 10, Sensitivity = 100, prevalen
# save_plot = FALSE,
folder = "") {

# PARAMETERS --------------------------------------------------------------
# Max_FP = 10
# Sensitivity = 100
# prevalence_screening_group = 100
# prevalence_diagnostic_group = 2
# labels_prevalence = c("Screening", "Diagnostic")


# FIXED parameters --------------------------------------------------------

Expand All @@ -53,6 +46,7 @@ PPV_diagnostic_vs_screening <- function(Max_FP = 10, Sensitivity = 100, prevalen
Min_FP = 0 #Step_size_FP #0
FP = seq(Min_FP, Max_FP, Step_size_FP)


# Calculate PPVs ----------------------------------------------------------

Real_Prevalence_PPV = list()
Expand Down
52 changes: 19 additions & 33 deletions R/PPV_heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,52 +56,45 @@ PPV_heatmap <-


# Check dimensions -----------------------------------------------------------


if (Min_Prevalence > Max_Prevalence) {
message("[WARNING]: Min_Prevalence (", Min_Prevalence , ") is > than Max_Prevalence (", Max_Prevalence, "). [EXPECTED]: Min_Prevalence should be smaller than Max_Prevalence. [CHANGED]: Min_Prevalence = Max_Prevalence/2")
Min_Prevalence = Max_Prevalence/2
}

# If the dimensions of the overlay are bigger, adjust Max_FP and Max_Prevalence

if (overlay == "area") {

if (overlay_position_FP > Max_FP) {
# if (overlay_position_FP_FN > Max_FP) {
message("Changing Max_FP to overlay_position_FP to fit overlay")
# Max_FP = overlay_position_FP_FN
Max_FP = overlay_position_FP
message("[WARNING]: overlay_position_FP (", overlay_position_FP , ") is > than Max_FP (", Max_FP, "). [EXPECTED]: overlay_position_FP should be smaller than Max_FP [CHANGED]: Max_FP = overlay_position_FP")
Max_FP = overlay_position_FP
}

if (overlay_prevalence_2 > Max_Prevalence) {
message("Changing Max_Prevalence to overlay_prevalence_2 to fit overlay")
message("[WARNING]: overlay_prevalence_2 (", overlay_prevalence_2 , ") is > than Max_Prevalence (", Max_Prevalence, "). [EXPECTED]: overlay_prevalence_2 should be smaller than Max_Prevalence [CHANGED]: Max_Prevalence = overlay_prevalence_2")
Max_Prevalence = overlay_prevalence_2
}

# if(overlay_position_FP_FN > (100 - Sensitivity)) {
if(overlay_position_FN > (100 - Sensitivity)) {
message("[WARNING]: overlay_position_FN (", overlay_position_FN , ") is > than (100 - Sensitivity) (", (100 - Sensitivity), "). [EXPECTED]: overlay_position_FN should be smaller than (100 - Sensitivity) [CHANGED]: Sensitivity = 100 - overlay_position_FN")
Sensitivity = 100 - overlay_position_FN
}


if (overlay_prevalence_1/overlay_prevalence_2 < Min_Prevalence/Max_Prevalence) {

message("Overlay impossible to fit in plot: overlay_prevalence_1/overlay_prevalence_2 < Min_Prevalence/Max_Prevalence: Changing Min_Prevalence to (overlay_prevalence_1/overlay_prevalence_2) * Max_Prevalence to fit overlay")

# Min Prevalence adjusted to fit overlay
Min_Prevalence = (overlay_prevalence_1/overlay_prevalence_2) * Max_Prevalence

message("[WARNING]: overlay_prevalence_1/overlay_prevalence_2 (", overlay_prevalence_1/overlay_prevalence_2 , ") is > than Min_Prevalence/Max_Prevalence (", Min_Prevalence/Max_Prevalence, "). [EXPECTED]: Prevalence for overlay should be smaller than Prevalence [CHANGED]: Changing Min_Prevalence to (overlay_prevalence_1/overlay_prevalence_2) * Max_Prevalence to fit overlay")
Min_Prevalence = (overlay_prevalence_1/overlay_prevalence_2) * Max_Prevalence # Min Prevalence adjusted to fit overlay
}

}




# Check overlay prevalence ------------------------------------------------
# Check overlay prevalence ------------------------------------------------

if (length(overlay_prevalence_1) == 1) {
if (overlay_prevalence_1 > overlay_prevalence_2) {

message(overlay_prevalence_1, " is > than ", overlay_prevalence_2)
overlay_prevalence_1 = overlay_prevalence_2

message("[WARNING]: overlay_prevalence_1 (", overlay_prevalence_1 , ") is > than overlay_prevalence_2 (", overlay_prevalence_2, "). [EXPECTED]: overlay_prevalence_1 should be smaller than overlay_prevalence_2 [CHANGED]: overlay_prevalence_1 = overlay_prevalence_2/2")
overlay_prevalence_1 = overlay_prevalence_2/2
}
} else if (length(overlay_prevalence_1) > 1) {
if (DEBUG != 0) message("> 1 overlay")
Expand All @@ -110,9 +103,6 @@ PPV_heatmap <-

# SYSTEM parameters -------------------------------------------------------

#GRAPHIC Parameters *************

# modifier_text_overlay_position = (Max_Prevalence/75)
if (overlay != "no") {
filename_overlay = paste0("_", overlay)
} else {
Expand Down Expand Up @@ -169,14 +159,14 @@ PPV_heatmap <-

p = .plot_overlay_line(
PPV_melted = PPV_melted,
uncertainty_prevalence = uncertainty_prevalence,
Min_Prevalence = Min_Prevalence,
Max_Prevalence = Max_Prevalence,
Max_FP = Max_FP,
Sensitivity = Sensitivity,

overlay_prevalence_2 = overlay_prevalence_2,

# overlay_position_FP_FN = overlay_position_FP_FN,
overlay_position_FP = overlay_position_FP,
overlay_position_FN = overlay_position_FN,

Expand All @@ -196,6 +186,7 @@ PPV_heatmap <-


} else if (overlay == "area") {

p = .plot_overlay_area(
PPV_melted,
uncertainty_prevalence = uncertainty_prevalence,
Expand All @@ -204,12 +195,10 @@ PPV_heatmap <-
Sensitivity = Sensitivity,
Min_FP = Min_FP,
Max_FP = Max_FP,
# Step_size_FP = Step_size_FP,
overlay_labels = overlay_labels,
overlay_prevalence_1 = overlay_prevalence_1,
overlay_prevalence_2 = overlay_prevalence_2,

# overlay_position_FP_FN = overlay_position_FP_FN,
overlay_position_FP = overlay_position_FP,
overlay_position_FN = overlay_position_FN,

Expand All @@ -228,15 +217,14 @@ PPV_heatmap <-
)

} else {
# if (overlay == "no") {


p = .plot_creation(
PPV_melted = PPV_melted,
Min_Prevalence = Min_Prevalence,
Sensitivity = Sensitivity,
Min_FP = Min_FP,
Max_FP = Max_FP,
# Step_size_FP = Step_size_FP,

decimals_x = decimals_x,
decimals_y = decimals_y,

Expand All @@ -250,8 +238,7 @@ PPV_heatmap <-
PPV_NPV = PPV_NPV

)



}


Expand All @@ -260,7 +247,6 @@ PPV_heatmap <-
if (folder != "") {

print(p)
# plot_name = here::here(paste0("outputs/PPV_heatmap/", PPV_NPV, "_", Min_Prevalence, "_", Max_Prevalence, "_", Sensitivity, "_", Max_FP, filename_overlay, "_", Language, ".png"))
plot_name = paste0(folder, "/", PPV_NPV, "_", Min_Prevalence, "_", Max_Prevalence, "_", Sensitivity, "_", Max_FP, filename_overlay, "_", Language, ".png")
ggsave(plot_name, p, dpi = 300, width = 14, height = 10)
message("\n Plot created in: ", plot_name, "\n")
Expand Down
Loading

0 comments on commit 47936b5

Please sign in to comment.