# NOT RUN {
# generate data
n <- 50
p <- 3
features <- matrix(rnorm(n*p), ncol = p)
men <- matrix(rbinom(n, 1, 0.5), nrow = n)
outcome <- 2*(features[,1] > 1) + men*pmax(features[,2], 0) + rnorm(n)
outcome <- as.vector(outcome)
#find the optimal intervention using the non-parametric method:
imp_feat <- optint(Y = outcome, X = features, control = men,
method = "non-parametric", lambda = 10, plot = TRUE,
n.boot = 100, n.perm = 100)
#we can explore how the optimal intervention varies between genders using optint_by_group():
men <- as.vector(men)
imp_feat_by_gender <- optint_by_group(Y = outcome, X = features,
group = men,
method = "non-parametric",
lambda = 10)
#by default, only the significant features are displayed
#(see ?plot.optint_by_group for further details).
#for customized variable importance plot, use plot():
plot(imp_feat_by_gender, plot.vars = 3)
# }
Run the code above in your browser using DataLab