Skip to contents

Generates balance statistics for data coming from a longitudinal treatment scenario. The primary input is in the form of a list of formulas or data.frames contain the covariates at each time point. bal.tab() automatically classifies this list as either a data.frame.list or formula.list, respectively.

Usage

# S3 method for data.frame.list
bal.tab(x, 
        treat.list,
        stats,
        int = FALSE,
        poly = 1,
        distance = NULL,
        addl = NULL,
        data = NULL,
        continuous,
        binary,
        s.d.denom,
        thresholds = NULL,
        weights = NULL,
        cluster = NULL,
        imp = NULL,
        pairwise = TRUE,
        s.weights = NULL,
        abs = FALSE,
        subset = NULL,
        quick = TRUE,
        ...)
    
# S3 method for formula.list
bal.tab(x, 
        stats,
        int = FALSE,
        poly = 1,
        distance = NULL,
        addl = NULL,
        data = NULL,
        continuous,
        binary,
        s.d.denom,
        thresholds = NULL,
        weights = NULL,
        cluster = NULL,
        imp = NULL,
        pairwise = TRUE,
        s.weights = NULL,
        abs = FALSE,
        subset = NULL,
        quick = TRUE,
        ...)

Arguments

x

either a list of data frames containing all the covariates to be assessed at each time point or a list of formulas with the treatment for each time period on the left and the covariates for which balance is to be displayed on the right. Covariates to be assessed at multiple points must be included in the entries for each time point. Data must be in the "wide" format, with one row per unit. If a formula list is supplied, an argument to data is required unless all objects in the formulas exist in the environment.

treat.list

treatment status for each unit at each time point. This can be specified as a list or data frame of vectors, each of which contains the treatment status of each individual at each time point, or a list or vector of the names of variables in data that contain treatment at each time point. Required for the data.frame.list method.

stats, int, poly, distance, addl, data, continuous, binary, thresholds, weights, cluster, imp, pairwise, s.weights, abs, subset, quick, ...

see bal.tab() for details.

See below for a special note on the s.d.denom argument.

The following argument has a special note when used with longitudinal treatments:

s.d.denom

it is recommended not to set this argument for longitudinal treatments.

Details

bal.tab.formula.list() and bal.tab.data.frame.list() generate a list of balance summaries for each time point based on the treatments and covariates provided. All data must be in the "wide" format, with exactly one row per unit and columns representing variables at different time points. See the WeightIt::weightitMSM() documentation for an example of how to transform long data into wide data using reshape().

Multiple sets of weights can be supplied simultaneously by including entering a data frame or a character vector containing the names of weight variables found in data or a list thereof. When only one set of weights is supplied, the output for the adjusted group will simply be called "Adj", but otherwise will be named after each corresponding set of weights. Specifying multiple sets of weights will also add components to other outputs of bal.tab().

Value

An object of class bal.tab.msm containing balance summaries at each time point. Each balance summary is its own bal.tab object. See bal.tab.msm for more details.

See bal.tab() base methods for more detailed information on the value of the bal.tab objects produced for each time point.

Author

Noah Greifer

See also

bal.tab() base methods for details of calculations.

bal.tab.msm for output and related options. bal.tab.cluster for more information on clustered data. bal.tab.imp for more information on multiply imputed data. bal.tab.multi for more information on multi-category treatments.

Examples

if (requireNamespace("twang", quietly = TRUE)) {
data("iptwExWide", package = "twang")
library("cobalt")

## Estimating longitudinal propensity scores and weights
ps1 <- glm(tx1 ~ age + gender + use0,
            data = iptwExWide, 
            family = "binomial")$fitted.values
w1 <- ifelse(iptwExWide$tx1 == 1, 1/ps1, 1/(1-ps1))
ps2 <- glm(tx2 ~ age + gender + use0 + tx1 + use1,
            data = iptwExWide, 
            family = "binomial")$fitted.values
w2 <- ifelse(iptwExWide$tx2 == 1, 1/ps2, 1/(1-ps2))
ps3 <- glm(tx3 ~ age + gender + use0 + tx1 + use1 + tx2 + use2,
            data = iptwExWide, 
            family = "binomial")$fitted.values
w3 <- ifelse(iptwExWide$tx3 == 1, 1/ps3, 1/(1-ps3))
                     
w <- w1*w2*w3

# Formula interface plus addl:
bal.tab(list(tx1 ~ use0 + gender,
             tx2 ~ use0 + gender + use1 + tx1,
             tx3 ~ use0 + gender + use1 + tx1 + use2 + tx2),
        data = iptwExWide, 
        weights = w,
        distance = list(~ps1, ~ps2, ~ps3),
        addl = ~age*gender,
        un = TRUE)
        
# data frame interface:
bal.tab(list(iptwExWide[c("use0", "gender")],
             iptwExWide[c("use0", "gender", "use1", "tx1")],
             iptwExWide[c("use0", "gender", "use1", "tx1", "use2", "tx2")]),
        treat.list = iptwExWide[c("tx1", "tx2", "tx3")], 
        weights = w,
        distance = list(~ps1, ~ps2, ~ps3),
        un = TRUE)
}
#> Balance summary across all time points
#>          Times     Type Max.Diff.Un Max.Diff.Adj
#> ps1          1 Distance      0.7862       0.0251
#> use0   1, 2, 3  Contin.      0.2668       0.0558
#> gender 1, 2, 3   Binary      0.2945       0.0263
#> ps2          2 Distance      0.5288       0.0065
#> use1      2, 3  Contin.      0.1662       0.0316
#> tx1       2, 3   Binary      0.1695       0.0171
#> ps3          3 Distance      0.6565       0.0229
#> use2         3  Contin.      0.1087       0.0315
#> tx2          3   Binary      0.2423       0.0085
#> 
#> Effective sample sizes
#>  - Time 1
#>            Control Treated
#> Unadjusted  294.     706. 
#> Adjusted    185.18   573.6
#>  - Time 2
#>            Control Treated
#> Unadjusted   492.   508.  
#> Adjusted     318.9  264.49
#>  - Time 3
#>            Control Treated
#> Unadjusted  415.     585. 
#> Adjusted    235.67   366.4