acoppock / ri2

Randomization Inference for Randomized Experiments
Other
12 stars 4 forks source link

two-sided p-value for non-zero sharp null hypotheses #24

Closed jennywang0 closed 4 years ago

jennywang0 commented 4 years ago

P-value calculations in conduct_ri aren't robust to specifications of a sharp hypothesis that are not zero

summary.ri <- function(object, p = NULL, ...) {
  if(is.null(p)){p <- object$p}
  if (p == "two-tailed") {
    object$sims_df <-
      within(
        object$sims_df,
        extreme <- abs(est_sim) >= abs(est_obs)
      )
  } else if (p == "lower") {
    object$sims_df <-
      within(
        object$sims_df,
        extreme <- est_sim <= est_obs
      )
  } else if (p == "upper") {
    object$sims_df <-
      within(
        object$sims_df,
        extreme <- est_sim >= est_obs
      )
  } else {
    stop('p must be either "two-tailed" (the default), "lower", or "upper".')
 }

should be:

summary.ri <- function(object, p = NULL, ...) {
  if(is.null(p)){p <- object$p}
  if (p == "two-tailed") {
    object$sims_df <-
      within(
        object$sims_df,
        # Changed line:
        extreme <- abs(est_sim - sharp_hypothesis) >= abs(est_obs - sharp_hypothesis)
      )
  } else if (p == "lower") {
    object$sims_df <-
      within(
        object$sims_df,
        extreme <- est_sim <= est_obs
      )
  } else if (p == "upper") {
    object$sims_df <-
      within(
        object$sims_df,
        extreme <- est_sim >= est_obs
      )
  } else {
    stop('p must be either "two-tailed" (the default), "lower", or "upper".')
 }