Generate a point estimate of the outcome difference and ratio using G-computation
pointEstimate(
data,
outcome.type = c("binary", "count", "count_nb", "rate", "rate_nb", "continuous"),
formula = NULL,
Y = NULL,
X = NULL,
Z = NULL,
subgroup = NULL,
offset = NULL,
rate.multiplier = 1,
exposure.scalar = 1,
exposure.center = TRUE
)
(Required) A data.frame containing variables for
Y
, X
, and Z
or with variables matching the model
variables specified in a user-supplied formula. Data set should also
contain variables for the optional subgroup
and offset
, if
they are specified.
(Required) Character argument to describe the outcome
type. Acceptable responses, and the corresponding error distribution and
link function used in the glm
, include:
(Default) A binomial distribution with link = 'logit' is used.
A Poisson distribution with link = 'log' is used.
A negative binomial model with link = 'log' is used, where the theta parameter is estimated internally; ideal for over-dispersed count data.
A Poisson distribution with link = 'log' is used; ideal for events/person-time outcomes.
A negative binomial model with link = 'log' is used, where the theta parameter is estimated internally; ideal for over-dispersed events/person-time outcomes.
A gaussian distribution with link = 'identity' is used.
(Optional) Default NULL. An object of class "formula" (or one that can be coerced to that class) which provides the the complete model formula, similar to the formula for the glm function in R (e.g. `Y ~ X + Z1 + Z2 + Z3`). Can be supplied as a character or formula object. If no formula is provided, Y and X must be provided.
(Optional) Default NULL. Character argument which specifies the
outcome variable. Can optionally provide a formula instead of Y
and
X
variables.
(Optional) Default NULL. Character argument which specifies the
exposure variable (or treatment group assignment), which can be binary,
categorical, or continuous. This variable can be supplied as a factor
variable (for binary or categorical exposures) or a continuous variable.
For binary/categorical exposures, X
should be supplied as a factor
with the lowest level set to the desired referent. Numeric variables are
accepted, but will be centered (see Note). Character variables are not
accepted and will throw an error. Can optionally provide a formula
instead of Y
and X
variables.
(Optional) Default NULL. List or single character vector which
specifies the names of covariates or other variables to adjust for in the
glm
function. All variables should either be factors, continuous,
or coded 0/1 (i.e. not character variables). Does not allow interaction terms.
(Optional) Default NULL. Character argument that indicates subgroups for stratified analysis. Effects will be reported for each category of the subgroup variable. Variable will be automatically converted to a factor if not already.
(Optional, only applicable for rate/count outcomes) Default NULL. Character argument which specifies the variable name to be used as the person-time denominator for rate outcomes to be included as an offset in the Poisson regression model. Numeric variable should be on the linear scale; function will take natural log before including in the model.
(Optional, only applicable for rate/count outcomes). Default 1. Numeric variable signifying the person-time value to use in predictions; the offset variable will be set to this when predicting under the counterfactual conditions. This value should be set to the person-time denominator desired for the rate difference measure and must be inputted in the units of the original offset variable (e.g. if the offset variable is in days and the desired rate difference is the rate per 100 person-years, rate.multiplier should be inputted as 365.25*100).
(Optional, only applicable for continuous exposure) Default 1. Numeric value to scale effects with a continuous exposure. This option facilitates reporting effects for an interpretable contrast (i.e. magnitude of difference) within the continuous exposure. For example, if the continuous exposure is age in years, a multiplier of 10 would result in estimates per 10-year increase in age rather than per a 1-year increase in age.
(Optional, only applicable for continuous exposure) Default TRUE. Logical or numeric value to center a continuous exposure. This option facilitates reporting effects at the mean value of the exposure variable, and allows for a mean value to be provided directly to the function in cases where bootstrap resampling is being conducted and a standardized centering value should be used across all bootstraps. See note below on continuous exposure variables for additional details.
A named list containing the following:
Point estimates for the risk difference, risk ratio, odds ratio, incidence rate difference, incidence rate ratio, mean difference and/or number needed to treat/harm, depending on the outcome.type
Model formula used to fit the glm
Contrast levels compared
The response variable
Covariates used in the model
Number of observations provided to the model
Error distribution used in the model
A data.frame with the predicted values for the exposed and unexposed counterfactual predictions for each observation in the original dataset (on the log scale)
A data.frame with the marginal mean predicted outcomes for each exposure level
The glm
class object returned from the
fitted regression of the outcome on the exposure and relevant covariates.
The pointEstimate
function executes the following steps on
the data:
Fit a regression of the outcome on the exposure and relevant covariates, using the provided data set.
Using the model fit in step 1, predict counterfactuals (e.g. calculate predicted outcomes for each observation in the data set under each level of the treatment/exposure).
Estimate the marginal difference/ratio of treatment effect by taking the difference or ratio of the average of all observations under the treatment/no treatment regimes.
As counterfactual predictions are generated with random sampling of the
distribution, users should set a seed (set.seed
) prior to
calling the function for reproducible confidence intervals.
Ahern J, Hubbard A, Galea S. Estimating the effects of potential public health interventions on population disease burden: a step-by-step illustration of causal inference methods. Am. J. Epidemiol. 2009;169(9):1140<U+2013>1147. 10.1093/aje/kwp015
Altman DG, Deeks JJ, Sackett DL. Odds ratios should be avoided when events are common. BMJ. 1998;317(7168):1318. 10.1136/bmj.317.7168.1318
Hern<U+00E1>n MA, Robins JM (2020). Causal Inference: What If. Boca Raton: Chapman & Hall/CRC. Book link
Robins J. A new approach to causal inference in mortality studies with a sustained exposure period<U+2014>application to control of the healthy worker survivor effect. Mathematical Modelling. 1986;7(9):1393<U+2013>1512. 10.1016/0270-0255(86)90088-6
Snowden JM, Rose S, Mortimer KM. Implementation of G-computation on a simulated data set: demonstration of a causal inference technique. Am. J. Epidemiol. 2011;173(7):731<U+2013>738. 10.1093/aje/kwq472
Westreich D, Cole SR, Young JG, et al. The parametric g-formula to estimate the effect of highly active antiretroviral therapy on incident AIDS or death. Stat Med. 2012;31(18):2000<U+2013>2009. 10.1002/sim.5316
# NOT RUN {
## Obtain the risk difference and risk ratio for cardiovascular disease or death
## between patients with and without diabetes, while controlling for
## age,
## sex,
## BMI,
## whether the individual is currently a smoker, and
## if they have a history of hypertension.
data(cvdd)
ptEstimate <- pointEstimate(data = cvdd, Y = "cvd_dth", X = "DIABETES",
Z = c("AGE", "SEX", "BMI", "CURSMOKE", "PREVHYP"), outcome.type = "binary")
# }
Run the code above in your browser using DataLab