This function allows users to get the benefits of a weightit
object when using weights not estimated with weightit() or weightitMSM().
These benefits include diagnostics, plots, and direct compatibility with
cobalt for assessing balance.
Usage
as.weightit(x, ...)
# S3 method for class 'weightit.fit'
as.weightit(x, covs = NULL, ...)
# Default S3 method
as.weightit(
x,
treat,
covs = NULL,
estimand = NULL,
s.weights = NULL,
ps = NULL,
...
)
as.weightitMSM(x, ...)
# Default S3 method
as.weightitMSM(
x,
treat.list,
covs.list = NULL,
estimand = NULL,
s.weights = NULL,
ps.list = NULL,
...
)Arguments
- x
required; a
numericvector of weights, one for each unit, or aweightit.fitobject fromweightit.fit().- ...
additional arguments. These must be named. They will be included in the output object.
- covs
an optional data frame of covariates. For using WeightIt functions, this is not necessary, but for use with cobalt it is. Note that when using with a
weightit.fitobject, this should not be the matrix supplied to thecovsargument ofweightit.fit()unless there are no factor/character variables in it. Ideally this is the original, unprocessed covariate data frame with factor variables included.- treat
a vector of treatment statuses, one for each unit. Required when
xis a vector of weights.- estimand
an optional
characterof length 1 giving the estimand. The text is not checked.- s.weights
an optional
numericvector of sampling weights, one for each unit.- ps
an optional
numericvector of propensity scores, one for each unit.- treat.list
a list of treatment statuses at each time point.
- covs.list
an optional list of data frames of covariates at each time point. For using WeightIt functions, this is not necessary, but for use with cobalt it is.
- ps.list
an optional list of
numericvectors of propensity scores at each time point.
Examples
treat <- rbinom(500, 1, .3)
weights <- rchisq(500, df = 2)
W <- as.weightit(weights, treat = treat, estimand = "ATE")
summary(W)
#> Summary of weights
#>
#> ─ Weight ranges:
#>
#> Min Max
#> Treated 0.019 ╞═══════════════════╡ 8.843
#> Control 0.004 ╞═══════════════════════════╡ 12.028
#>
#> ─ Units with the 5 most extreme weights by group:
#>
#> 88 271 60 403 99
#> Treated 6.23 7.314 7.614 7.65 8.843
#> 169 187 430 50 415
#> Control 8.826 8.83 9.904 11.167 12.028
#>
#> ─ Weight statistics:
#>
#> Coef of Var MAD Entropy # Zeros
#> Treated 0.947 0.766 0.411 0
#> Control 1.002 0.734 0.43 0
#>
#> ─ Effective Sample Sizes:
#>
#> Control Treated
#> Unweighted 346. 154.
#> Weighted 172.99 81.44
# See ?weightit.fit for using as.weightit() with a
# weightit.fit object.
