Skip to content

Commit

Permalink
Edit DESCRIPTION, remove get_number_decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
Simina M. Boca committed Mar 6, 2020
1 parent e370e10 commit 339ed7b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ inst/doc
vignettes/*cache*
vignettes/*files*
vignettes/*log

R/get_number_decimals.R
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 15 additions & 8 deletions R/get_number_decimals.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,39 @@ 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)
{
n_dec <- 0
} 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=""))
}
}
}
Expand Down

0 comments on commit 339ed7b

Please sign in to comment.