Learn R Programming

gFormulaMI (version 1.0.0)

gFormulaImpute: G-formula multiple imputation

Description

gFormulaImpute creates multiple imputed synthetic datasets of longitudinal histories under specified treatment regimes of interest, based on the G-formula.

Usage

gFormulaImpute(
  data,
  M = 50,
  trtVars,
  trtRegimes,
  nSim = NULL,
  micePrintFlag = FALSE,
  silent = FALSE,
  method = NULL,
  predictorMatrix = NULL
)

Value

an S3 object of class mids (multiply imputed dataset)

Arguments

data

The observed data frame

M

The number of imputed datasets to generate

trtVars

A vector of variable names indicating the time-varying treatment variables

trtRegimes

A vector specifying the treatment regime of interest, or a list of vectors specifying the treatment regimes of interest

nSim

The number of individuals to simulate in each imputed dataset. Defaults to number of individuals in observed data

micePrintFlag

TRUE/FALSE specifying whether the output from the call(s) to mice should be printed

silent

TRUE/FALSE indicating whether to print output to console (FALSE) or not (TRUE)

method

An optional method argument to pass to mice. If not specified, the default is to impute continuous variables using normal linear regression (norm), binary variables using logistic regression (logreg), polytomous regression for unordered factors and proportional odds model for ordered factors

predictorMatrix

An optional predictor matrix to specify which variables to use as predictors in the imputation models. The default is to impute sequentially, i.e. impute using all variables to the left of the variable being imputed as covariates

Author

Jonathan Bartlett jonathan.bartlett1@lshtm.ac.uk

Details

gFormulaImpute creates multiple imputed synthetic datasets of longitudinal histories under specified treatment regimes of interest, based on the G-formula, as described in Bartlett et al 2023. Specifically, to the observed data frame, an additional nSim rows are added in which all variables are set to missing, except the time-varying treatment variables. The latter are set to the values as specified in the trtRegimes argument. If multiple treatment regimes are specified, nSim rows are added for each of the specified treatment regimes.

gFormulaImpute uses the mice package to impute the potential outcome values of the time-varying confounders and outcome in the synthetic datasets. Imputation is performed sequentially from left to right in the data frame. As such, the variables must be ordered in time in the input data frame, with the time-varying confounders at each time followed by the corresponding treatment variable at that time.

For the data argument, gFormulaImpute expects either a fully observed (complete) data frame, or else a set of multiple imputation stored in an object of class mids (from the mice package).

Unlike with Rubin's regular multiple imputation pooling rules, it is possible for the pooling rules developed by Raghunathan et al (2003) to give negative variance estimates. The probability of this occurring is reduced by increasing M and/or nSim.

gFormulaImpute returns an object of class mids. This can be analysed using the same methods that imputed datasets from mice can be analysed with (see examples). However, Rubin's standard pooling rules are not valid for analysis of the synthetic datasets. Instead, the synthetic variance estimator of Raghunathan et al (2003) must be used, as implemented in the syntheticPool function.

The development of the gFormulaMI package was supported by a grant from the UK Medical Research Council (MR/T023953/1).

References

Bartlett JW, Olarte Parra C, Daniel RM. G-formula for causal inference via multiple imputation. 2023 https://arxiv.org/abs/2301.12026

Raghunathan TE, Reiter JP, Rubin DB. 2003. Multiple imputation for statistical disclosure limitation. Journal of Official Statistics, 19(1), p.1-16.

Examples

Run this code
set.seed(7626)
#impute synthetic datasets under two regimes of interest
imps <- gFormulaImpute(data=simDataFullyObs,M=10,
                        trtVars=c("a0","a1","a2"),
                        trtRegimes=list(c(0,0,0),c(1,1,1)))
#fit linear model to final outcome with regime as covariate
fits <- with(imps, lm(y~factor(regime)))
#pool results using Raghunathan et al 2003 rules
syntheticPool(fits)


Run the code above in your browser using DataLab