View source: R/optweight.svy.fit.R
optweight.svy.fit | R Documentation |
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.
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,
...
)
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 |
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 |
|
std.binary , std.cont |
|
min.w |
|
verbose |
|
solver |
string; the name of the optimization solver to use. Allowable options depend on |
... |
Options that are passed to the settings function corresponding to |
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.
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. |
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()
which you should use for estimating the
balancing weights, unless you know better.
optweight.fit()
for more details about the allowed norms and optimization.
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)
#Weighted means; same as targets
col_w_mean(covs, w = ows.fit$w)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.