calc.weights: Calculate outcome weights to address positivity violations

View source: R/calc.weights.R

calc.weightsR Documentation

Calculate outcome weights to address positivity violations

Description

The weights are calculated according to formula (14) in Schomaker et al. (2023).

Usage

calc.weights(X, Anodes = NULL, Ynodes = NULL, Lnodes = NULL, Cnodes = NULL,
             abar = NULL, times = length(Anodes), c = 0.01, screen = FALSE, 
             survival = FALSE, eps = 1e-10, zero = 0, 
             d.method = c("binning", "parametric", "hal_density", "hazardbinning"),
             z.method = c("density", "eps"), w.function = "gal_ga",
             for.sgf = TRUE,
             verbose = TRUE, ...)

Arguments

X

A data frame, following the time-ordering of the variables.

Anodes

A character string of column names in X of the intervention variable(s).

Ynodes

A character string of column names in X of the outcome variable(s).

Lnodes

A character string of column names in X of all confounders, both baseline and time-varying.

Cnodes

A character string of column names in X of the censoring variable(s).

abar

Numeric vector or matrix of intervention values. See Details.

times

Numeric value specifying for how many time points the weights should be calculated.

c

A numeric value (or vector) specifying the threshold(s) below which the weights correspond to the density ratios, rather than 1.

screen

Logical. If TRUE, variable screening with LASSO is performed prior to estimating the conditional densities for the weights.

survival

Logical. If TRUE, a survival setting is assumed and taken into account for model specification.

eps

A numeric value specifying epsilon if z.method="eps". See details.

zero

A numeric value specifying which actual number is considered to be "zero" in the denominator.

d.method

A string specifying which method should be used to estimate the conditional density. One of "binning", "parametric", "hal_density", "hazardbinning".

z.method

A string specifying the method which should be used if the denominator is zero: The default is "density", which modifies the density according to formula (15) in Schomaker et al. (2024). Alternatively, "eps" replaces the denominator with a fixed value specified under eps.

w.function

A string specifying the weight function which specifies how the conditional densities from numerator and denominator as well as c should be combined. Currently, "gal_ga" equates to formula (14) of Schomaker et al. (2024); whereas "gal_ga2" equates to the same weights, but where the cutoff for c to define positivity violations is not based on the conditional treatment density alone, but relative to the density defined in the denominator.

for.sgf

Logical. If TRUE, weights are organized such that they fit the order required for sgf.

verbose

Logical. If TRUE, notes and warnings are printed.

...

Further arguments to be passed on.

Details

Calculates the outcome weights as described in formula (15) of Schomaker et al. (2024).

For details on the specific conditional density estimation methods specified under d.method, see the manual at https://github.com/MichaelSchomaker/CICI.

In survival settings, past censoring and outcome nodes are omitted from the formulae. If censoring is present without a survival setting (e.g. Cnodes describe drop-outs and Y is a continuous outcome), then survival should be set as FALSE.

Value

An object of class Yweights. This is a named list of length of c; each list entry is another list of length(number of time points); each entry is a matrix of size n times I (n=sample size; I=number of Interventions).

Author(s)

Michael Schomaker

References

Schomaker M, McIlleron H, Denti P, Diaz I. (2024) Causal Inference for Continuous Multiple Time Point Interventions, Statistics in Medicine, 43:5380-5400, see also https://arxiv.org/abs/2305.06645.

Examples

data(EFV)

w <- calc.weights(X=EFV, Lnodes  = c("sex", "metabolic", 
                                     "log_age", "NRTI" ,"weight.0",
                                     "adherence.1","weight.1",
                                     "adherence.2","weight.2",
                                     "adherence.3","weight.3",
                                     "adherence.4","weight.4"),
                        Ynodes  = c("VL.0","VL.1","VL.2","VL.3","VL.4"),
                        Anodes  = c("efv.0","efv.1","efv.2","efv.3","efv.4"),
                        d.method="parametric", abar=seq(0,5,1), c=0.01)
                        
summary(w)
# w can now be used under 'Yweights' in sgf()


CICI documentation built on April 7, 2026, 5:08 p.m.