From add8a4bd762348d21fdf452aa46ee4436ccdaf11 Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Mon, 6 Jun 2022 16:15:31 +0200 Subject: [PATCH] Compute and display confidence interval --- R/server.R | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/R/server.R b/R/server.R index 55acf1c..3e2f9ab 100644 --- a/R/server.R +++ b/R/server.R @@ -53,24 +53,39 @@ server <- function(input, output, session) { reference <- ranked_data()[!gene %chin% comparison_gene_ids, score] comparison <- ranked_data()[gene %chin% comparison_gene_ids, score] - p_value <- stats::wilcox.test( + reference_median <- format( + round(stats::median(reference), digits = 3), + nsmall = 3 + ) + + comparison_median <- format( + round(stats::median(comparison), digits = 3), + nsmall = 3 + ) + + test_result <- stats::wilcox.test( x = comparison, y = reference, - alternative = "greater" - )$p.value + conf.int = TRUE + ) - reference_median <- stats::median(reference) - comparison_median <- stats::median(comparison) + p_value <- format( + round(test_result$p.value, digits = 4), + nsmall = 4, + scientific = FALSE + ) + + lower <- format(round(test_result$conf.int[1], digits = 3), nsmall = 3) + upper <- format(round(test_result$conf.int[2], digits = 3), nsmall = 3) HTML(glue::glue( "The p-value for the alternative hypothesis that your genes have ", - "higher scores than other genes is {format(round(p_value, ", - "digits = 4), nsmall = 4, scientific = FALSE)}. This value was ", - "computed using a Wilcoxon rank sum test. The median score of your ", - "genes is {format(round(comparison_median, digits = 2), ", - "nsmall = 2, scientific = FALSE)} compared to a median score of ", - "{format(round(reference_median, digits = 2), nsmall = 2, ", - "scientific = FALSE)} of the other genes." + "different scores than other genes is {p_value}. This value ", + "was computed using a Wilcoxon rank sum test. Based on a 95% ", + "confidence, the difference in scores is between {lower} and ", + "{upper}. The median score of your genes is ", + "{comparison_median} compared to a median score of ", + "{reference_median} of the other genes." )) } })