Skip to contents

cqte() evaluates treated-minus-control predictive quantiles at user-supplied covariate rows.

Usage

# S3 method for class 'causalmixgpd_causal_fit'
cqte(
  fit,
  probs = c(0.1, 0.5, 0.9),
  newdata = NULL,
  interval = "credible",
  level = 0.95,
  show_progress = TRUE
)

Arguments

fit

A "causalmixgpd_causal_fit" object from run_mcmc_causal().

probs

Numeric vector of probabilities in (0, 1) specifying the quantile levels of the outcome distribution to estimate treatment effects at.

newdata

Optional data.frame or matrix of covariates for prediction. If NULL, uses the training covariates stored in fit.

interval

Character or NULL; type of credible interval:

  • NULL: no interval

  • "credible" (default): equal-tailed quantile intervals

  • "hpd": highest posterior density intervals

level

Numeric credible level for intervals (default 0.95 for 95 percent CI).

show_progress

Logical; if TRUE, print step messages and render progress where supported.

Value

An object of class "causalmixgpd_qte" containing the CQTE summary, the probability grid, and the treated/control prediction objects used to construct the effect. The returned object includes a top-level $fit_df data frame for direct extraction.

Details

For each prediction row \(x\), the conditional quantile treatment effect is $$\mathrm{CQTE}(\tau, x) = Q_1(\tau \mid x) - Q_0(\tau \mid x).$$

This estimand is available only for conditional causal models with covariates. For marginal quantile contrasts over the empirical covariate distribution, use qte or qtt.

If the fit includes a PS block, the same PS adjustment is applied to both arm predictions before differencing.

Examples

# \donttest{
N <- 25
X <- data.frame(x1 = stats::rnorm(N))
A <- stats::rbinom(N, 1, 0.5)
y <- abs(stats::rnorm(N)) + 0.1
mcmc_small <- list(niter = 100, nburnin = 50, thin = 1, nchains = 1, seed = 1)
cb <- build_causal_bundle(y = y, X = X, A = A, backend = "sb", kernel = "normal",
                         components = 3, mcmc_outcome = mcmc_small, mcmc_ps = mcmc_small)
fit <- run_mcmc_causal(cb, show_progress = FALSE)
#> Defining model
#> Building model
#> Setting data and initial values
#> Checking model sizes and dimensions
#>   [Note] This model is not fully initialized. This is not an error.
#>          To see which variables are not initialized, use model$initializeInfo().
#>          For more information on model initialization, see help(modelInitialization).
#> ===== Monitors =====
#> thin = 1: beta
#> ===== Samplers =====
#> RW sampler (2)
#>   - beta[]  (2 elements)
#> Compiling
#>   [Note] This may take a minute.
#>   [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
#> Compiling
#>   [Note] This may take a minute.
#>   [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
#> running chain 1...
#> Defining model
#> Building model
#> Setting data and initial values
#> Checking model sizes and dimensions
#>   [Note] This model is not fully initialized. This is not an error.
#>          To see which variables are not initialized, use model$initializeInfo().
#>          For more information on model initialization, see help(modelInitialization).
#> ===== Monitors =====
#> thin = 1: alpha, beta_mean, beta_ps_mean, sd, w
#> ===== Samplers =====
#> conjugate sampler (3)
#>   - sd[]  (3 elements)
#> categorical sampler (15)
#>   - z[]  (15 elements)
#> RW sampler (9)
#>   - alpha
#>   - beta_mean[]  (3 elements)
#>   - beta_ps_mean[]  (3 elements)
#>   - v[]  (2 elements)
#>   [Note] Assigning an RW_block sampler to nodes with very different scales can result in low MCMC efficiency.  If all nodes assigned to RW_block are not on a similar scale, we recommend providing an informed value for the "propCov" control list argument, or using the "barker" sampler instead.
#> Compiling
#>   [Note] This may take a minute.
#>   [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
#> Compiling
#>   [Note] This may take a minute.
#>   [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
#>   [Warning] To calculate WAIC, set 'WAIC = TRUE', in addition to having enabled WAIC in building the MCMC.
#> running chain 1...
#> Defining model
#> Building model
#> Setting data and initial values
#> Checking model sizes and dimensions
#>   [Note] This model is not fully initialized. This is not an error.
#>          To see which variables are not initialized, use model$initializeInfo().
#>          For more information on model initialization, see help(modelInitialization).
#> ===== Monitors =====
#> thin = 1: alpha, beta_mean, beta_ps_mean, sd, w
#> ===== Samplers =====
#> conjugate sampler (3)
#>   - sd[]  (3 elements)
#> categorical sampler (10)
#>   - z[]  (10 elements)
#> RW sampler (9)
#>   - alpha
#>   - beta_mean[]  (3 elements)
#>   - beta_ps_mean[]  (3 elements)
#>   - v[]  (2 elements)
#>   [Note] Assigning an RW_block sampler to nodes with very different scales can result in low MCMC efficiency.  If all nodes assigned to RW_block are not on a similar scale, we recommend providing an informed value for the "propCov" control list argument, or using the "barker" sampler instead.
#> Compiling
#>   [Note] This may take a minute.
#>   [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
#> Compiling
#>   [Note] This may take a minute.
#>   [Note] Use 'showCompilerOutput = TRUE' to see C++ compilation details.
#>   [Warning] To calculate WAIC, set 'WAIC = TRUE', in addition to having enabled WAIC in building the MCMC.
#> running chain 1...
cqte(fit, probs = c(0.5, 0.9), newdata = X[1:5, , drop = FALSE])
#> [cqte] Preparing CQTE inputs
#> [cqte] Preparing propensity-score adjustment
#> [cqte] Predicting treated-arm quantiles
#> [cqte] Predicting control-arm quantiles
#> [cqte] Aggregating CQTE estimates
#> CQTE (Conditional Quantile Treatment Effect)
#>   Prediction points: 5
#>   Quantile grid: 0.5, 0.9
#>   Conditional (covariates): YES
#>   Propensity score used: YES
#>   PS scale: logit
#>   Credible interval: credible (95%)
#> 
#> CQTE estimates (treated - control):
#>    profile index   mean  lower upper
#>  Profile 1   0.5  0.017 -0.491 0.763
#>  Profile 1   0.9 -0.081  -2.55 3.238
#>  Profile 2   0.5  0.004 -0.295 0.232
#>  Profile 2   0.9 -0.145 -2.754 3.171
#>  Profile 3   0.5 -0.039 -1.003 0.663
#>  Profile 3   0.9 -0.179 -2.924 3.112
#> ... (4 more rows)
cqte(fit, probs = c(0.5, 0.9), interval = "credible", level = 0.90)  # 90% CI
#> [cqte] Preparing CQTE inputs
#> [cqte] Preparing propensity-score adjustment
#> [cqte] Predicting treated-arm quantiles
#> [cqte] Predicting control-arm quantiles
#> [cqte] Aggregating CQTE estimates
#> CQTE (Conditional Quantile Treatment Effect)
#>   Prediction points: 25
#>   Quantile grid: 0.5, 0.9
#>   Conditional (covariates): YES
#>   Propensity score used: YES
#>   PS scale: logit
#>   Credible interval: credible (90%)
#> 
#> CQTE estimates (treated - control):
#>  id index   mean  lower upper
#>   1   0.5  0.017 -0.478 0.435
#>   1   0.9 -0.081 -2.518 2.979
#>   2   0.5  0.004 -0.177 0.182
#>   2   0.9 -0.145 -2.535 2.936
#>   3   0.5 -0.039 -0.602 0.608
#>   3   0.9 -0.179 -2.641 2.911
#> ... (44 more rows)
cqte(fit, probs = c(0.5, 0.9), interval = "hpd")  # HPD intervals
#> [cqte] Preparing CQTE inputs
#> [cqte] Preparing propensity-score adjustment
#> [cqte] Predicting treated-arm quantiles
#> [cqte] Predicting control-arm quantiles
#> [cqte] Aggregating CQTE estimates
#> CQTE (Conditional Quantile Treatment Effect)
#>   Prediction points: 25
#>   Quantile grid: 0.5, 0.9
#>   Conditional (covariates): YES
#>   Propensity score used: YES
#>   PS scale: logit
#>   Credible interval: hpd
#> 
#> CQTE estimates (treated - control):
#>  id index   mean  lower upper
#>   1   0.5  0.017 -0.657 0.846
#>   1   0.9 -0.081 -4.099 3.251
#>   2   0.5  0.004 -0.329 0.253
#>   2   0.9 -0.145 -4.302 3.198
#>   3   0.5 -0.039 -1.103 0.892
#>   3   0.9 -0.179 -4.459 3.132
#> ... (44 more rows)
cqte(fit, probs = c(0.5, 0.9), interval = NULL)   # No intervals
#> [cqte] Preparing CQTE inputs
#> [cqte] Preparing propensity-score adjustment
#> [cqte] Predicting treated-arm quantiles
#> [cqte] Predicting control-arm quantiles
#> [cqte] Aggregating CQTE estimates
#> CQTE (Conditional Quantile Treatment Effect)
#>   Prediction points: 25
#>   Quantile grid: 0.5, 0.9
#>   Conditional (covariates): YES
#>   Propensity score used: YES
#>   PS scale: logit
#>   Credible interval: none
#> 
#> CQTE estimates (treated - control):
#>  id index   mean lower upper
#>   1   0.5  0.017    NA    NA
#>   1   0.9 -0.081    NA    NA
#>   2   0.5  0.004    NA    NA
#>   2   0.9 -0.145    NA    NA
#>   3   0.5 -0.039    NA    NA
#>   3   0.9 -0.179    NA    NA
#> ... (44 more rows)
# }