standardize_glm_dr | R Documentation |
Get regression standardized doubly-robust estimates from a glm
standardize_glm_dr(
formula_outcome,
formula_exposure,
data,
values,
ci_level = 0.95,
ci_type = "plain",
contrasts = NULL,
family_outcome = "gaussian",
family_exposure = "binomial",
reference = NULL,
transforms = NULL
)
formula_outcome |
The formula which is used to fit the glm model for the outcome. |
formula_exposure |
The formula which is used to fit the glm model for the exposure.
If not |
data |
The data. |
values |
A named list or data.frame specifying the variables and values at which marginal means of the outcome will be estimated. |
ci_level |
Coverage probability of confidence intervals. |
ci_type |
A string, indicating the type of confidence intervals. Either "plain", which gives untransformed intervals, or "log", which gives log-transformed intervals. |
contrasts |
A vector of contrasts in the following format:
If set to |
family_outcome |
The family argument which is used to fit the glm model for the outcome. |
family_exposure |
The family argument which is used to fit the glm model for the exposure. |
reference |
A vector of reference levels in the following format:
If |
transforms |
A vector of transforms in the following format:
If set to |
standardize_glm_dr
performs regression standardization
in generalized linear models, see e.g., documentation for standardize_glm_dr
. Specifically,
this version uses a doubly robust estimator for standardization, meaning inference is valid
when either the outcome regression or the exposure model is correctly specified
and there is no unmeasured confounding.
An object of class std_glm
. Obtain numeric results in a data frame with the tidy.std_glm function.
This is a list with the following components:
An unnamed list with one element for each of the requested contrasts. Each element is itself a list with the elements:
Estimated counterfactual means and standard errors for each exposure level
Estimated covariance matrix of counterfactual means
The estimated regression model for the outcome
The estimated exposure model
A character vector of the exposure variable names
Data.frame of the estimates of the contrast with inference
The transform argument used for this contrast
The requested contrast type
The reference level of the exposure
Confidence interval type
Confidence interval level
A named list with the elements:
Estimated counterfactual means and standard errors for each exposure level
Estimated covariance matrix of counterfactual means
The estimated regression model for the outcome
The estimated exposure model
A character vector of the exposure variable names
Gabriel E.E., Sachs, M.C., Martinussen T., Waernbaum I., Goetghebeur E., Vansteelandt S., Sjölander A. (2024), Inverse probability of treatment weighting with generalized linear outcome models for doubly robust estimation. Statistics in Medicine, 43(3):534–547.
# doubly robust estimator
# needs to correctly specify either the outcome model or the exposure model
# for confounding
# NOTE: only works with binary exposures
data <- AF::clslowbwt
x <- standardize_glm_dr(
formula_outcome = bwt ~ smoker * (race + age + lwt) + I(age^2) + I(lwt^2),
formula_exposure = smoker ~ race * age * lwt + I(age^2) + I(lwt^2),
family_outcome = "gaussian",
family_exposure = "binomial",
data = data,
values = list(smoker = c(0, 1)), contrasts = "difference", reference = 0
)
set.seed(6)
n <- 100
Z <- rnorm(n)
X <- rbinom(n, 1, prob = (1 + exp(Z))^(-1))
Y <- rbinom(n, 1, prob = (1 + exp(as.numeric(X) + Z))^(-1))
dd <- data.frame(Z, X, Y)
x <- standardize_glm_dr(
formula_outcome = Y ~ X * Z, formula_exposure = X ~ Z,
family_outcome = "binomial",
data = dd,
values = list(X = 0:1), reference = 0,
contrasts = c("difference"), transforms = c("odds")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.