getw | R Documentation |
Uses entropy balancing to find and return the weights that produce mean balance on \phi(X_i)
, the expanded features of X_i
using a given kernel \phi(.)
, for the control or sample group and treated group or target population.
getw(target, observed, svd.U, ebal.tol = 1e-06, ebal.maxit = 500)
target |
a numeric vector of length equal to the total number of units where population/treated units take a value of 1 and sample/control units take a value of 0. |
observed |
a numeric vector of length equal to the total number of units where sampled/control units take a value of 1 and population/treated units take a value of 0. |
svd.U |
a matrix of left singular vectors from performing |
ebal.tol |
tolerance level used by custom entropy balancing function |
ebal.maxit |
maximum number of iterations in optimization search used by |
A list containing:
w |
A numeric vector of weights. |
converged |
boolean indicating if |
ebal_error |
returns error message if |
#load and clean data
set.seed(123)
data("lalonde")
# Select a random subset of 500 rows
lalonde_sample <- sample(1:nrow(lalonde), 500, replace = FALSE)
lalonde <- lalonde[lalonde_sample, ]
xvars=c("age","black","educ","hisp","married","re74","re75","nodegr","u74","u75")
#need a kernel matrix to run SVD on then find weights with; so get that first with makeK.
#running makeK with the sampled units as the bases
K = makeK(allx = lalonde[,xvars], useasbases = 1-lalonde$nsw)
#SVD on this kernel and get matrix with left singular values
U = svd(K)$u
#Use the first 10 dimensions of U.
U2=U[,1:10]
getw.out=getw(target=lalonde$nsw,
observed=1-lalonde$nsw,
svd.U=U2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.