cfsens_pac: Sensitivity analysis of individual treatment effects with...

Usage Arguments

View source: R/cfsens_pac.R

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
cfsens_pac(
  X,
  Y,
  T,
  alpha,
  delta,
  null_type = c("sharp", "negative", "positive"),
  score_type = c("cqr"),
  ps_fun = regression_forest,
  ps = NULL,
  pred_fun = quantile_forest,
  train_prop = 0.75,
  train_id = NULL
)

Arguments

X

covariates.

Y

the observed outcome vector.

T

the vector of treatment assignments.

alpha

the target confidence level.

delta

the confidence level over the randomness over the calibration set.

null_type

the null to be tested that takes value in {"sharp", "negative", "positive"}. See Details.

score_type

the type of nonconformity scores. The default is "cqr".

ps_fun

a function that models the treatment assignment mechanism. The default is "regression_forest".

ps

a vector of propensity score. The default is NULL.

pred_fun

a function that models the potential outcome conditional on the covariates. The default is "quantile_forest".

train_prop

proportion of units used for training. The default is 75\

\item

train_idThe index of the units used for training. The default is NULL.

an itepac object. cfsens_pac conducts sensitivity analysis of individual treatment effects with PAC-type guarantee. It currently supports testing the sharp null and the directional nulls. When null_type = "sharp", the null hypothesis is H_0: Y(1) - Y(0) = 0. When null_type = "negative", the null hypothesis is H_0: Y(1) - Y(0) <= 0. When null_type = "positive", the null hypothesis is H_0: Y(1) - Y(0) >= 0. ## Data generating model data_model <- function(n, p, Gamma, seed){ set.seed(seed) beta <- matrix(c(-0.531,0.126,-0.312,0.018,rep(0,p-4)), nrow=p) X <- matrix(runif(n * p), n, p) U <- rnorm(n) * abs(1 + 0.5 * sin(2.5 * X[,1])) Y1 <- X %*% beta + U Y0 <- X %*% beta - U prop.x <- exp(X %*% beta) / (1 + exp(X %*% beta)) p.x <- 1-(1/(prop.x + (1-prop.x)/Gamma ) -1)/( 1/(prop.x + (1-prop.x)/Gamma) - 1/(prop.x + Gamma*(1-prop.x))) t.x <- qnorm(1-p.x/2) * abs(1+0.5*sin(2.5*X[,1])) prop.xu <- (prop.x/(prop.x+Gamma*(1-prop.x)))*(abs(U)<=t.x) + (prop.x/(prop.x+ (1-prop.x)/Gamma))*(abs(U)>t.x) TT <- rbinom(n, size=1, prob=prop.xu) Y <- TT * Y1 + (1 - TT) * Y0 return(list(Y1 = Y1, Y0 = Y0, Y = Y, X = X, T = TT)) } ## Generate confounded training data n <- 1000 n_test <- 5 p <- 10 Gamma <- 1.5 data <- data_model(n, p, Gamma, 2021) ## Generate confounded test data test <- data_model(n_test, p, Gamma, 2022)

## Run sensitivity analysis with PAC-type guarantee ## grf package needs to be installed alpha <- 0.2 delta <- 0.1 res <- cfsens_pac(data$X, data$Y, data$T, alpha = alpha, delta = delta, null_type = "negative", ps_fun = regression_forest, pred_fun = quantile_forest)

out_res <- predict(res, test$X, Y1_test = test$Y1, type = "att") out_res cfsens_mgn


zhimeir/cfsensitivity documentation built on Feb. 10, 2022, 12:38 a.m.