Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/optweight.svy.R

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.

1 2 3 4 5 6 7 8 9 10 |

`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 populaton mean values for each covariate. The resulting weights will yield sample means within |

`s.weights` |
A vector of sampling weights or the name of a variable in |

`verbose` |
Whether information on the optimization problem solution should be printed. This information contains how many iterations it took to estimate the weights and whether the solution is optimal. |

`...` |
For |

`x` |
An |

The optimization is performed by the lower-level function `optweight.svy.fit`

using `solve_osqp`

in the osqp package, which provides a straightforward interface to specifying the constraints and objective function for quadratic optimization problems and uses a fast and flexible solving algorithm.

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 *δ*, the weighted mean will be within *δ* 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 Details for interpretation of these values. |

`info` |
The |

Noah Greifer

Anderson, E. (2018). osqp: Quadratic Programming Solver using the 'OSQP' Library. R package version 0.1.0. https://CRAN.R-project.org/package=osqp

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

https://osqp.org/docs/index.html for more information on osqp, the underlying solver, and the options for `solve_osqp`

.

`osqpSettings`

for details on options for `solve_osqp`

.

`optweight.svy.fit`

, the lower-level function that performs the fitting.

`optweight`

for estimating weights that balance treatment groups.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ```
library("cobalt")
data("lalonde", package = "cobalt")
cov.formula <- ~ age + educ + race + married +
nodegree
targets <- check.targets(cov.formula, data = lalonde,
targets = c(23, 9, .3, .3, .4,
.2, .5))
tols <- check.tols(cov.formula, data = lalonde,
tols = 0)
ows <- optweight.svy(cov.formula,
data = lalonde,
tols = tols,
targets = targets)
ows
covs <- splitfactor(lalonde[c("age", "educ", "race",
"married", "nodegree")],
drop.first = FALSE)
#Unweighted means
apply(covs, 2, mean)
#Weighted means; same as targets
apply(covs, 2, weighted.mean, w = ows$weights)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.