Learn R Programming

postDoubleR (version 1.4.12)

custom_helper: Custom generator

Description

Generates custom methods for use in post-double selection based on user specified inputs

Usage

custom_helper(X, Y, W, Y.hat.model, W.hat.model)

Arguments

X

A matrix of covariates

Y

A vector of the target variable, of same length as the number of rows of Y

W

A vector of the treatment variable, of same length as the number of rows of X

Y.hat.model

A function generates a model to predict from. (with a predict method)

W.hat.model

A function generates a model to predict from. (with a predict method)

Value

A list with two elements: The fitted W model and the fitted Y model.

Examples

Run this code
# NOT RUN {

 n = 2000; p = 10
 X = matrix(rnorm(n*p), n, p)
 W = rbinom(n, 1, 0.4 + 0.2 * (X[,1] > 0))
 Y = rbinom(n, 1,( W + 0.1 * (X[,3] > 0) ))
 Y[is.na(Y)] <- 1

Y_est <- function(X,Y){
Y_model <- glm(Y~.,family = binomial,data = as.data.frame(cbind(X,Y)))
}

W_est <- function(X,W){
W_model <- glm(W~.,family = binomial,data = as.data.frame(cbind(X,W)))
}

 custom_helper(X = X, Y = Y, W = W,
                  Y.hat.model = substitute(Y_est),
                  W.hat.model = substitute(W_est))

 custom_helper( X = X, Y = Y, W = W,
                Y.hat.model =
                             expression(
                             glm(Y~.,family = "binomial",data = as.data.frame(cbind(X,Y)))
                             ),
                W.hat.model =
                             expression(
                             glm(W~.,family = "gaussian",data = as.data.frame(cbind(X,Y)))
                             )
              )


# }

Run the code above in your browser using DataLab