R/vec-bootstrap-q.R

Defines functions bootstrap_q_vec

Documented in bootstrap_q_vec

#' 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)
}

Try the TidyDensity package in your browser

Any scripts or data that you put into this service are public.

TidyDensity documentation built on Nov. 2, 2023, 5:38 p.m.