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 |
w |
numeric vector of weights. |
converged |
boolean indicating if |
ebal_error |
returns error message if |
#load and clean data a bit
data(lalonde)
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
#usually search over all columns of U to find which produces weights with
#the minimum bias bound; in this ex, search only first 10 dims
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.