sbw_estimate: Estimate a treatment effect from a fitted 'sbw_fit' object

View source: R/sbw_estimate.R

sbw_estimateR Documentation

Estimate a treatment effect from a fitted sbw_fit object

Description

Estimate a treatment effect from a fitted sbw_fit object

Usage

sbw_estimate(object, outcome, estimand, ...)

## S3 method for class 'sbw_fit'
sbw_estimate(
  object,
  outcome,
  estimand,
  data = NULL,
  probs = 0.5,
  horizon = NULL,
  B = 1500,
  alpha = 0.05,
  ci_method = c("wald", "percentile"),
  seed = NULL,
  ...
)

Arguments

object

An sbw_fit from sbw_weights().

outcome

A one-sided-response formula naming the outcome, e.g. Y ~ 1 (or Surv(time, status) ~ 1 for estimand = "survival_ratio"; Surv() resolves without attaching the survival package).

estimand

One of "ATE", "RR" (relative risk, i.e. ratio of weighted arm means), "survival_ratio", "mann_whitney", "quantile_diff", or "quantile_ratio". No user-supplied functional is accepted; an uncovered estimand means: take weights(object) and run (and bootstrap) your own estimator.

...

Passed to methods.

data

Optional data frame holding the outcome, for when the weights were fit on baseline data before outcomes were available. Its rows must correspond one-to-one, in the same order, to the data passed to sbw_weights(); any column the two share is checked for agreement. Defaults to the data the weights were fit on.

probs

Vector of probabilities in (0, 1), used when estimand is "quantile_diff" or "quantile_ratio". Default 0.5 (the median).

horizon

Time t0 at which to evaluate the survival ratio; required for estimand = "survival_ratio".

B

Number of bootstrap replicates.

alpha

Significance level for the confidence interval.

ci_method

Either "wald" (default) or "percentile".

seed

Optional seed set at the start of the bootstrap.

Details

The bootstrap resamples participants independently (a nonparametric row bootstrap), which is valid under simple randomization. It does not account for stratified or covariate-adaptive randomization (permuted blocks, minimization, biased coin); under those designs the confidence intervals may be miscalibrated.

For estimand = "survival_ratio", if the SBW point estimate or its bootstrap standard error is non-finite, the unadjusted Kaplan-Meier ratio is returned instead, with a warning and mc_fail = TRUE.

Value

An object of class sbw_estimate: a list with estimand; estimate (named by estimand, or ⁠q<p>⁠ per quantile); se, the bootstrap standard error (on the log scale when scale = "log"); ci, a matrix with one row per estimate (lower, upper) on the estimate's own scale; scale ("log" for "RR", "quantile_ratio", and "survival_ratio", otherwise "identity"); alpha; and B. Most estimands also return boot_fail_rate, the fraction of bootstrap resamples that failed. "survival_ratio" instead returns horizon, mc_fail, and detail (the full boot_km_ratio() result, which includes its own boot_fail_rate).

Examples

set.seed(1)
n = 100
trial_baseline = data.frame(
  age = rnorm(n, 50, 10),
  region = sample(c("N", "S"), n, replace = TRUE),
  arm = rbinom(n, 1, 0.5)
)
# Design stage: fit weights before any outcomes exist.
sbw = sbw_weights(~ age + region, data = trial_baseline, treatment = arm)

# Analysis stage: outcomes arrive later, one row per participant, same order.
trial_outcomes = data.frame(Y = rbinom(n, 1, plogis(-1 + 0.02 * trial_baseline$age)))
sbw_estimate(sbw, Y ~ 1, estimand = "RR", data = trial_outcomes, B = 200, seed = 1)

sbwadjust documentation built on Oct. 10, 2026, 5:08 p.m.