View source: R/cfsens_cf_mgn.R
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
X |
covariates. |
Y |
the observed outcome vector. |
T |
the vector of treatment assignments. |
Gamma |
The confounding level. |
alpha |
the target confidence level. |
side |
the type of predictive intervals that takes value in {"two", "above", "below"}. 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 |
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\ \itemtrain_idThe index of the units used for training. The default is |
an cfmgn
object.
cfsens_cf_mgn
constructs robust predictive intervals for
counterfactuals with the margianl guarantee.
When side = "two"
, the predictive interval takes the form a,b;
when side = "above"
, the predictive interval takes the form [a,Inf);
when side = "below"
, the predictive interval takes the form (-Inf,a].
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.
[a,Inf); when qovoxLxpeKT94gPPNEF94jAjl8rrw0hw-3-, the predictive interval takes the form (-Inf,a]: R:a,Inf);%0Awhen%20qovoxLxpeKT94gPPNEF94jAjl8rrw0hw-3-,%20the%20predictive%20interval%20takes%20the%20form%20(-Inf,a ## 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 <- 5000 n_test <- 5000 p <- 10 Gamma <- 1.5 data <- data_model(n, p, Gamma, 2021) ## Generate confounded test data test <- data_model(n_test, p, Gamma, 2022) ## Construct predictive intervals with marginal guarantees ## grf package needs to be installed alpha <- 0.2 res <- cfsens_cf_mgn(data$X, data$Y, data$T, Gamma = Gamma, alpha = alpha, ps_fun = regression_forest, pred_fun = quantile_forest) out_res <- predict(res, test$X, estimand = "treated", type = "ate") cover <- mean((test$Y1 >= out_res$Y_lo) * (test$Y1 <= out_res$Y_hi)) cover
cfsens_cf_pac
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.