View source: R/get_marginal_effect.R
get_marginal_effect | R Documentation |
Estimates the marginal treatment effect from a logistic regression working model using a specified choice of variance estimator and contrast.
get_marginal_effect(
object,
trt,
strata = NULL,
method = "Ge",
type = "HC0",
contrast = "diff",
reference,
mod = FALSE
)
object |
a fitted glm object. |
trt |
a string specifying the name of the treatment variable
in the model formula. It must be one of the linear predictor variables used
in fitting the |
strata |
an optional string or vector of strings specifying the names of stratification variables. Relevant only for Ye's method and used to adjust the variance-covariance estimation for stratification. If provided, each specified variable must be present in the model. |
method |
a string indicating the chosen method for variance estimation.
Supported methods are |
type |
a string indicating the type of variance estimator to use (only applicable for Ge's method). Supported types include HC0 (default), model-based, HC3, HC, HC1, HC2, HC4, HC4m, and HC5. See vcovHC for heteroscedasticity-consistent estimators. |
contrast |
a string indicating choice of contrast. Defaults to 'diff' for a risk difference. See apply_contrast. |
reference |
a string or list of strings indicating which treatment
group(s) to use as reference level for pairwise comparisons. Accepted values
must be a subset of the levels in the treatment variable. Default to the
first n-1 treatment levels used in the |
mod |
for Ye's method, the implementation of open-source RobinCar package
has an additional variance decomposition step when estimating the robust variance,
which then utilizes different counterfactual outcomes than the original reference.
Set |
The get_marginal_effect
function is a wrapper that facilitates
advanced variance estimation techniques for GLM models with covariate adjustment
targeting a population average treatment effect. It is particularly useful in clinical trial analysis
and other fields requiring robust statistical inference.
It allows researchers to account for complex study designs,
including stratification and treatment contrasts, by providing a flexible
interface for variance-covariance estimation.
an updated glm
object appended with marginal estimate components:
counterfactual.predictions (see predict_counterfactuals),
counterfactual.means (see average_predictions),
robust_varcov (see estimate_varcov),
marginal_est, marginal_se (see apply_contrast) and marginal_results. A summary is shown below
counterfactual.predictions | Counterfactual predictions based on the working model. For each subject in the input glm data, the potential outcomes are obtained by assigning subjects to each of the possible treatment variable levels. Each prediction is associated with a descriptive label explaining the counterfactual scenario. |
counterfactual.means | Average of the counterfactual predictions for each level of the treatment variable. |
robust_varcov | Variance-covariance matrix of the marginal effect estimate for each level of treatment variable, with estimation method indicated in the attributes. |
marginal_est | Marginal treatment effect estimate for a given contrast. |
marginal_se | Standard error estimate of the marginal treatment effect estimate. |
marginal_results | Analysis results data (ARD) containing a summary of the analysis for subsequent reporting. |
trial01$trtp <- factor(trial01$trtp)
fit1 <- glm(aval ~ trtp + bl_cov, family = "binomial", data = trial01) |>
get_marginal_effect(trt = "trtp", method = "Ye", contrast = "diff", reference = "0")
fit1$marginal_results
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.