# get simulation data
n_obs <- 500 # Num of observations
n_var <- 100 # Num of observed variables
n_rel_var <- 4 # Num of relevant variables
data <- HDCATE.get_sim_data(n_obs, n_var, n_rel_var)
# conditional expectation model is misspecified
x_formula <- paste(paste0('X', c(2:n_var)), collapse ='+')
# propensity score model is misspecified
# x_formula <- paste(paste0('X', c(1:(n_var-1))), collapse ='+')
# create a new HDCATE model
model <- HDCATE(data=data, y_name='Y', d_name='D', x_formula=x_formula)
# manually define a lasso method
my_lasso_fit_exp <- function(df) {
hdm::rlasso(as.formula(paste0('Y', "~", x_formula)), df)
}
my_lasso_predict_exp <- function(fitted_model, df) {
predict(fitted_model, df)
}
my_lasso_fit_ps <- function(df) {
hdm::rlassologit(as.formula(paste0('D', "~", x_formula)), df)
}
my_lasso_predict_ps <- function(fitted_model, df) {
predict(fitted_model, df, type="response")
}
# Apply the "my-lasso" apporach to the first stage
HDCATE.set_first_stage(
model,
my_lasso_fit_exp,
my_lasso_fit_exp,
my_lasso_fit_ps,
my_lasso_predict_exp,
my_lasso_predict_exp,
my_lasso_predict_ps
)
Run the code above in your browser using DataLab