kmatch: Create matching vectors based on data

Description Usage Arguments Value Author(s) Examples

Description

Given a data frame and the specified matching vectors and weight vector, kmatch extracts the matching vectors and weight vector from the data set, and form them to a system of linear equations, whose matrix expression is Aw=b, where A is the matching vectors and b is the weight vector. The w is the weights we want. kmatch then randomly samples w subject to the non-negativity constraint w_i >= 0 and sum(w)=0. These two make the sampling space bounded so uniform sampling over the whole sampling space is achievable. Then the w is the weights we want.

Usage

1
2
kmatch(x, weight.var, match.var, n = 1, thin = 5, replace = FALSE,
  chains = 1, burn = 0.5)

Arguments

x

is a data frame containing needed input data

weight.var

character name of the column of the input weights

match.var

character vector of names of columns of 'data' we wish to match on

n

numeric number of weight vectors desired. Default is 1

thin

only 1 out of every thin vectors will be recorded. Default is 5

replace

if FALSE then any rows that had non-zero weight in weight.var will be set to 0 in the output. Default is FALSE

chains

number of chains. Default is 1.

burn

is the number of points to burn in hitandrun (not very costly, because it just adds to total number of iterations, whereas thin is a multiple)

Value

Returns a list of "chains" matrices of 'n' sets of weights that match the given set of weights in terms of weighted averages to the 'match.var' factors. The columns of each matrix are the sets of weights.

Author(s)

Mike Flynn mflynn210@gmail.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
set.seed(40)
x <- data.frame(size = rnorm(10), weight = rep(.02, 10))
weights <- kmatch(x, weight.var = "weight", match.var = "size", n = 100, replace = TRUE)

x2 <- data.frame(var1 = c(-2,-1, 0, 1, 2),
                 var2 = c(1, -1, 2, -1, 0),
                 w = rep(.2, 5))
weights2 <- kmatch(x = x2, weight.var = "w",
                   match.var = c("var1", "var2"),
                   n = 10, thin = 1, replace= TRUE)[[1]]

davidkane9/kmatching documentation built on May 15, 2019, 1:14 a.m.