GenericML_combine | R Documentation |
This function combines multiple "GenericML"
objects into one "GenericML"
object. Combining several "GenericML"
objects can be useful when you cannot run GenericML()
for sufficiently many splits due to memory constraints. In this case, you may run GenericML()
multiple times with only a small number of sample splits each and combine the returned "GenericML"
objects into one GenericML
object with this function.
GenericML_combine(x)
x |
A list of |
To ensure consistency of the estimates, all "GenericML"
objects in the list x
must have the exact same parameter specifications in their original call to GenericML()
, except for the parameters num_splits
, parallel
, num_cores
, seed
, and store_learners
(i.e. these arguments may vary between the "GenericML"
objects in the list x
). An error will be thrown if this is not satisfied.
A"GenericML"
object as returned by GenericML()
. In the arguments
component of this object, the objects parallel
, num_cores
, seed
, and store_learners
are set to NULL
as these might differ between the individual GenericML
objects in x
. Moreover, the propensity_scores
component of the returned object is taken from the first "GenericML"
object in x
.
GenericML()
if (require("glmnet") && require("ranger")) { ## generate data set.seed(1) n <- 150 # number of observations p <- 5 # number of covariates D <- rbinom(n, 1, 0.5) # random treatment assignment Z <- matrix(runif(n*p), n, p) # design matrix Y0 <- as.numeric(Z %*% rexp(p) + rnorm(n)) # potential outcome without treatment Y1 <- 2 + Y0 # potential outcome under treatment Y <- ifelse(D == 1, Y1, Y0) # observed outcome ## column names of Z colnames(Z) <- paste0("V", 1:p) ## specify learners learners <- c("lasso", "mlr3::lrn('ranger', num.trees = 10)") ## glmnet v4.1.3 isn't supported on Solaris, so skip Lasso in this case if(Sys.info()["sysname"] == "SunOS") learners <- learners[-1] ## call GenericML three times and store the returned objects in a list x x <- lapply(1:3, function(...) GenericML(Z, D, Y, learners, num_splits = 2, parallel = FALSE)) ## combine the objects in x into one GenericML object genML <- GenericML_combine(x) ## you can use all methods of GenericML objects on the combined object, for instance accessors: get_BLP(genML, plot = TRUE) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.