From ba28d5b8fe68c8d8c921f13205cde18c7c4374a7 Mon Sep 17 00:00:00 2001 From: Matias-Lopez-13 <112888781+Matias-Lopez-13@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:47:33 -0300 Subject: [PATCH] Update find_odds.R --- R/find_odds.R | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/R/find_odds.R b/R/find_odds.R index 2bfda6c..b5ab81d 100644 --- a/R/find_odds.R +++ b/R/find_odds.R @@ -4,27 +4,29 @@ ##' ##' ##' @title Find odds given ideas about unequally easy evidence -##' @param m1 TODO -##' @param m2 TODO -##' @param n TODO -##' @param thep TODO -##' @return A vector representing TODO +##' @param obs_support An integer representing the number of observations in favor of the working hypothesis. Must be less than or equal to the total. +##' @param total_obs An integer representing the total number of observations +##' @param thep The p-value threshold +##' @return A vector representing a big value to state that x>0 ##' @importFrom BiasedUrn dFNCHypergeo ##' @importFrom stats uniroot ##' @export -sens_analysis <- function(m1, m2, n, thep=.05) { + + obs_oppose <- obs_support+1 + +sens_analysis <- function(obs_support, obs_oppose, total_obs, thep=.05) { find_odds <- function(x, thep = thep) { ## thep is the desired pvalue ## x is the odds if (x < 0) { return(999) } - res0 <- dFNCHypergeo(seq(0, m1), m1 = m1, m2 = m2, n = n, odds = x) + res0 <- dFNCHypergeo(seq(0, obs_support), m1 = obs_support, m1 = obs_oppose, n = total_obs, odds = x) return(res0[3] - thep) } theodds <- uniroot(f = find_odds, interval = c(.0001, n * 10), trace = 2, extendInt = "yes") found_odds <- theodds$root - the_found_dens <- dFNCHypergeo(seq(0, m1), m1 = m1, m2 = m2, n = n, odds = found_odds) + the_found_dens <- dFNCHypergeo(seq(0, obs_support), m1 = obs_support, m1 = obs_oppose, n = total_obs, odds = found_odds) return(the_found_dens) }