A permutation test involves permuting one or more variables in a data set before performing the test, in order to break any existing relationships and simulate the null hypothesis. One can then compare the true statistic to the generated distribution of null statistics.

permute(data, n, ..., .id = ".id")

permute_(data, n, columns, .id = ".id")



A data frame


Number of permutations to generate.


Columns to permute. This supports bare column names or dplyr dplyr::select_helpers


Name of variable that gives each model a unique integer id.


In permute_, vector of column names to permute.


A data frame with n rows and one column: perm


library(purrr) perms <- permute(mtcars, 1000, mpg) models <- map(perms$perm, ~ lm(mpg ~ wt, data = .)) glanced <- map_df(models, broom::glance, .id = "id") # distribution of null permutation statistics hist(glanced$statistic)
# confirm these are roughly uniform p-values hist(glanced$p.value)
# test against the unpermuted model to get a permutation p-value mod <- lm(mpg ~ wt, mtcars) mean(glanced$statistic > broom::glance(mod)$statistic)
#> [1] 0