gcomputation: an R Package for Estimating Marginal Effects Using G-Computation

Description

The R package ‘gcomputation’ provides functions to compute G-Computation (GC) to estimate marginal effects. It has functions for estimating marginal effects for binary, time-to-event, continuous and count outcomes regarding two exposures. The package implements GC with various working models or algorithms, referred to as Q-models.

Key Features

gc_binary, gc_times, gc_continuous and gc_count are the main functions, implementing GC to estimate marginal functions for binary, time-to-event, continuous and count outcomes regarding two exposures using a variety of modeling strategies.

The package supports several methods to construct the Q-model:

The package offers estimation of three types of marginal effects:

S3 methods are included for objects generated by gc_logistic and gc_survival functions, allowing for:

Other Exported Functions and Data:

The package also supports bootstrapping for confidence interval estimation, with options for "bcv" (default) or "boot" types and a default of 500 bootstrap resamples. Users can also control whether tuning parameters are estimated within each bootstrap iteration or on the total population.

Basic Usage

For a binary outcome:

data("dataPROPHYVAP")

.f <- formula(VAP ~ GROUP * (AGE + SEX + BMI + DIABETES))

# 1. Standard execution
# boot.tune=TRUE estimates tuning parameters inside each bootstrap iteration.
gc_bin <- gc_binary(formula=.f, model="ridge", data=dataPROPHYVAP, group="GROUP",
                 cv=10, boot.type="bcv", boot.number=500, boot.tune=TRUE,
                 effect="ATE", progress=TRUE, seed=5192)
gc_bin

# Summary specifying Asymptotic CIs ("norm")
summary(gc_bin, ci.type="norm")

# Calibration plot
plot(gc_bin)


# 2. Execution with multiple imputation
# Uses boot.mi=TRUE and m=5. boot.tune=FALSE to only estimate it once on the complete data set
.f_mi <- formula(VAP ~ GROUP * (AGE + SEX + BMI + DIABETES + GLASGOW + INJURY))
gc_mi <- gc_binary(formula=.f_mi, model="elasticnet", data=dataPROPHYVAP,
                   group="GROUP", cv=10, boot.type="bcv", boot.number=500, boot.tune=FALSE,
                   effect="ATE", progress=TRUE, seed=8051, boot.mi=TRUE, m=5)

# Plotting the calibration curve, smoothed across m imputations
plot(gc_mi, smooth=TRUE) 

# Summary specifying Non-parametric CIs ("perc")
summary(gc_mi, ci.type="perc")


# 3. Transportability
# Define a new dataset (e.g., a subset of younger patients, AGE<=50)
newdata_binary <- subset(dataPROPHYVAP, AGE<=50)

# Transport the fitted gc_bin model to the new dataset
gc_transport <- transport(object=gc_bin, newdata=newdata, estim_var = "monte_carlo", n.sim=10)
summary(gc2, ci.type="perc", ci.level=0.95)

summary(gc_transport, ci.type="norm")

For a survival outcome:

data(dataPROPHYVAP)

.ft <- formula(Surv(TIME_DEATH, DEATH) ~ GROUP * (AGE + BMI + GLASGOW + LEUKO))

gc_surv <- gc_times(formula=.ft, model="lasso", data=dataPROPHYVAP, group="GROUP",
              param.tune=0.03, boot.type="bcv", boot.number=500, boot.tune=FALSE,
              effect="ATE", pro.time=30, seed=5312)

gc_surv
summary(gc_surv, ci.type="perc")

#Predicted survival curves for treatment groups
plot(gc_surv, method="survival", col=c("red3","blue3"))
legend("bottomleft", c("Placebo", "Ceftriaxone"), col=c("red3","blue3"), lty=1)

Installation

To install the version from GitHub:

remotes::install_github("chupverse/gcomputation")

Reporting bugs

You can report any issues at this link.