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.

as.weightit(...)

# S3 method for default
as.weightit(weights,
            treat,
            covs = NULL,
            estimand = NULL,
            s.weights = NULL,
            ps = NULL,
            ...)

as.weightitMSM(...)

# S3 method for default
as.weightitMSM(weights,
               treat.list,
               covs.list = NULL,
               estimand = NULL,
               s.weights = NULL,
               ps.list = NULL,
               ...)

Arguments

weights

required; a numeric vector of weights, one for each unit.

treat

required; a vector of treatment statuses, one for each unit.

covs

an optional data.frame of covariates. For using WeightIt functions, this is not necessary, but for use with cobalt it is.

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.frames 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.

...

additional arguments. These must be named. They will be included in the output object.

Value

An object of class weightit (for as.weightit()) or weightitMSM (for as.weightitMSM()).

Author

Noah Greifer

Examples

treat <- rbinom(500, 1, .3)
weights <- rchisq(500, df = 2)
W <- as.weightit(weights= weights, treat = treat,
                 estimand = "ATE")
summary(W)
#>                  Summary of weights
#> 
#> - Weight ranges:
#> 
#>            Min                                   Max
#> treated 0.0345 |---------------------------| 12.9095
#> control 0.0020 |---------------------------| 12.8696
#> 
#> - Units with 5 most extreme weights by group:
#>                                                 
#>                3      85     197     193       1
#>  treated  8.2941  8.9772 10.2539 10.3918 12.9095
#>              226     352     485     131     330
#>  control 10.2435 10.3664  10.592 10.7309 12.8696
#> 
#> - Weight statistics:
#> 
#>         Coef of Var   MAD Entropy # Zeros
#> treated       1.131 0.785   0.486       0
#> control       1.016 0.716   0.418       0
#> 
#> - Effective Sample Sizes:
#> 
#>            Control Treated
#> Unweighted   344.   156.  
#> Weighted     169.6   68.68