apply_contrast {beeca} | R Documentation |
Apply contrast to calculate marginal estimate of treatment effect and corresponding standard error
Description
Calculates the marginal estimate of treatment effect and its corresponding standard error based on a fitted GLM object using specified contrast (summary measure) methods
Usage
apply_contrast(
object,
contrast = c("diff", "rr", "or", "logrr", "logor"),
reference
)
Arguments
object |
a fitted |
contrast |
a string specifying the type of contrast to apply.
Accepted values are "diff" (risk difference), "rr" (risk ratio),
"or" (odds ratio), "logrr" (log risk ratio), "logor" (log odds ratio).
Note: log-transformed ratios (logrr and logor) work better compared to rr
and or when computing confidence intervals using normal approximation.
The choice of contrast affects how treatment effects are calculated and
interpreted. Default is |
reference |
a string indicating which treatment group should be considered as
the reference level. Accepted values are one of the levels in the treatment
variable. Default to the first level used in the This parameter influences the calculation of treatment effects relative to the chosen reference group. |
Details
The apply_constrast()
functions computes the summary measure between two arms
based on the estimated marginal effect and its variance-covariance matrix using
the Delta method.
Note: Ensure that the glm
object has been adequately prepared with
average_predictions()
and estimate_varcov()
before applying apply_contrast()
. Failure to do so may result in
errors indicating missing components.
Value
An updated glm
object with two additional components
appended: marginal_est
(marginal estimate of the treatment effect)
and marginal_se
(standard error of the marginal estimate).
These appended component provide crucial information for interpreting
the treatment effect using the specified contrast method.
See Also
get_marginal_effect()
for estimating marginal effects directly
from an original glm
object
Examples
trial01$trtp <- factor(trial01$trtp)
fit1 <- glm(aval ~ trtp + bl_cov, family = "binomial", data = trial01) |>
predict_counterfactuals(trt = "trtp") |>
average_predictions() |>
estimate_varcov(method = "Ye") |>
apply_contrast("diff", reference = "0")
# Assuming `trial01` is a dataset with treatment (`trtp`)
# and baseline covariate (`bl_cov`)
trial01$trtp <- factor(trial01$trtp)
fit1 <- glm(aval ~ trtp + bl_cov, family = "binomial", data = trial01)
# Preprocess fit1 as required by apply_contrast
fit2 <- fit1 |>
predict_counterfactuals(trt = "trtp") |>
average_predictions() |>
estimate_varcov(method = "Ye")
# Apply contrast to calculate marginal estimates
fit3 <- apply_contrast(fit2, contrast = "diff", reference = "0")
fit3$marginal_est
fit3$marginal_se