getw: Find Weights using Entropy Balancing.

View source: R/functions.R

getwR Documentation

Find Weights using Entropy Balancing.

Description

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.

Usage

getw(target, observed, svd.U, ebal.tol = 1e-06, ebal.maxit = 500)

Arguments

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 svd() on the kernel matrix.

ebal.tol

tolerance level used by custom entropy balancing function ebalance_custom

ebal.maxit

maximum number of iterations in optimization search used by ebalance_custom

Value

w

numeric vector of weights.

converged

boolean indicating if ebalance_custom converged

ebal_error

returns error message if ebalance_custom encounters an error

Examples


#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)
 

chadhazlett/KBAL documentation built on Jan. 3, 2024, 9:57 p.m.