Skip to content

Commit

Permalink
Removed the export tag from several internal functions, i.e. cleaned …
Browse files Browse the repository at this point in the history
…up the reference manual a bit
  • Loading branch information
OskarGauffin committed Feb 14, 2024
1 parent a3c5b09 commit 83f9ef4
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 24 deletions.
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ S3method(print,da)
S3method(summary,da)
export(add_disproportionality)
export(add_expected_counts)
export(apply_rule_of_N)
export(build_colnames_da)
export(ci_for_ic)
export(ci_for_prr)
export(ci_for_ror)
Expand All @@ -14,8 +12,6 @@ export(da)
export(ic)
export(prr)
export(ror)
export(round_and_sort_by_lower_da_limit)
export(round_columns_with_many_decimals)
export(write_to_excel)
import(data.table)
importFrom(Rdpack,reprompt)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ Fixing a minor bug discovered by the CRAN checks.

# version 0.0.3
Fixing a bug where the group_by-variable was hard-coded as "group". From now, any group_by column name should work.

30 changes: 16 additions & 14 deletions R/lower_level_disprop_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ conf_lvl_to_quantile_prob <- function(conf_lvl = 0.95) {
#' @param quantile_prob A list with two parameters, lower and upper. Default: list(lower = 0.025, upper = 0.975)
#' @param da_name A string, such as "ic", "prr" or "ror". Default: NULL
#' @return A list with two symbols, to be inserted in the dtplyr-chain
#' @export
build_colnames_da <- function(quantile_prob = list("lower" = 0.025, "upper" = 0.975),
da_name = NULL) {
ic_lower_name <- paste0(da_name, 100 * quantile_prob$lower)
Expand All @@ -444,9 +443,9 @@ build_colnames_da <- function(quantile_prob = list("lower" = 0.025, "upper" = 0.
}
# 2.3 ci_for_ic ----
#' @title Confidence intervals for Information Component (IC)
#' @description Mainly used in \code{link{ic}}. Produces quantiles of the
#' posterior gamma distribution. Called twice in \code{ic} to create a
#' credibility interval.
#' @description Mainly used in function \code{\link{ic}}. Produces quantiles of the
#' posterior gamma distribution. Called twice in \code{ic} to create
#' credibility intervals.
#' @param conf_lvl_probs The probabilities of the posterior, based on
#' a passed confidence level (\code{conf_lvl}) in \code{\link{ic}}. For
#' instance, if \code{sgn_lvl = .95} in \code{ic} is used, quantiles will be
Expand Down Expand Up @@ -509,24 +508,29 @@ ci_for_ror <- function(a, b, c, d, conf_lvl_probs) {

# 2.6 apply_rule_of_N ----
#' @title apply_rule_of_N
#' @description Internal fcn to set da-columns to NA when observed count < 3
#' @description Internal function to set disproportionality cells for ROR and PRR to NA when observed count < 3
#' @param da_df See the intermediate object da_df in add_disproportionality
#' @param da_estimators Default is c("ic", "prr", "ror").
#' @param rule_of_N PARAM_DESCRIPTION
#' @return OUTPUT_DESCRIPTION
#' @param rule_of_N An length one integer between 0 and 10.
#' @return The input data frame (da_df) with potentially some cells set to NA.
#' @details Sometimes, you want to protect yourself from spurious findings based
#' on small observed counts combined with infinitesimal expected counts.
#' @importFrom stringr str_subset
#' @importFrom dplyr mutate across starts_with cur_column
#' @export
#' @importFrom checkmate qassert
apply_rule_of_N <- function(da_df = NULL,
da_estimators = c("ic", "prr", "ror"),
rule_of_N = NULL) {


if (!is.null(rule_of_N)) {
# Rule of N = 3 is built into the IC
# This only applies to PRR and ROR columns, as the shrinkage takes care of this for the IC
da_estimators_not_ic <- stringr::str_subset(da_estimators, "ic", negate = T)

# We only need to check the observed once
# Check that rule_of_N input is an integer between 0 and 10
checkmate::qassert(rule_of_N, "X1[0,10]")

# We only need to check the observed once, it does not change between PRR and ROR.
replace_these_rows <- da_df[["obs"]] < rule_of_N

da_df <-
Expand All @@ -549,7 +553,6 @@ apply_rule_of_N <- function(da_df = NULL,
#' @param number_of_digits See add_disproportionality
#' @return A df with rounded columns
#' @importFrom dplyr mutate across starts_with
#' @export
round_columns_with_many_decimals <- function(da_df = NULL, da_estimators = NULL, number_of_digits = NULL) {
if (!is.null(number_of_digits)) {
da_df <-
Expand All @@ -573,7 +576,6 @@ round_columns_with_many_decimals <- function(da_df = NULL, da_estimators = NULL,
#' @param number_of_digits Numeric value. Set the number of digits to show in output by passing
#' an integer. Default value is 2 digits. Set to NULL to avoid rounding.
#' @return The df object, sorted.
#' @export
#' @importFrom checkmate qassert
#' @importFrom purrr pluck
#' @importFrom dplyr group_by summarise left_join arrange select
Expand All @@ -600,8 +602,8 @@ round_and_sort_by_lower_da_limit <- function(df = NULL,
}

sort_by_colname <- conf_lvl |>
pvda::conf_lvl_to_quantile_prob() |>
pvda::build_colnames_da(da_name = sort_by) |>
conf_lvl_to_quantile_prob() |>
build_colnames_da(da_name = sort_by) |>
purrr::pluck("lower")

# Take the mean lower quantile for the chosen da and sort by it.
Expand Down
6 changes: 3 additions & 3 deletions man/apply_rule_of_N.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/ci_for_ic.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 83f9ef4

Please sign in to comment.