View source: R/optweight.svy.R
optweight.svy | R Documentation |
Estimate targeting weights for covariates specified in formula
. The
target means are specified with targets
and the maximum distance
between each weighted covariate mean and the corresponding target mean is
specified by tols
. See Zubizarreta (2015) for details of the
properties of the weights and the methods used to fit them.
optweight.svy(
formula,
data = NULL,
tols = 0,
targets = NULL,
s.weights = NULL,
b.weights = NULL,
norm = "l2",
verbose = FALSE,
...
)
formula |
a formula with nothing on the left hand side and the
covariates to be targeted on the right hand side. See |
data |
An optional data set in the form of a data frame that contains the variables in |
tols |
a vector of target balance tolerance values for each covariate.
The resulting weighted covariate means will be no further away from the
targets than the specified values. If only one value is supplied, it will be
applied to all covariates. Can also be the output of a call to |
targets |
A vector of target population mean values for each baseline covariate. The resulting weights will yield sample means within |
s.weights |
A vector of sampling weights or the name of a variable in |
b.weights |
A vector of base weights or the name of a variable in |
norm |
|
verbose |
|
... |
Arguments passed on to
|
The optimization is performed by the lower-level function
optweight.svy.fit()
.
Weights are estimated so that the standardized differences between the
weighted covariate means and the corresponding targets are within the given
tolerance thresholds (unless std.binary
or std.cont
are
FALSE
, in which case unstandardized mean differences are considered
for binary and continuous variables, respectively). For a covariate x
with specified tolerance \delta
, the weighted mean will be within
\delta
of the target. If standardized tolerance values are requested,
the standardization factor is the standard deviation of the covariate in the
whole sample. The standardization factor is always unweighted.
See the optweight()
help page for information on interpreting
dual variables and solving convergence failure.
An optweight.svy
object with the following elements:
weights |
The estimated weights, one for each unit. |
covs |
The covariates used in the fitting. Only includes the raw covariates, which may have been altered in the fitting process. |
s.weights |
The provided sampling weights. |
call |
The function call. |
tols |
The tolerance values for each covariate. |
duals |
A data.frame containing the dual variables for each covariate. See |
info |
Information about the performance of the optimization at termination. |
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. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1080/01621459.2015.1023805")}
optweight.svy.fit()
, the lower-level function that performs the fitting.
optweight.fit()
for more details about the optimization options.
optweight()
for estimating weights that balance treatment groups.
library("cobalt")
data("lalonde", package = "cobalt")
cov.formula <- ~ age + educ + race + married + nodegree
targets <- process_targets(cov.formula, data = lalonde,
targets = c(23, 9, .3, .3, .4,
.2, .5))
ows <- optweight.svy(cov.formula,
data = lalonde,
tols = 0,
targets = targets)
ows
#Unweighted means
col_w_mean(ows$covs)
#Weighted means; same as targets
col_w_mean(ows$covs, w = ows$weights)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.