Description Usage Arguments Value Author(s) Examples
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.
1 2 |
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 |
replace |
if FALSE then any rows that had non-zero weight in |
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) |
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.
Mike Flynn mflynn210@gmail.com
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]]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.