Skip to contents

This function tests whether the observed imbalance is less than might be expected via a random draw, via a permutation test.

Usage

imbalance_test(
  data,
  randovar,
  n_iter = 1000,
  stratavars = NULL,
  arms = NULL,
  cross = TRUE,
  ...
)

Arguments

data

a dataframe with the variables indicated in randovar and, optionally, stratavars

randovar

character with the variable name indicating the randomisation

n_iter

integer. number of simulations to perform

stratavars

character vector with the variable names indicating the stratification variables

arms

character vector of arms in the appropriate balance. If NULL the levels in randovar are used and assumed to be balanced

cross

logical. Whether to cross the stratification variables.

...

other arguments passed onto other methods

Value

a list with:

  • n_rando: the number of randomisations

  • stratavars: the names of the stratification variables

  • arms: the arms

  • observed: a dataframe with the observed imbalance

  • simulated: a dataframe with the simulated imbalances (number of rows = nrow(n_iter))

  • tests: a dataframe with the p-values

Examples

data(rando_balance)
# without stratification variables
imbalance_test(rando_balance, "rando_res")
#> assuming balanced randomisation between arms
#> Simulating randomisations ■■■■■■■■■■■■■■■■■                 55% | ETA:  2s
#> Randomisations to date: 100 
#> Overall imbalance: 0 
#>   Probability of equal or less imbalance from random allocation: 0.072 
imb <- imbalance_test(rando_balance, "rando_res", stratavars = "strat1")
#> assuming balanced randomisation between arms
#> Simulating randomisations ■■■■■■■■■■■                       32% | ETA:  9s
#> Simulating randomisations ■■■■■■■■■■■■■■■■■■■■■■■■■         79% | ETA:  3s
imbalance_test(rando_balance, "rando_res", stratavars = c("strat1", "strat2"))
#> assuming balanced randomisation between arms
#> Simulating randomisations ■■■■                              11% | ETA: 27s
#> Simulating randomisations ■■■■■■■■■■                        31% | ETA: 21s
#> Simulating randomisations ■■■■■■■■■■■■■                     41% | ETA: 18s
#> Simulating randomisations ■■■■■■■■■■■■■■■■                  50% | ETA: 15s
#> Simulating randomisations ■■■■■■■■■■■■■■■■■■■               60% | ETA: 12s
#> Simulating randomisations ■■■■■■■■■■■■■■■■■■■■■■            70% | ETA:  9s
#> Simulating randomisations ■■■■■■■■■■■■■■■■■■■■■■■■■         80% | ETA:  6s
#> Simulating randomisations ■■■■■■■■■■■■■■■■■■■■■■■■■■■■      90% | ETA:  3s
#> Randomisations to date: 100 
#> Overall imbalance: 0 
#>   Probability of equal or less imbalance from random allocation: 0.079 
#> 
#> Randomisation stratified by strat1 and strat2 
#> Maximum observed imbalanced within stratifying variables: 0 
#>   Probability of equal or less imbalance from random allocation: 0.079 
#> Maximum observed imbalanced within individual strata: 3 
#>   Probability of equal or less imbalance from random allocation: 0.109 
imb <- imbalance_test(rando_balance, "rando_res2", stratavars = c("strat1", "strat2"))
#> assuming balanced randomisation between arms
#> Simulating randomisations ■■■■                              10% | ETA: 27s
#> Simulating randomisations ■■■■■■■■■■                        30% | ETA: 21s
#> Simulating randomisations ■■■■■■■■■■■■■                     41% | ETA: 18s
#> Simulating randomisations ■■■■■■■■■■■■■■■■                  51% | ETA: 15s
#> Simulating randomisations ■■■■■■■■■■■■■■■■■■■               61% | ETA: 12s
#> Simulating randomisations ■■■■■■■■■■■■■■■■■■■■■■            70% | ETA:  9s
#> Simulating randomisations ■■■■■■■■■■■■■■■■■■■■■■■■■         80% | ETA:  6s
#> Simulating randomisations ■■■■■■■■■■■■■■■■■■■■■■■■■■■■      90% | ETA:  3s