Contrast generic

Description

S3 generic dispatched on the class of fit. survatr ships contrast.survatr_fit() for time-indexed survival / risk / RMST contrasts.

causatr::contrast() (same symbol name in causatr, but not an S3 generic there) handles scalar-outcome causatr_fit objects. If both packages are attached, this generic shadows causatr::contrast(); users who need the causatr path should call causatr::contrast() explicitly.

Usage

contrast(fit, ...)

Arguments

fit A fitted model object.
Arguments passed to methods.

Value

Method-dependent.

See Also

Other survatr_result methods: contrast.survatr_fit(), forrest(), forrest.survatr_result(), plot.survatr_result(), print.survatr_result(), tidy.survatr_result()

Examples

library("survatr")

# Small rectangular person-period dataset: 30 ids over 4 periods.
set.seed(1)
n_id <- 30L
K <- 4L
pp <- data.frame(
  id = rep(seq_len(n_id), each = K),
  t = rep(seq_len(K), times = n_id),
  A = rep(rbinom(n_id, 1L, 0.5), each = K),
  Y = rbinom(n_id * K, 1L, 0.1)
)

fit <- surv_fit(pp, "Y", "A", ~1, "id", "t", time_formula = ~ factor(t))

# Contrast two static interventions; dispatches to contrast.survatr_fit().
contrast(
  fit,
  interventions = list(a1 = causatr::static(1), a0 = causatr::static(0)),
  times = 1:4,
  type = "risk_difference"
)
<survatr_result>
  Type:        risk_difference
  Reference:   a1
  CI method:   none
  Time grid:   [1, 4] (4 unique times)
  Estimates:   8 rows
  Contrasts:   4 rows

   contrast  time    estimate    se ci_lower ci_upper
     <char> <int>       <num> <num>    <num>    <num>
1: a0 vs a1     1 -0.06035855    NA       NA       NA
2: a0 vs a1     2 -0.09674334    NA       NA       NA
3: a0 vs a1     3 -0.14352823    NA       NA       NA
4: a0 vs a1     4 -0.14352823    NA       NA       NA