Learn R Programming

triplesmatch (version 1.1.0)

triplesIP: Integer program for finding optimal triples match

Description

This finds the optimal triples match using a quadratic program. The 'gurobi' package should be installed if using this function. This function should not be used for large problems. Note that this solver may find a good solution even if not optimal; setting `time_limit` is recommended. For most problems, [triples()] should be used instead to find a good approximate solution very quickly.

Usage

triplesIP(z, cost, mt, mc, time_limit = Inf, threads = 1, verbose = 0)

Value

A named list with two elements: `match` and `opt_info`. `match` contains the triples match. Similarly to the [triples()] function, this is in the form of a data.frame with number of rows equal to the number of triples and 8 columns specifying the match number, the names of the three units within the match, the costs of the two treated-control pairs within the match, the number of treated units, and the stratum. `opt_info` contains technical output from the optimization solver.

Arguments

z

Treatment indicator vector. 0 for control, 1 for treated

cost

Matrix of costs. Rows correspond to treated units; columns to controls

mt

The number of treated units to be used

mc

The number of control units to be used

time_limit

The amount of time in seconds before the solver should abort

threads

The number of threads that should be allocated

verbose

Whether the output of the 'gurobi' solver should be printed. 0 if not, 1 if so

See Also

triples for an approximate solution

Examples

Run this code
if (FALSE) { # rlang::is_installed(c("gurobi"))
# Generate some data
set.seed(1)
n <- 40
x <- rnorm(n, 0, 1)
nt <- floor(n * 0.4)
nc <- n - nt
z <- c(rep(1, nt), rep(0, nc))
# Create some strata
ps <- glm(z ~ x, family = binomial)$fitted.values
ps_st <- cut(ps, c(0, quantile(ps, 1/3 * 1:2), 1), labels = 1:3)
# Create a distance matrix
dist <- dist_mahal(data.frame(x = x), z, ps_st)
# Construct the triples match using integer program for stratum 1
mIP <- triplesIP(z = z[ps_st == 1], cost = dist[[1]],
                 mt = 5, mc = 7, time_limit = 30, threads = 1, verbose = 0)
}

Run the code above in your browser using DataLab