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 weightit.fit
as.weightit(x, covs = NULL, ...)
# S3 method for default
as.weightit(
x,
treat,
covs = NULL,
estimand = NULL,
s.weights = NULL,
ps = NULL,
...
)
as.weightitMSM(x, ...)
# S3 method for default
as.weightitMSM(
x,
treat.list,
covs.list = NULL,
estimand = NULL,
s.weights = NULL,
ps.list = NULL,
...
)
Arguments
- x
required; a
numeric
vector of weights, one for each unit, or aweightit.fit
object 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 aweightit.fit
object, this should not be the matrix supplied to thecovs
argument 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
x
is a vector of weights.- estimand
an optional
character
of length 1 giving the estimand. The text is not checked.- s.weights
an optional
numeric
vector of sampling weights, one for each unit.- ps
an optional
numeric
vector 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.frame
s of covariates 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
numeric
vectors 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.0123 |---------------------------| 11.9693
#> control 0.0039 |------------------------| 10.6706
#>
#> - Units with the 5 most extreme weights by group:
#>
#> 451 340 496 25 216
#> treated 7.6391 7.9751 8.6735 9.3784 11.9693
#> 404 265 260 348 52
#> control 8.102 8.1265 9.3111 9.4798 10.6706
#>
#> - Weight statistics:
#>
#> Coef of Var MAD Entropy # Zeros
#> treated 1.023 0.773 0.455 0
#> control 0.984 0.747 0.426 0
#>
#> - Effective Sample Sizes:
#>
#> Control Treated
#> Unweighted 335. 165.
#> Weighted 170.41 80.91
# See ?weightit.fit for using as.weightit() with a
# weightit.fit object.