contrast: Contrast Potential Outcomes

View source: R/contrast.R

contrastR Documentation

Contrast Potential Outcomes

Description

Compute pairwise differences of posterior potential outcomes along strata, treatment arms, or time points.

Usage

contrast(object, ...)

## S3 method for class 'PSEstimate'
contrast(
  object,
  S = NULL,
  Z = NULL,
  T = NULL,
  type = c("all", "sequential", "cycle"),
  ...
)

## S3 method for class 'PStrataFit'
contrast(
  object,
  S = NULL,
  Z = NULL,
  T = NULL,
  type = c("all", "sequential", "cycle"),
  ...
)

Arguments

object

A PSEstimate, PSContrast, or PStrataFit object. If PStrataFit, estimate() is called automatically.

...

Additional arguments passed to estimate() when object is a PStrataFit.

S

Strata to contrast. TRUE for all pairwise, or a numeric/logical index vector. NULL (default) = no contrast.

Z

Treatment arms to contrast. TRUE for all pairwise.

T

Time points to contrast (survival only).

type

"all" (all pairwise), "sequential" (consecutive pairs), or "cycle" (consecutive + wrap-around).

Value

A PSContrast object (inherits from PSEstimate).

Examples


data(sim_data_normal)
model <- PStrataModel(
  S.formula = Z + D ~ 1,
  Y.formula = Y ~ 1,
  Y.family  = gaussian(),
  strata    = c(n = "00", c = "01", a = "11"),
  ER        = c("n", "a")
)
ps_fit <- fit(model, data = sim_data_normal, chains = 2, iter = 500)

# Treatment effect (Z contrast) for each stratum
ctr_z <- contrast(ps_fit, Z = TRUE)
summary(ctr_z)
plot(ctr_z)

# Stratum contrasts for each treatment arm
ctr_s <- contrast(ps_fit, S = TRUE)
summary(ctr_s)


PStrata documentation built on May 14, 2026, 5:06 p.m.