Skip to content

Commit

Permalink
Merge pull request #195 from spsanderson/development
Browse files Browse the repository at this point in the history
Fixes #190
  • Loading branch information
spsanderson committed May 23, 2022
2 parents 26a8876 + 3764f4a commit 4b5bfa0
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(":=")
export(.data)
export(as_label)
export(as_name)
export(bootstrap_unnest_tbl)
export(ci_hi)
export(ci_lo)
export(color_blind)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ None
`td_scale_color_colorblind()`
2. Fix #187 - Add functions `ci_lo()` and `ci_hi()`
3. Fix #189 - Add function `tidy_bootstrap()`
4. Fix #190 - Add function `bootstrap_unnest_tbl()`

## Minor Fixes and Improvements
1. Fix #176 - Update `_autoplot` functions to include cumulative mean MCMC chart
Expand Down
55 changes: 55 additions & 0 deletions R/bootstrap-unnest-tbl.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#' Unnest Tidy Bootstrap Tibble
#'
#' @family Bootstrap
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @details This function takes as input the output of the `tidy_bootstrap()`
#' function and returns a two column tibble. The columns are `sim_number` and `y`
#'
#' It looks for an attribute that comes from using `tidy_bootstrap()` so it will
#' not work unless the data comes from that function.
#'
#' @description Unnest the data output from `tidy_bootstrap()`.
#'
#' @param .data The data that is passed from the `tidy_bootstrap()` function.
#'
#' @examples
#' tb <- tidy_bootstrap(.x = mtcars$mpg)
#' bootstrap_unnest_tbl(tb)
#'
#' bootstrap_unnest_tbl(tb) %>%
#' tidy_distribution_summary_tbl(sim_number)
#'
#' @return
#' A tibble
#'
#' @export
#'

bootstrap_unnest_tbl <- function(.data){

# Checks ----
atb <- attributes(.data)
distribution_family_type <- atb$dist_type

if (!atb$tibble_type == "tidy_bootstrap_nested"){
rlang::abort(
message = "You must provide the output from the tidy_bootstrap() function.",
use_cli_format = TRUE
)
}

# Data ----
df <- tidyr::unnest(.data, bootstrap_samples) %>%
purrr::set_names("sim_number", "y")

# Return ----
attr(df, ".num_sims") <- atb$.num_sims
attr(df, "distribution_family_tpe") <- distribution_family_type
attr(df, "tibble_type") <- "tidy_bootstrap"
attr(df, "dist_with_params") <- "Empirical"

return(df)

}
2 changes: 1 addition & 1 deletion R/empirical-tidy-bootstrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ tidy_bootstrap <- function(.x, .num_sims = 2000, .proportion = 0.8,
attr(df, "distribution_family_type") <- dist_type
attr(df, ".x") <- .x
attr(df, ".num_sims") <- .num_sims
attr(df, "tibble_type") <- "tidy_bootstrap"
attr(df, "tibble_type") <- "tidy_bootstrap_nested"
attr(df, "dist_with_params") <- "Empirical"

# Return ----
Expand Down
40 changes: 40 additions & 0 deletions man/bootstrap_unnest_tbl.Rd

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

4 changes: 4 additions & 0 deletions man/tidy_bootstrap.Rd

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

0 comments on commit 4b5bfa0

Please sign in to comment.