check.targets {optweight} | R Documentation |
Construct and Check Targets Input
Description
Checks whether proposed target population means values for targets
are suitable in number and order for submission to optweight
and optweight.svy
. Users should include one value per variable in formula
. For factor variables, one value per level of the variable is required. The output of check.targets
can also be used as an input to targets
in optweight
and optweight.svy
.
Usage
check.targets(formula,
data = NULL,
targets,
stop = FALSE)
## S3 method for class 'optweight.targets'
print(x, digits = 5, ...)
Arguments
formula |
A formula with the covariates to be balanced with |
data |
An optional data set in the form of a data frame that contains the variables in |
targets |
A vector of target population means values for each covariate. These should be in the order corresponding to the order of the corresponding variable in |
stop |
|
x |
An |
digits |
How many digits to print. |
... |
Ignored. |
Details
The purpose of check.targets
is to allow users to ensure that their proposed input to targets
in optweight
and optweight.svy
is correct both in the number of entries and their order. This is especially important when factor variables and interactions are included in the formula because factor variables are split into several dummies and interactions are moved to the end of the variable list, both of which can cause some confusion and potential error when entering targets
values.
Factor variables are internally split into a dummy variable for each level, so the user must specify a target population mean value for each level of the factor. These must add up to 1, and an error will be displayed if they do not. These values represent the proposrtion of units in the target population with each factor level.
Interactions (e.g., a:b
or a*b
in the formula
input) are always sent to the end of the variable list even if they are specified elsewhere in the formula
. It is important to run check.targets
to ensure the order of the proposed targets
corresponds to the represented order of covariates used in the formula. You can run check.targets
with targets = NULL
to see the order of covariates that is required without specifying any targets.
Value
An optweight.targets
object, which is a named vector of target population mean values, one for each (expanded) covariate specified in formula
. This should be used as user inputs to optweight
and optweight.svy
.
Author(s)
Noah Greifer
See Also
Examples
library("cobalt")
data("lalonde", package = "cobalt")
#Checking if the correct number of entries are included:
check.targets(treat ~ age + race + married +
nodegree + re74,
data = lalonde,
targets = c(25, .4, .1, .5, .3,
.5, 4000))
#Notice race is split into three values (.4, .1, and .5)