Description Usage Arguments Value Examples
View source: R/custom_dispatch.R
Generates custom methods for use in post-double selection based on user specified inputs
1 | custom_helper(X, Y, W, Y.hat.model, W.hat.model)
|
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) |
A list with two elements: The fitted W model and the fitted Y model.
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)))
)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.