Skip to content

Commit

Permalink
Fixes #239
Browse files Browse the repository at this point in the history
  • Loading branch information
spsanderson committed Sep 15, 2022
1 parent ee8f074 commit ad6177c
Show file tree
Hide file tree
Showing 132 changed files with 1,241 additions and 666 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export(as_name)
export(bootstrap_density_augment)
export(bootstrap_p_augment)
export(bootstrap_p_vec)
export(bootstrap_q_augment)
export(bootstrap_q_vec)
export(bootstrap_unnest_tbl)
export(ci_hi)
export(ci_lo)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## New Features
1. Fix #237 - Add function `bootstrap_density_augment()`
2. Fix #238 - Add functions `bootstrap_p_vec()` and `bootstrap_p_augment()`
3. Fix #239 - Add functions `bootstrap_q_vec()` and `bootstrap_q_augment()`

## Minor Fixes and Improvements
1. Fix #242 - Fix `prop` check in `tidy_bootstrap()`
Expand Down
2 changes: 1 addition & 1 deletion R/augment-bootstrap-p.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bootstrap_p_augment <- function(.data, .value, .names = "auto"){
rlang::call2(
"bootstrap_p_vec",
.x = rlang::sym(col),
#.ns = "healthyR.ts"
.ns = "TidyDensity"
)
}

Expand Down
73 changes: 73 additions & 0 deletions R/augment-bootstrap-q.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#' Augment Bootstrap Q
#'
#' @family Augment Function
#' @family Bootstrap
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @description
#' Takes a numeric vector and will return the quantile.
#'
#' @details
#' Takes a numeric vector and will return the quantile of that vector.
#' This function is intended to be used on its own in order to add columns to a
#' tibble.
#'
#' @param .data The data being passed that will be augmented by the function.
#' @param .value This is passed [rlang::enquo()] to capture the vectors you want
#' to augment.
#' @param .names The default is "auto"
#'
#' @examples
#' x <- mtcars$mpg
#'
#' tidy_bootstrap(x) %>%
#' bootstrap_unnest_tbl() %>%
#' bootstrap_q_augment(y)
#'
#' @return
#' A augmented tibble
#'
#' @export
#'

bootstrap_q_augment <- function(.data, .value, .names = "auto"){

column_expr <- rlang::enquo(.value)

if(rlang::quo_is_missing(column_expr)){
rlang::abort(
message = "bootstrap_q_vec(.value) is missing",
use_cli_format = TRUE
)
}

col_nms <- names(tidyselect::eval_select(rlang::enquo(.value), .data))

make_call <- function(col){
rlang::call2(
"bootstrap_q_vec",
.x = rlang::sym(col),
.ns = "TidyDensity"
)
}

grid <- expand.grid(
col = col_nms
, stringsAsFactors = FALSE
)

calls <- purrr::pmap(.l = list(grid$col), make_call)

if(any(.names == "auto")){
newname <- "q"
} else {
newname <- as.list(.names)
}

calls <- purrr::set_names(calls, newname)

ret <- tibble::as_tibble(dplyr::mutate(.data, !!!calls))

return(ret)
}
2 changes: 1 addition & 1 deletion R/vec-bootstrap-p.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ bootstrap_p_vec <- function(.x){
x_term <- .x

# Checks ----
if (!is.numeric(x)){
if (!is.numeric(.x)){
rlang::abort(
message = "'.x' must be a numeric vector",
use_cli_format = TRUE
Expand Down
45 changes: 45 additions & 0 deletions R/vec-bootstrap-q.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#' Compute Bootstrap Q of a Vector
#'
#' @family Bootstrap
#' @family Vector Function
#'
#' @author Steven P. Sanderson II, MPH
#'
#' @details
#' A function to return the quantile of a vector.
#'
#' @description
#' This function takes in a vector as it's input and will return the quantile
#' of a vector.
#'
#' @param .x A numeric
#'
#' @examples
#' x <- mtcars$mpg
#'
#' bootstrap_q_vec(x)
#'
#' @return
#' A vector
#'
#' @export
#'

bootstrap_q_vec <- function(.x){

x_term <- .x
n <- length(x_term)

if (!is.numeric(.x)){
rlang::abort(
message = "'.x' must be a numeric vector",
use_cli_format = TRUE
)
}

ret <- unname(
stats::quantile(x_term, probs = seq(0, 1, 1 / (n - 1)), type = 1)
)

return(ret)
}
24 changes: 12 additions & 12 deletions docs/articles/getting-started.html

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

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/getting-started_files/figure-html/plot_density-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/getting-started_files/figure-html/plot_density-3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pkgdown: 2.0.6
pkgdown_sha: ~
articles:
getting-started: getting-started.html
last_built: 2022-09-14T19:16Z
last_built: 2022-09-15T18:58Z
urls:
reference: https://www.spsanderson.com/TidyDensity/reference
article: https://www.spsanderson.com/TidyDensity/articles
Expand Down
Binary file modified docs/reference/Rplot002.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ad6177c

Please sign in to comment.