htest_infer_sim: helper for randomization-inference simulation testing using...

View source: R/h_test_infer_sim.R

htest_infer_simR Documentation

helper for randomization-inference simulation testing using Infer package; set options in args

Description

htest_infer_sim works through the Infer package to generate samples and a p-value from a 'null hypothesis distribution'. Written (mainly) by Oska Fentem, originally called "test_hypothesis"

Usage

htest_infer_sim(
  df,
  formula,
  response = NULL,
  hypothesis,
  gen,
  stat = NULL,
  p_val_dir = NULL,
  seed = 123
)

Arguments

formula

I'm not completely sure how to use a formula here, does it transform a variable?

response

the outcome of interest

hypothesis
  • If the hypothesis option stat is specified then statistics like the mean are calculated for this sample

gen

something about how many samples are generated and how

stat

the statistic(s) (multiple?) to calculate?

p_val_dir

Direction for p-value calculation, if supplied

Details

We used it for testing whether the median of a difference (input as a single column) is likely to be distinct from 0. Having this function enabled us to purrr map a bunch of stuff Given a formula pr null hypothesis and arguments for generating samples: Generate samples under this null If p_val_dir is supplied, then the function computes a p-value for observed data given the null

Examples


mtcarsX <- mtcars %>% mutate(gear_d_carb = gear - carb)
htest_infer_sim(df = mtcarsX,
stat = "median",
hypothesis = list(null = "point", med = 0),
gen =  list(reps = 1000, type = "bootstrap"),
response = "gear_d_carb",
p_val_dir = "two_sided")

rethinkpriorities/rp-r-package documentation built on Jan. 7, 2023, 10:11 p.m.