custom_helper: Custom generator

Description Usage Arguments Value Examples

View source: R/custom_dispatch.R

Description

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

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 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)))
                             )
              )

postDoubleR documentation built on Oct. 7, 2019, 5:05 p.m.