permutation_test {permutest} | R Documentation |
Run permutation test
Description
Run permutation test with user inputted data, test statistic, and permutation function
Usage
permutation_test(
df,
group_col,
outcome_col,
strata_col = NULL,
test_stat = "diff_in_means",
perm_func = permute_group,
alternative = "two-sided",
shift = 0,
reps = 10000,
perm_set = NULL,
complete_enum = FALSE,
return_test_dist = FALSE,
return_perm_dist = FALSE,
seed = NULL
)
Arguments
df |
A data frame |
group_col |
The name of the column in df that corresponds to the group label |
outcome_col |
The name of the column in df that corresponds to the outcome variable |
strata_col |
The name of the column in df that corresponds to the strata |
test_stat |
Test statistic function |
perm_func |
Function to permute group |
alternative |
String, two-sided or one-sided (greater or less) p-value; options are 'greater', 'less', or 'two-sided' |
shift |
Value of shift to apply in one- or two-sample problem |
reps |
Number of iterations to use when calculating permutation p-value |
perm_set |
Matrix of group assignments to use instead of reps iterations of perm_func |
complete_enum |
Boolean, whether to calculate P-value under complete enumeration of permutations |
return_test_dist |
Boolean, whether to return test statistic distribution under permutations |
return_perm_dist |
Boolean, whether to return a matrix where each row is the group assignment under that permutation |
seed |
An integer seed value |
Value
p_value
: the permutation test p-value
test_stat_dist
: array, the distribution of the test statistic under the set of permutations,
if return_test_dist is set to TRUE
perm_indices_mat
: matrix, each row corresponds to a permutation used
in the permutation test calculation
Examples
data <- data.frame(group = c(rep(1, 10), rep(2, 10)), outcome = c(rep(1, 10), rep(1, 10)))
permutation_test(df = data, group_col = "group", outcome_col = "outcome",
test_stat = "diff_in_means", perm_func = permute_group, alternative = "greater",
shift = 0, reps = 10, return_perm_dist = TRUE, return_test_dist = TRUE, seed = 42)