Skip to contents

optweight.svy.fit() performs the optimization for optweight.svy() and should, in most cases, not be used directly. Little processing of inputs is performed, so they must be given exactly as described below.

Usage

optweight.svy.fit(
  covs,
  targets,
  tols = 0,
  s.weights = NULL,
  b.weights = NULL,
  norm = "l2",
  std.binary = FALSE,
  std.cont = TRUE,
  min.w = 1e-08,
  verbose = FALSE,
  solver = NULL,
  ...
)

Arguments

covs

a numeric matrix of covariates to be targeted.

targets

a vector of target population mean values for each covariate. The resulting weights will yield sample means within tols units of the target values for each covariate. If any target values are NA, the corresponding variable will not be targeted and its weighted mean will be wherever the weights yield the smallest variance. To ensure the weighted mean for a covariate is equal to its unweighted mean (i.e., so that its original mean is its target mean), its original mean must be supplied as a target.

tols

a vector of target balance tolerance values. Default is 0.

s.weights

an optional vector of sampling weights. Default is a vector of 1s.

b.weights

an optional vector of base weights. Default is a vector of 1s.

norm

character; a string containing the name of the norm corresponding to the objective function to minimize. Allowable options include "l1" for the L1 norm, "l2" for the L2 norm (the default), "linf" for the L\(\infty\) norm, "entropy" for the negative entropy, and "log" for the sum of the negative logs. See Details at optweight.fit() for more information.

std.binary, std.cont

logical; whether the tolerances are in standardized mean units (TRUE) or raw units (FALSE) for binary variables and continuous variables, respectively. The default is FALSE for std.binary because raw proportion differences make more sense than standardized mean difference for binary variables. These arguments are analogous to the binary and continuous arguments in bal.tab() in cobalt.

min.w

numeric; a single value less than 1 for the smallest allowable weight. Some analyses require nonzero weights for all units, so a small, nonzero minimum may be desirable. The default is 1e-8 (\(10^{-8}\)), which does not materially change the properties of the weights from a minimum of 0 but prevents warnings in some packages that use weights to estimate treatment effects. When norm is "entropy" or "log" and min.w <= 0, min.w will be set to the smallest nonzero value.

verbose

logical; whether information on the optimization problem solution should be printed. Default is FALSE.

solver

string; the name of the optimization solver to use. Allowable options depend on norm. Default is to use whichever eligible solver is installed, if any, or the default solver for the corresponding norm. See Details at optweight.fit() for information.

...

Options that are passed to the settings function corresponding to solver.

Value

An optweight.svy.fit object with the following elements:

w

The estimated weights, one for each unit.

duals

A data.frame containing the dual variables for each covariate. See Zubizarreta (2015) for interpretation of these values.

info

A list containing information about the performance of the optimization at termination.

Details

optweight.svy.fit() transforms the inputs into the required inputs for the optimization functions, which are (sparse) matrices and vectors, and then supplies the outputs (the weights, dual variables, and convergence information) back to optweight.svy(). Little processing of inputs is performed, as this is normally handled by optweight.svy().

Target constraints are applied to the product of the estimated weights and the sampling weights. In addition, sum of the product of the estimated weights and the sampling weights is constrained to be equal to the sum of the product of the base weights and sampling weights.

References

Zubizarreta, J. R. (2015). Stable Weights that Balance Covariates for Estimation With Incomplete Outcome Data. Journal of the American Statistical Association, 110(511), 910–922. doi:10.1080/01621459.2015.1023805

See also

optweight.svy() which you should use for estimating the balancing weights, unless you know better.

optweight.fit() for more details about the allowed norms and optimization.

Examples

library("cobalt")
data("lalonde", package = "cobalt")

covs <- splitfactor(lalonde[c("age", "educ", "race",
                              "married", "nodegree")],
                    drop.first = FALSE)

targets <- c(23, 9, .3, .3, .4, .2, .5)

ows.fit <- optweight.svy.fit(covs,
                             targets = targets,
                             norm = "l2")

#Unweighted means
col_w_mean(covs)
#>         age        educ  race_black race_hispan  race_white     married 
#>  27.3631922  10.2687296   0.3957655   0.1172638   0.4869707   0.4153094 
#>    nodegree 
#>   0.6302932 

#Weighted means; same as targets
col_w_mean(covs, w = ows.fit$w)
#>         age        educ  race_black race_hispan  race_white     married 
#>        23.0         9.0         0.3         0.3         0.4         0.2 
#>    nodegree 
#>         0.5