View source: R/optweight.svy.R
| optweight.svy | R Documentation |
Estimates stable balancing weights to generalize a sample characterized by supplied covariates to a given target population. The target means are specified with targets and the maximum distance between each weighted covariate mean. See Jackson et al. (2021) 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",
min.w = 1e-08,
verbose = FALSE,
...
)
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,
...
)
formula |
a formula with nothing on the left hand side and the covariates to be targeted on the right hand side. Interactions and functions of covariates are allowed. Can be omitted, in which case all variables in |
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 covariate. The resulting weights will yield sample means within |
s.weights |
a vector of sampling weights. For |
b.weights |
a vector of base weights. If supplied, the desired norm of the distance between the estimated weights and the base weights is minimized. For |
norm |
|
min.w |
|
verbose |
|
... |
for |
covs |
a numeric matrix of covariates to be targeted. |
std.binary, std.cont |
|
solver |
string; the name of the optimization solver to use. Allowable options depend on |
optweight.svy() is the primary user-facing function for estimating stable balancing weights for generalization to a target population. The optimization is performed by the lower-level function optweight.svy.fit(), which transforms the inputs into the required inputs for the optimization functions and then supplies the outputs (the weights, dual variables, and convergence information) back to optweight.svy(). Little processing of inputs is performed by optweight.svy.fit(), as this is normally handled by optweight.svy().
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.
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.
See optweight() for information on norm, solver, and convergence failure.
For optweight.svy(), 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 |
A list containing information about the performance of the optimization at termination. |
norm |
The |
solver |
The |
For optweight.svy.fit(), 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. |
info |
A list containing information about the performance of the optimization at termination. |
norm |
The |
solver |
The |
Jackson, D., Rhodes, K., & Ouwens, M. (2021). Alternative weighting schemes when performing matching-adjusted indirect comparisons. Research Synthesis Methods, 12(3), 333–346. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1002/jrsm.1466")}
optweight() for estimating weights that balance treatment groups.
process_targets() for specifying the covariate target means supplied to targets.
library("cobalt")
data("lalonde", package = "cobalt")
cov.names <- c("age", "educ", "race",
"married", "nodegree")
targets <- c(age = 23,
educ = 9,
race_black = .3,
race_hispan = .3,
race_white = .4,
married = .2,
nodegree = .5)
ows <- optweight.svy(lalonde[cov.names],
targets = targets)
ows
# Unweighted means
col_w_mean(lalonde[cov.names])
# Weighted means; same as targets
col_w_mean(lalonde[cov.names],
w = ows$weights)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.