ldamatch demos

Kyle Gorman & Géza Kiss

2016-06-23

Univariate case…

library(ldamatch)
set.seed(257)

SIZE <- 15
condition <- as.factor(c(rep("control", 2 * SIZE), rep("treatment", SIZE)))
covariate1 <- c(rnorm(2 * SIZE), rnorm(SIZE, 1, 2))

Multivariate case…

covariate2 <- c(rnorm(2 * SIZE), rnorm(SIZE, 1, 2))
covariates <- cbind(covariate1, covariate2)

Multivariate case (with special proportions and Wilcox test)…

my.props <- prop.table(c(control = 4, treatment = 3))
is.in <- match_groups(condition, covariates, U_halt, props = my.props)
## Initial group sizes:  control: 30    treatment: 15 
## Starting heuristic1 search.
## Finished heuristic1 search in 0.061 seconds.
## Eventual group sizes: control: 18    treatment: 13 
## Removed subjects:     control: 12    treatment: 2
print(table(condition, is.in))
##            is.in
## condition   FALSE TRUE
##   control      12   18
##   treatment     2   13

Multivariate case (with Wilks test)…

is.in <- match_groups(condition, covariates, wilks_halt)
## Initial group sizes:  control: 30    treatment: 15 
## Starting heuristic1 search.
## Finished heuristic1 search in 0.029 seconds.
## Eventual group sizes: control: 27    treatment: 14 
## Removed subjects:     control: 3 treatment: 1
print(table(condition, is.in))
##            is.in
## condition   FALSE TRUE
##   control       3   27
##   treatment     1   14

Multivariate case (with t-test and Anderson-Darling test simultaneously)…

t_ad_halt <- create_halting_test(c(t_halt, ad_halt))
threshes <- c(.2, .02)
is.in <- match_groups(condition, covariates, t_ad_halt, threshes)
## Initial group sizes:  control: 30    treatment: 15 
## Starting heuristic1 search.
## Finished heuristic1 search in 0.579 seconds.
## Eventual group sizes: control: 25    treatment: 12 
## Removed subjects:     control: 5 treatment: 3
print(table(condition, is.in))
##            is.in
## condition   FALSE TRUE
##   control       5   25
##   treatment     3   12

Univariate case for more than two groups…

set.seed(257)

SIZE <- 15
condition <- as.factor(c(rep("group1", SIZE), rep("group2", SIZE), rep("group3", SIZE)))
covariate1 <- c(rnorm(SIZE, 0, 1), rnorm(SIZE, 0, 2), rnorm(SIZE, 1, 2))
covariate2 <- c(rnorm(SIZE, 0, 1), rnorm(SIZE, 0, 2), rnorm(SIZE, 1, 2))
covariates <- cbind(covariate1, covariate2)