Skip to content

Commit

Permalink
Update find_odds.R
Browse files Browse the repository at this point in the history
  • Loading branch information
Matias-Lopez-13 authored Jun 20, 2024
1 parent 7a50b5c commit ba28d5b
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions R/find_odds.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit ba28d5b

Please sign in to comment.