Skip to contents

For a Cox model containing both doses, the always-treat-vs-never-treat effect is the linear combination exp(b_drug1 + b_drug2). This is exactly Stata's lincom drug1 + drug2; here it is computed with marginaleffects::hypotheses(), which reads the fit's own variance-covariance matrix (the robust sandwich version when the model was fitted with cluster = id), so no standard error is computed by hand.

Usage

hr_msm(fit, method, contrast = "drug1 + drug2 = 0")

Arguments

fit

A survival::coxph() fit that contains both drug1 and drug2.

method

A label for this row (appears on the forest plot).

contrast

The hypothesis string. Defaults to "drug1 + drug2 = 0"; the = 0 is only the null reference (HR 1 on the log scale) and does not change the point estimate.

Value

A one-row tibble with columns method, hr, lo, hi.

Examples

dat <- simulate_hr_agent(n = 2000)
fit <- survival::coxph(
  survival::Surv(t_start, t_stop, death) ~ drug1 + drug2, cluster = id, data = dat)
hr_msm(fit, "Marginal (unweighted)")
#> Warning: The default delta method standard errors for `coxph` models only take into account uncertainty in the regression coefficients. Standard errors may be too small. Use the `inferences()` function or set `vcov` to "rsample", "boot"  or "fwb" to compute confidence intervals by bootstrapping. Set `vcov` to `FALSE` or `options(marginaleffects_safe=FALSE)` to silence this warning.
#> # A tibble: 1 × 4
#>   method                   hr    lo    hi
#>   <chr>                 <dbl> <dbl> <dbl>
#> 1 Marginal (unweighted) 0.516 0.258  1.03