This runs pairwise t-tests (based on lm(), therefore assuming equal variances) on multiple imputations, with the ability to take into account survey weights.

pairwise_t_test_mi(
  mi_list,
  dv,
  groups,
  weights = NULL,
  p.adjust.method = p.adjust.methods
)

Arguments

mi_list

A list of dataframes, each consisting of a multiply imputed dataset

dv

The dependent variable for the t.test (must be in mi_list)

groups

The grouping variable (each distinct value will be treated as a level)

weights

The variable containing survey weights, must be in mi_list

p.adjust.method

The method to adjust p-values for multiple comparison (see stats::p.adjust())

Value

A tibble containing the results of the t-tests with one test per row

Examples

#Create list with imputed data
library(mice)
library(dplyr)
imp <- mice(nhanes2)
#> 
#>  iter imp variable
#>   1   1  bmi  hyp  chl
#>   1   2  bmi  hyp  chl
#>   1   3  bmi  hyp  chl
#>   1   4  bmi  hyp  chl
#>   1   5  bmi  hyp  chl
#>   2   1  bmi  hyp  chl
#>   2   2  bmi  hyp  chl
#>   2   3  bmi  hyp  chl
#>   2   4  bmi  hyp  chl
#>   2   5  bmi  hyp  chl
#>   3   1  bmi  hyp  chl
#>   3   2  bmi  hyp  chl
#>   3   3  bmi  hyp  chl
#>   3   4  bmi  hyp  chl
#>   3   5  bmi  hyp  chl
#>   4   1  bmi  hyp  chl
#>   4   2  bmi  hyp  chl
#>   4   3  bmi  hyp  chl
#>   4   4  bmi  hyp  chl
#>   4   5  bmi  hyp  chl
#>   5   1  bmi  hyp  chl
#>   5   2  bmi  hyp  chl
#>   5   3  bmi  hyp  chl
#>   5   4  bmi  hyp  chl
#>   5   5  bmi  hyp  chl
imp_list <- complete(imp, action="long") %>%
   group_split(.imp)

#Specify dependent variable and grouping factor
pairwise_t_test_mi(imp_list, bmi, age)
#> # A tibble: 3 × 7
#>   x     y     mean_diff t_value    df p_value group_var
#>   <chr> <chr>     <dbl>   <dbl> <dbl>   <dbl> <chr>    
#> 1 20-39 40-59    -3.79   -1.52   6.89   0.344 age      
#> 2 20-39 60-99    -4.69   -1.92   7.61   0.280 age      
#> 3 40-59 60-99    -0.899  -0.462  4.57   0.665 age