R/jackknife.R

Defines functions jackknife

Documented in jackknife

#' Generate Jackknife Subsamples
#'
#' Generate jackknife subsamples. For data with \eqn{n} elements,
#' the jackknife generates \eqn{n} subsamples, each with one element
#' deleted. The generalized (delete-\eqn{p}, block) jackknife generates
#' subsamples by deleting `p` observations.
#'
#' @template param-n
#' @param size A scalar integer representing the number of elements to delete.
#'    When `size = 1`, the subsets are generated by ordinary
#'    (delete-one) jackknife. When `size > 1`, the subsets are generated by
#'    the block (delete-\eqn{p}) jackknife.
#'
#' @references
#'
#' -   Davison, A. C. & Hinkley, D. V. (1997)
#'     *Bootstrap Methods and Their Applications*.
#'     Cambridge University Press, Cambridge. ISBN 0-521-57391-2.
#' -   Tukey, J. W. (1958). "Bias and confidence in not quite large samples".
#'     *The Annals of Mathematical Statistics*.
#'     [doi:10.1214/aoms/1177706647](https://dx.doi.org/10.1214/aoms/1177706647).
#' -   Efron, B.; Stein, C. (May 1981). "The Jackknife Estimate of Variance".
#'     *The Annals of Statistics*.
#'     [doi:10.1214/aos/1176345462](https://dx.doi.org/10.1214/aos/1176345462).
#'
#' @export
jackknife <- function(n, size = 1L) {
  idx <- seq_len(n)
  f <- function(i) sample_idx(out_id = i, n = n)
  if (size == 1) {
    res <- map(idx, f)
  } else {
    res <- utils::combn(idx, size, FUN = f, simplify = FALSE)
  }
  res
}
jrnold/ramsleep documentation built on May 29, 2019, 11:43 a.m.