-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from gorkang/development
Development
- Loading branch information
Showing
11 changed files
with
188 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Package: BayesianReasoning | ||
Title: Plot and help understand Positive Predictive Values, and their relationship with Sensitivity, Specificity and Prevalence. | ||
Title: Plot and help understand Positive and Negative Predictive Values, and their relationship with Sensitivity, Specificity and Prevalence. | ||
Version: 0.1 | ||
Authors@R: person("Gorka", "Navarrete", email = "[email protected]", | ||
role = c("aut", "cre")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# README | ||
|
||
### v0.1 It barely works | ||
|
||
Initial release, includes 3 functions: | ||
|
||
* **PPV_heatmap.R**: Plot PPV heatmaps | ||
* **PPV_diagnostic_vs_screening.R**: Plot PPV for a diagnostic and a screening group | ||
* **min_possible_prevalence.R**: Show minimum possible prevalence given the test characteristics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
.createPPVmatrix <- function(Max_Prevalence, Sensitivity, Max_FP) { | ||
|
||
# Libraries --------------------------------------------------------------- | ||
# if (!require('dplyr')) install.packages('dplyr'); library('dplyr') | ||
if (!require('reshape2')) install.packages('reshape2'); library('reshape2') | ||
|
||
|
||
# DEBUG ------------------------------------------------------------------- | ||
|
||
# Max_Prevalence = 4 | ||
# Sensitivity = 90 | ||
# Max_FP = 10 | ||
# PPV_NPV = "PPV" # NPV/PPV | ||
|
||
#TEST Parameters ************** | ||
|
||
# False Positives (x axis) | ||
Steps_FP <<- 100 | ||
Step_size_FP <<- Max_FP/Steps_FP | ||
Min_FP <<- 0 | ||
FP = seq(Min_FP, Max_FP, Step_size_FP) #With (Max_FP-Step_size_FP) we get 100 FPs. If we use Max_FP instead we have 101 (because we start at 0!) | ||
|
||
#CONDITION Parameters *********** | ||
|
||
#Prevalence_y - x out of y | ||
Prevalence_x <<- 1 | ||
Min_Prevalence <<- 1 | ||
Steps_Prevalence <<- 100 | ||
Step_size_Prevalence <<- Max_Prevalence/Steps_Prevalence | ||
Prevalence = seq(Min_Prevalence, (1 + Max_Prevalence), Step_size_Prevalence) #With (1 + Max_Prevalence) we get 101. If we use Max_Prevalence we get 100 | ||
|
||
|
||
# PPV Calculation ------------------------------------------------------------- | ||
|
||
# We calculate the 100x100 PPV matrix using %o% (outer) | ||
PPV <<- (Sensitivity * Prevalence_x) / ((Sensitivity * Prevalence_x) + ((Prevalence - 1) %o% FP) ) | ||
|
||
#Label columns and rows of matrix | ||
colnames(PPV) = FP | ||
rownames(PPV) = Prevalence | ||
|
||
# Long format para ggplot Heatmap | ||
PPV_melted = melt(PPV) | ||
|
||
# Give names to variables | ||
names(PPV_melted) = c("melted_Prevalence", "melted_FP", "melted_PPV") | ||
|
||
PPV_melted <<- PPV_melted | ||
|
||
|
||
# NPV Calculation ------------------------------------------------------------- | ||
|
||
# As NPV is more dependent on Sensitivity, the x axis should show Sensitivity, and FP should be fixed | ||
NPV <<- ((Prevalence - 1) %o% (100 - FP)) / (((Prevalence - 1) %o% (100 - FP)) + (Prevalence_x * (100 - Sensitivity))) | ||
|
||
#Label columns and rows of matrix | ||
colnames(NPV) = FP | ||
rownames(NPV) = Prevalence | ||
|
||
# Long format para ggplot Heatmap | ||
NPV_melted = melt(NPV) | ||
|
||
# Give names to variables | ||
names(NPV_melted) = c("melted_Prevalence", "melted_FP", "melted_NPV") | ||
|
||
NPV_melted <<- NPV_melted | ||
|
||
# HACK to easily switch betweeen NPV and PPV | ||
if (PPV_NPV == "NPV") { | ||
PPV_melted = NPV_melted | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.