| wElnet | R Documentation |
A model selection function fitting Elastic Net (linear or logistic) models with sampling weights
by a replicating weights method to select an optimal lambda for a given alpha by weighted error minimization.
This is extended from wlasso::wlasso(), which is now officially available in wlasso. For an extended
model selection for a sequence of alpha's by CPU parallel computing, use par_wElnet().
wElnet(
data = NULL,
col.y = NULL,
col.x = NULL,
cluster = NULL,
strata = NULL,
weights = NULL,
design = NULL,
family = c("gaussian", "binomial"),
lambda = NULL,
alpha = 1,
nlambda = 100,
lambda.min.ratio = NULL,
method = c("dCV", "JKn", "bootstrap", "subbootstrap", "BRR", "split", "extrapolation"),
k = 10,
R = 1,
B = 200,
dCV.sw.test = FALSE,
train.prob = 0.7,
method.split = c("dCV", "bootstrap", "subbootstrap"),
print.rw = FALSE,
standardize = TRUE,
offset = NULL,
...
)
data |
A data frame with information about the response variable and covariates, as well as sampling weights, strata, and cluster indicators. It could be |
col.y |
A numeric value indicating the index of the response variable or a string of the response variable name . |
col.x |
A numeric vector indicating indices of covariates or a vector of strings indicating these column names. |
cluster |
A string of a cluster identifier. It could be |
strata |
A string of a strata identifier. It could be |
weights |
A string of a sampling weights' identifier. It could be |
design |
An object of class |
family |
A string indicating a |
lambda |
A sequence of lambda supplied by a user. |
alpha |
A numeric value of the elastic net mixing parameter
where |
nlambda |
An integer. The number of lambda grids to be generated. Default is |
lambda.min.ratio |
The smallest value for |
method |
A string indicating a method of replicate weights. Choose one of these: |
k |
An integer. The number of folds for the |
R |
An integer. The number of times the sample is partitioned for |
B |
An integer. The number of bootstrap re-samples for |
dCV.sw.test |
A logical value indicating the method for estimating the error for |
train.prob |
A numeric between 0 and 1 that sets the proportion of clusters (for the method |
method.split |
A string of one the following replicate weights methods to be implemented under the |
print.rw |
A logical value. If |
standardize, offset, ... |
Optional parameters to be passed to the low level function |
The output object of the function wElnet() is an object of class w.elnet:
lambda: A list containing information of two elements:
grid: A vector of all grid values for the tuning parameter.
min: A numeric value of an optimal tuning parameter minimizing the average error.
error: A list containing information of two elements:
average: A numeric vector indicating the average error for each tuning parameter in lambda$grid.
all: A numeric matrix indicating the error of each test set for each tuning parameter.
alpha: A numeric value of the elastic net mixing parameter used to fit this model (as supplied to the alpha argument).
model: A list containing information of two elements in relation to the fitted models.
grid: A list containing information on models fitted by each tuning parameter in the lambda$grid.
a0: A numeric vector of model intercepts across the whole grid of tuning parameters (hence, of the same length as lambda$grid).
beta: A matrix of regression coefficients for all the covariates across the whole grid of tuning parameters (the dimension of the matrix is the size of covariates by the length of lambda$grid).
df: A numeric vector of the degrees of freedom (i.e., the number of coefficients different from zero) across the whole grid of tuning parameters (hence, of the same length as lambda$grid).
final_model: An object with S3 class glmnet found in r-glmnet. A list containing information on the final model fitted by the optimal tuning parameter, lambda$min.
i.e., the optimal tuning parameter selected from lambda$grid.
data.rw: A data frame containing the original data set and the replicate weights added to define training and test sets. Only included in the output object if print.rw=TRUE.
call: The call that executes this function producing the object of w.elnet.
Note that both model and final_model are fitted by the original data, not by one of the generated training sets by replicate weights.
svyVarSel::wlasso() for detailed arguments.
glmnet::glmnet() for detailed arguments and return values.
data(nhanes2013_sbc)
# alpha can be selected based on `glmnet::glmnet()`:
alpha <- c(0.000, 0.001, 0.008, 0.027, 0.064, 0.125, 0.216, 0.343, 0.512, 0.729, 1.000)
en.dcv <- wElnet(data = nhanes2013_sbc,
col.y = "HBP", col.x = 2:61,
family = "binomial", alpha = 0.729,
cluster = "SDMVPSU", strata = "SDMVSTRA", weights = "WTSAF2YR",
method = "dCV", k=10, R=20)
# Or equivalently:
des <- survey::svydesign(ids=~SDMVPSU, strata = ~SDMVSTRA, weights = ~WTSAF2YR,
nest = TRUE, data = nhanes2013_sbc)
en.dcv <- wElnet(col.y = "HBP", col.x = 2:61, design = des,
family = "binomial", alpha = alpha[10],
method = "dCV", k=10, R=20)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.