#' Analytic, bootstrap, and permutations for unique numbers
#'
#'
#' @param data A data frame
#' @param variable A numeric variable that includes the first decimal place.
#' @param group A second variable used to group the primary variable such that
#' average frequency Z-scores are calculated separately for each group.
#' @param decimal_place The number of decimal places used for the calculation.
#' The default is set to "1" meaning decimals in the second (hundreds place)
#' and below are discarded.
#' @param reps The number of shuffles (simulations) to perform. The default is set to 1,000.
#'
#' @return A tibble
#' @export
#'
#' @examples
#' unique_num(bodyweight, obs, reps = 100)
#'
#' @importFrom magrittr %>%
#' @importFrom rlang .data
#' @useDynLib fabricated
#' @importFrom Rcpp sourceCpp
#'
#'
unique_num <- function(data,
variable,
group = NULL,
decimal_place = 1,
reps = 1000) {
var <- deparse(substitute(group))
if(is.null(data[[var]])) {
vec_0 <- data %>%
dplyr::select({{ variable }}) %>%
#mutate({{ variable}} = as.numeric({{ variable }})) %>%
dplyr::pull()
out_0 <- unique_num_cpp(sample_0 = vec_0, decimals = decimal_place, reps = reps)
return(out_0)
}
else {
groups_0 <- data %>%
dplyr::select({{ group }}) %>%
dplyr::distinct() %>%
dplyr::pull()
#groups_1 <- group_0[[var]]
out_1 <- data.frame(group = NA,
d_uni_int = NA,
d_num = NA,
d_exp_num = NA,
d_an_z = NA,
d_boot_p = NA,
d_perm_p = NA)
out_1 <- data.frame()
for(i in groups_0) {
vec_1 <- data %>%
dplyr::filter({{ group }} == i) %>%
dplyr::select({{ variable }}) %>%
dplyr::pull()
out_2 <- unique_num_cpp(vec_1, decimal_place, reps) %>%
mutate(group = i)
out_1 <- bind_rows(out_1, out_2)
}
return(out_1)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.