R/get_bootstrap_pvalue.R

Defines functions get_bootstrap_pvalue

get_bootstrap_pvalue <- function(p_val_type, t_stat, t_boot) {

  #' get bootstrapped p-value based on bootstrapped t-stats
  #' @param p_val_type Character vector of length 1. Type of p-value.
  #'        Options include "two-tailed", "equal-tailed", ">" and "<".
  #' @param t_stat The original t-statistic
  #' @param t_boot The bootstrapped t-statistics
  #' @return A bootstrapped p-value
  #' @noRd

  if (p_val_type == "two-tailed") {
    p_val <- mean(abs(t_stat) < abs(t_boot), na.rm = FALSE)
  } else if (p_val_type == "equal-tailed") {
    p_l <- mean(t_stat < t_boot, na.rm = FALSE)
    p_h <- mean(t_stat > t_boot, na.rm = FALSE)
    p_val <- 2 * min(p_l, p_h, na.rm = FALSE)
  } else if (p_val_type == ">") {
    p_l <- mean(t_stat < t_boot, na.rm = FALSE)
    p_val <- p_l
  } else if (p_val_type == "<") {
    p_h <- mean(t_stat > t_boot, na.rm = FALSE)
    p_val <- p_h
  }

  p_val
}

Try the fwildclusterboot package in your browser

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

fwildclusterboot documentation built on March 7, 2023, 5:33 p.m.