diff --git a/.gitignore b/.gitignore index 8f2ee95..b690c3d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ inst/doc vignettes/*cache* vignettes/*files* vignettes/*log + +R/get_number_decimals.R \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 77ddde0..4f56fa3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,7 +10,7 @@ Description: This package allows users to estimate the science-wise suggest most published medical research is true," 2013, Biostatistics, using an EM approach due to the presence of rounding and censoring. It also allows users to estimate the - proportion of true null hypotheses in the presence of + false discovery rate conditional on covariates, using a regression framework, as per Boca and Leek, "A direct approach to estimating false discovery rates conditional on covariates," 2018, PeerJ. diff --git a/R/get_number_decimals.R b/R/get_number_decimals.R index 1d05925..60e233e 100644 --- a/R/get_number_decimals.R +++ b/R/get_number_decimals.R @@ -20,21 +20,26 @@ get_number_decimals <- function(x) stop("All elements of x should be in [0,1)") } + ##get the maximum number of digits + max_digits <- 6 + ##get all numbers spaced 10^-k apart from 0 to 1 - list_grid <- lapply(1:6, function(k){(1:10^k)/(10^k)}) + list_grid <- lapply(1:max_digits, function(k){(1:10^k)/(10^k)}) ##function for a single number n_dec_single <- function(x_single){ ##round to get rid of funny numerical issues x_single <- round(x_single, 12) - if(x_single < 10^-6) + if(x_single < 10^-max_digits) { - n_dec <- 7 - warning("7 is a place-holder. Number of decimals seems to be > 6. This case is not implemented. Beware floating point arithmetic!") + n_dec <- max_digits + 1 + warning(paste(max_digits + 1, " is a place-holder. Number of decimals seems to be >", + max_digits, ". This case is not implemented. Beware floating point arithmetic!", + sep="")) } else { ##get which vector the query number is in, which corresponds to the "number of digits" - grid_x_is_in <- sapply(list_grid, function(l,a){a %in% l}, x_single) + grid_x_is_in <- sapply(list_grid, function(l,a){min(abs(l-a)) < 10^-12}, x_single) if(x_single==0) { @@ -42,10 +47,12 @@ get_number_decimals <- function(x) } else { if(sum(grid_x_is_in) >= 1) { - n_dec <- min((1:6)[grid_x_is_in]) + n_dec <- min((1:max_digits)[grid_x_is_in]) } else { - n_dec <- 7 - warning("7 is a place-holder. Number of decimals seems to be > 6. This case is not implemented. Beware floating point arithmetic!") + n_dec <- max_digits + 1 + warning(paste(max_digits + 1, " is a place-holder. Number of decimals seems to be >", + max_digits, ". This case is not implemented. Beware floating point arithmetic!", + sep="")) } } }