From 197df7c908d78de2ca0663dbedbbe9130a483649 Mon Sep 17 00:00:00 2001 From: Maria Gargiulo Date: Tue, 6 Feb 2024 12:31:42 +0100 Subject: [PATCH] add example for estimates_exist; closes #35 --- R/estimate_mse.R | 16 ++++++++++++++++ man/estimates_exist.Rd | 15 +++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/R/estimate_mse.R b/R/estimate_mse.R index 0d486ee..864c7a1 100644 --- a/R/estimate_mse.R +++ b/R/estimate_mse.R @@ -160,6 +160,22 @@ run_lcmcr <- function(stratum_data_prepped, stratum_name, min_n = 1, #' full file path to the JSON file containing the estimates, otherwise it will #' be `NA`. #' @export +#' @importFrom dplyr "%>%" +#' +#' @examples +#' \dontrun{ +#' in_A <- sample(c(0, 1), size = 100, replace = TRUE, prob = c(0.45, 0.65)) +#' in_B <- sample(c(0, 1), size = 100, replace = TRUE, prob = c(0.5, 0.5)) +#' in_C <- sample(c(0, 1), size = 100, replace = TRUE, prob = c(0.75, 0.25)) +#' in_D <- sample(c(0, 1), size = 100, replace = TRUE, prob = c(1, 0)) +#' +#' my_stratum <- tibble::tibble(in_A, in_B, in_C, in_D) %>% +#' dplyr::mutate(rs = rowSums(.)) %>% +#' dplyr::filter(rs >= 1) %>% +#' dplyr::select(-rs) +#' +#' estimates_exist(stratum_data_prepped = my_stratum, estimates_dir = "path_to_estimates") +#' } estimates_exist <- function(stratum_data_prepped, estimates_dir) { diff --git a/man/estimates_exist.Rd b/man/estimates_exist.Rd index 44f526b..a6b7741 100644 --- a/man/estimates_exist.Rd +++ b/man/estimates_exist.Rd @@ -25,3 +25,18 @@ be \code{NA}. \description{ Check whether stratum estimates already exist in pre-calculated files. } +\examples{ +\dontrun{ +in_A <- sample(c(0, 1), size = 100, replace = TRUE, prob = c(0.45, 0.65)) +in_B <- sample(c(0, 1), size = 100, replace = TRUE, prob = c(0.5, 0.5)) +in_C <- sample(c(0, 1), size = 100, replace = TRUE, prob = c(0.75, 0.25)) +in_D <- sample(c(0, 1), size = 100, replace = TRUE, prob = c(1, 0)) + +my_stratum <- tibble::tibble(in_A, in_B, in_C, in_D) \%>\% + dplyr::mutate(rs = rowSums(.)) \%>\% + dplyr::filter(rs >= 1) \%>\% + dplyr::select(-rs) + +estimates_exist(stratum_data_prepped = my_stratum, estimates_dir = "path_to_estimates") +} +}