You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a requirement in order to help #212 become more robust.
If a tidy_ distribution function is passed to tidy_combine_distirbutions() and the output is NULL then this will cause a failure in building the final output.
Can use purrr::compact() to drop NULLS from input list.
The text was updated successfully, but these errors were encountered:
#' Combine Multiple Tidy Distributions of Different Types#'#' @family Multiple Distribution#'#' @author Steven P. Sanderson II, MPH#'#' @details Allows a user to generate a tibble of different `tidy_` distributions#'#' @description This allows a user to specify any `n` number of `tidy_`#' distributions that can be combined into a single tibble. This is the preferred#' method for combining multiple distributions of different types, for example#' a Gaussian distribution and a Beta distribution.#'#' This generates a single tibble with an added column of dist_type that will#' give the distribution family name and its associated parameters.#'#' @param ... The `...` is where you can place your different distributions#'#' @examples#'#' tn <- tidy_normal()#' tb <- tidy_beta()#' tc <- tidy_cauchy()#'#' tidy_combine_distributions(tn, tb, tc)#'#' ## OR#'#' tidy_combine_distributions(#' tidy_normal(),#' tidy_beta(),#' tidy_cauchy(),#' tidy_logistic()#' )#'#' @return#' A tibble#'#' @export#'tidy_combine_distributions<-function(...){
# Add distributions to a listdist_list<-list(...)
dist_list<-purrr::compact(dist_list)
# Checks ----if (length(dist_list) <2){
rlang::abort(
message="You must add at least two distributions to the function",
use_cli_format=TRUE
)
}
# Get the distribution typedist_final_tbl<-purrr::map(
.x=dist_list,
.f=~.x %>%
dplyr::mutate(dist_type= attributes(.x)[["dist_with_params"]]) %>%
dplyr::mutate(dist_type= as.factor(dist_type))
) %>%
purrr::map_dfr(dplyr::as_tibble)
attr(dist_final_tbl, "tibble_type") <-"tidy_multi_dist_combine"# Return ---return(dist_final_tbl)
}
Examples:
> tidy_combine_distributions(tidy_normal(), tidy_exponential(), NULL) %>% tidy_distribution_summary_tbl(dist_type)
# A tibble: 2 × 11dist_typemean_valmedian_valstd_valmin_valmax_valskewnesskurtosisrange<fct><dbl><dbl><dbl><dbl><dbl><dbl><dbl><dbl>1Gaussian c(… 0.0278-0.2301.05-2.50e+03.670.8204.746.172Exponential… 1.010.7431.009.69e-44.521.525.124.52# … with 2 more variables: iqr <dbl>, variance <dbl>
This is a requirement in order to help #212 become more robust.
If a
tidy_
distribution function is passed totidy_combine_distirbutions()
and the output is NULL then this will cause a failure in building the final output.Can use
purrr::compact()
to dropNULLS
from input list.The text was updated successfully, but these errors were encountered: