Learn R Programming

cobalt (version 5.0.0)

.cens: Mark a Censoring Indicator

Description

.cens() marks a variable as a censoring indicator rather than a treatment, so that bal.tab() assesses the balance of the units still under observation against the full at-risk sample. It is most often used on the left side of a formula, as in .cens(C) ~ x1 + x2, but it can also be called directly and supplied to bal.tab()'s treat argument.

Usage

.cens(x)

Value

x coerced to a 0/1 numeric vector of class treat (see treat) with a "treat.type" attribute of "censoring". Any value other than 0, 1, or NA throws an error.

Inside a formula the marker is stripped before the formula is processed, so .cens() is not actually evaluated there and the treatment name remains that of the indicator itself (e.g., C rather than .cens(C)).

Arguments

x

a censoring indicator: a numeric variable taking only the values 0 (still under observation) and 1 (censored), a logical variable, or a factor with levels 0/1 or FALSE/TRUE. Missing values are allowed and preserved.

Note on the coding convention

The survival convention is used: 1 means the unit is censored (drops out of observation) and 0 means it remains under observation. This is the opposite of an "observed" or "event" indicator.

Missing values are permitted because a unit censored at an earlier time point has no later indicator. Units with a missing indicator are not at risk, so they are in neither sample.

Details

Censoring is considered its own treatment type in cobalt, distinct from binary, multi-category, and continuous treatments. What matters is whether the units still under observation resemble the full sample once weighted. See class-bal.tab.cens for the output this produces and the arguments that control it.

This function is deliberately identical in name and contract to WeightIt::.cens(), so that the same code works whichever package is attached; cobalt defines its own only to avoid depending on WeightIt. bal.tab() recognizes an indicator tagged by either.

See Also

  • class-bal.tab.cens for the output of bal.tab() with a censoring indicator

  • bal.tab()

Examples

Run this code
if (FALSE) { # rlang::is_installed("WeightIt")
data("lalonde", package = "cobalt")

# A censoring indicator: 1 = lost to follow-up
set.seed(1234)
lalonde$C <- rbinom(nrow(lalonde), 1,
                    prob = plogis(-1.5 + 0.05 * lalonde$age))

# Inverse probability of censoring weights
W <- WeightIt::weightit(.cens(C) ~ age + educ + race,
                        data = lalonde, method = "glm")

# Balance of the weighted uncensored units against the
# full at-risk sample
bal.tab(W, un = TRUE)

# The same thing without WeightIt, using the weights directly
bal.tab(.cens(C) ~ age + educ + race, data = lalonde,
        weights = W$weights, un = TRUE)
}

Run the code above in your browser using DataLab