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))
Univariate case (with heuristic search)…
is.in <- ldamatch(condition, covariate1, t_halt)
## Initial group sizes: control: 30 treatment: 15
## Starting heuristic search.
## Finished heuristic search in 0.007 seconds.
## Eventual group sizes: control: 28 treatment: 14
## Removed subjects: control: 2 treatment: 1
print(table(condition, is.in))
## is.in
## condition FALSE TRUE
## control 2 28
## treatment 1 14
Univariate case (with Monte Carlo search)…
is.in <- ldamatch(condition, covariate1, t_halt, method = "monte")
## Initial group sizes: control: 30 treatment: 15
## Starting montecarlo search.
## Finished montecarlo search in 0.005 seconds.
## Eventual group sizes: control: 30 treatment: 13
## Removed subjects: control: 0 treatment: 2
print(table(condition, is.in))
## is.in
## condition FALSE TRUE
## control 0 30
## treatment 2 13
Multivariate case…
covariate2 <- c(rnorm(2 * SIZE), rnorm(SIZE, 1, 2))
covariates <- cbind(covariate1, covariate2)
Multivariate case (with heuristic search)…
is.in <- ldamatch(condition, covariates, t_halt)
## Initial group sizes: control: 30 treatment: 15
## Starting heuristic search.
## Finished heuristic search in 0.028 seconds.
## Eventual group sizes: control: 25 treatment: 13
## Removed subjects: control: 5 treatment: 2
print(table(condition, is.in))
## is.in
## condition FALSE TRUE
## control 5 25
## treatment 2 13
Multivariate case (with Monte Carlo search)…
is.in <- ldamatch(condition, covariates, t_halt, method = "monte")
## Initial group sizes: control: 30 treatment: 15
## Starting montecarlo search.
## Finished montecarlo search in 0.083 seconds.
## Eventual group sizes: control: 29 treatment: 11
## Removed subjects: control: 1 treatment: 4
print(table(condition, is.in))
## is.in
## condition FALSE TRUE
## control 1 29
## treatment 4 11
Multivariate case (with special proportions and Wilcox test)…
my.props <- prop.table(c(control = 4, treatment = 3))
is.in <- ldamatch(condition, covariates, U_halt, props = my.props)
## Initial group sizes: control: 30 treatment: 15
## Starting heuristic search.
## Finished heuristic search in 0.045 seconds.
## Eventual group sizes: control: 20 treatment: 15
## Removed subjects: control: 10 treatment: 0
print(table(condition, is.in))
## is.in
## condition FALSE TRUE
## control 10 20
## treatment 0 15
Multivariate case (with Wilks test)…
is.in <- ldamatch(condition, covariates, wilks_halt)
## Initial group sizes: control: 30 treatment: 15
## Starting heuristic search.
## Finished heuristic search in 0.036 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
Multivariate case (with Wilks test and Monte Carlo search)…
is.in <- ldamatch(condition, covariates, wilks_halt, method = "monte")
## Initial group sizes: control: 30 treatment: 15
## Starting montecarlo search.
## Finished montecarlo search in 0.117 seconds.
## Eventual group sizes: control: 27 treatment: 10
## Removed subjects: control: 3 treatment: 5
print(table(condition, is.in))
## is.in
## condition FALSE TRUE
## control 3 27
## treatment 5 10
Multivariate case (with Anderson-Darling test and heuristic search)…
is.in <- ldamatch(condition, covariates, ad_halt, method = "heuristic")
## Initial group sizes: control: 30 treatment: 15
## Starting heuristic search.
## Finished heuristic search in 0.681 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
Multivariate case (with t-test and Anderson-Darling test simultaneously)…
combined_halting_test <- create_halting_test(c(t_halt, ad_halt))
threshes <- c(.2, .02)
is.in <- ldamatch(condition, covariates, combined_halting_test, threshes)
## Initial group sizes: control: 30 treatment: 15
## Starting heuristic search.
## Finished heuristic search in 0.129 seconds.
## Eventual group sizes: control: 25 treatment: 13
## Removed subjects: control: 5 treatment: 2
print(table(condition, is.in))
## is.in
## condition FALSE TRUE
## control 5 25
## treatment 2 13
Univariate case (with exhaustive search)…
estimate_exhaustive(min_preserved = 42, condition, cases_per_second = 100)
## If 44 of 45 kept: at most 45 cases. If 100 cases per second evaluated: 0.45 seconds.
## If 43 of 45 kept: at most 1035 cases. If 100 cases per second evaluated: 10.35 seconds.
## If 42 of 45 kept: at most 15225 cases. If 100 cases per second evaluated: 2.538 minutes.
## [1] 15225
foreach::registerDoSEQ()
is.ins <- ldamatch(condition, covariate1, t_halt, method = "exhaustive")
## Initial group sizes: control: 30 treatment: 15
## Starting exhaustive search.
## Created 2 group size configurations each with a total size of 44
## control: 29 treatment: 15 KL_diverg: 0.000128651338541343
## Size of Cartesian product: 30
## Number of cases processed per second: 163.0435
## control: 30 treatment: 14 KL_diverg: 0.000520578560755861
## Size of Cartesian product: 15
## Number of cases processed per second: 300
## Created 3 group size configurations each with a total size of 43
## control: 29 treatment: 14 KL_diverg: 0.000135741532290407
## Size of Cartesian product: 450
## Number of cases processed per second: 387.931
## control: 28 treatment: 15 KL_diverg: 0.000536783341068091
## Size of Cartesian product: 435
## Number of cases processed per second: 327.8071
## control: 30 treatment: 13 KL_diverg: 0.0021993283249259
## Size of Cartesian product: 105
## Number of cases processed per second: 411.7647
## Finished exhaustive search in 3.033 seconds.
## Eventual group sizes: control: 30 treatment: 13
## Removed subjects: control: 0 treatment: 2
print(table(condition, is.ins[[1]]))
##
## condition FALSE TRUE
## control 0 30
## treatment 2 13
print(length(is.ins))
## [1] 1
# (Confirm exhaustive search by applying heuristic search to it.)
is.in <- ldamatch(condition[is.ins[[1]]], covariate1[is.ins[[1]]], t_halt)
print(table(condition[is.ins[[1]]], is.in))
## is.in
## TRUE
## control 30
## treatment 13