gformula {trajmsm}R Documentation

Counterfactual means via G-Formula

Description

Calculates counterfactual means using the g-formula approach.

Usage

gformula(
  formula,
  baseline,
  covariates,
  treatment,
  outcome,
  ntimes_interval,
  obsdata
)

Arguments

formula

Specification of the model for the outcome to be fitted.

baseline

Names of the baseline covariates.

covariates

Names of the time-varying covariates (should be a list).

treatment

Names of the time-varying treatment.

outcome

Name of the outcome variable.

ntimes_interval

Length of a time-interval (s).

obsdata

Observed data in wide format.

Value

list_gform_countermeans

List of counterfactual means obtained with g-formula.

Author(s)

Awa Diop, Denis Talbot

Examples


obsdata = gendata(n = 1000, format = "wide", total_followup = 6, seed = 945)
years <- 2011:2016
baseline_var <- c("age","sex")
variables <- c("hyper", "bmi")
var_cov <- c("statins","hyper", "bmi")
covariates <- lapply(years, function(year) {
paste0(variables, year)})
treatment_var <- paste0("statins", 2011:2016)
formula = paste0("y ~", paste0(treatment_var,collapse = "+"), "+",
                paste0(unlist(covariates), collapse = "+"),"+",
                paste0(baseline_var, collapse = "+"))
res_gform <- gformula(formula = formula, baseline = baseline_var, covariates = covariates,
treatment = treatment_var, outcome = "y", ntimes_interval = 6, obsdata =   obsdata )


[Package trajmsm version 0.1.0 Index]