Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/CV.twostageSL.R
Function to get V-fold cross-validated risk estimate for two stage super learner. This function simply splits the data into V folds and then calls twostageSL. Most of the arguments are passed directly to twostageSL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | CV.twostageSL(
Y,
X,
V = NULL,
family.1 = binomial,
family.2 = gaussian,
family.single = gaussian,
library.2stage,
library.1stage,
twostage,
method = "method.CC_LS.scale",
id = NULL,
verbose = FALSE,
control = list(saveFitLibrary = FALSE),
cvControl = list(),
innerCvControl = list(),
obsWeights = NULL,
saveAll = TRUE,
parallel = "seq",
env = parent.frame()
)
|
Y |
The outcome. |
X |
The covariates. |
V |
The number of folds for |
family.1 |
Error distribution of the stage 1 outcome for two-stage super learner. Currently only allows |
family.2 |
Error distribution of the stage 2 outcome for two-stage super learner. Currently only allows |
family.single |
Error distribution of the outcome for standard super learner. Currently only allows |
library.2stage |
Candidate prediction algorithms in two-stage super learner. A list containing prediction algorithms at stage 1 and stage 2, the prediction algorithms are either a character vector or a list containing character vectors. See details below for examples on the structure. A list of functions included in the SuperLearner package can be found with |
library.1stage |
Candidate prediction algorithms in standard super learner. Either a character vector of prediction algorithms or a list containing character vectors. See details below for examples on the structure. A list of functions included in the SuperLearner package can be found with |
twostage |
logical; TRUE for implementing two-stage super learner; FALSE for implementing standatd super learner |
method |
Details on estimating the coefficients for the two-stage super learner and the model to combine the individual algorithms in the library. Currently, the built in option is only "method.CC_LS.scale" (default) which is a scaled version of CC_LS. CC_LS.scale uses Goldfarb and Idnani's quadratic programming algorithm to calculate the best convex combination of weights to minimize the squared error loss. In addition, CC_LS.scale divides the quadratic function by a large constant to shrink the huge matrix and vector in quadratic function. |
id |
Optional cluster identification variable. For the cross-validation splits, |
verbose |
logical; TRUE for printing progress during the computation (helpful for debugging). |
control |
A list of parameters to control the estimation process. Parameters include |
cvControl |
A list of parameters to control the cross-validation process. The outer cross-validation is the sample spliting for evaluating the |
innerCvControl |
A list of lists of parameters to control the inner cross-validation process. It should have |
obsWeights |
Optional observation weights variable. As with |
saveAll |
Logical; Should the entire |
parallel |
Options for parallel computation of the V-fold step. Use "seq" (the default) for sequential computation. |
env |
Environment containing the learner functions. Defaults to the calling environment. |
The twostageSL
function builds a estimator, but does not contain an estimate on the performance of the estimator. Various methods exist for estimator performance evaluation. If you are familiar with the super learner algorithm, it should be no surprise we recommend using cross-validation to evaluate the honest performance of the two stage super learner estimator. The function CV.twostageSL
computes the usual V-fold cross-validated risk estimate for the two stage super learner (and all algorithms in library.2stage
and library.1stage
for comparison).
An object of class CV.twostageSL
(a list) with components:
call |
The matched call. |
AllSL |
If |
SL.predict |
The predicted values from the two stage super learner when each particular row was part of the validation fold. |
discreteSL.predict |
The traditional cross-validated selector. Picks the algorithm with the smallest cross-validated risk (in super learner terms, gives that algorithm coefficient 1 and all others 0). |
whichDiscreteSL |
A list of length |
library.predict |
A matrix with the predicted values from each algorithm in |
coef |
A matrix with the coefficients for the two stage super learner on each fold. The columns are the algorithms in |
folds |
A list containing the row numbers for each validation fold. |
V |
Number of folds for |
number0 |
A dataframe indicating the number of zeros in each of the |
libraryNames |
A character vector with the names of the algorithms in the library. The format is 'predictionAlgorithm_screeningAlgorithm' with '_All' used to denote the prediction algorithm run on all variables in X. |
SL.library |
Returns the prediction algorithms and screening algorithms in |
method |
A list with the method functions. |
Y |
The outcome. |
Ziyue Wu
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 29 30 31 32 33 34 35 36 | ## simulate data
set.seed(12321)
## training set
n <- 10000
p <- 5
X <- matrix(rnorm(n*p), nrow = n, ncol = p)
colnames(X) <- paste("X", 1:p, sep="")
X <- data.frame(X)
Y <- rep(NA,n)
## probability of outcome being zero
prob <- plogis(1 + X[,1] + X[,2] + X[,1]*X[,2])
g <- rbinom(n,1,prob)
## assign zero outcome
ind <- g==0
Y[ind] <- 0
## assign non-zero outcome
ind <- g==1
Y[ind] <- 10 + X[ind, 1] + sqrt(abs(X[ind, 2] * X[ind, 3])) + X[ind, 2] - X[ind, 3] + rnorm(sum(ind))
## run the CV.twostageSL
cv_sl <- CV.twostageSL(
Y = Y, X = X,
family.1 = binomial,
family.2 = gaussian,
family.single = gaussian,
library.2stage = list(stage1=c("SL.glm","SL.mean","SL.earth"),
stage2=c("SL.glm","SL.mean","SL.earth")),
library.1stage = c("SL.glm","SL.mean","SL.earth"),
cvControl = list(V = 2),
innerCvControl = list(list(V = 5),
list(V = 5))
)
cv_sl$AllSL
cv_sl$whichDiscreteSL
plot(cv_sl)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.