| par_wElnet | R Documentation |
Fits wElnet() once per value of alpha, assigning each
alpha to its own CPU core via the parallel package, and
then selects the overall best (alpha, lambda) combination by
minimizing the average weighted error across all fits.
This function always uses a \code{"PSOCK"} cluster, on every
platform (Windows, Mac, Linux), because it is designed to run
safely inside RStudio. RStudio manages a graphics device and
other GUI state in the main R process; forking that process
(\code{"FORK"} clusters) is explicitly discouraged by R's own
\code{parallel} documentation in GUI-based sessions and can
crash the session. \code{"PSOCK"} workers are fresh, independent
R processes, so this risk does not apply, at the cost of a
small amount of serialization overhead when the cluster starts.
Because this function is part of the \code{MLSurvey} package,
each worker simply attaches \code{MLSurvey} (along with
\code{glmnet} and \code{survey}) via \code{library()}, which
makes [wElnet()], [replicate_weights()], and all of their
internal helper functions available on every worker
automatically -- no manual \code{clusterExport()} of function
definitions is required.
par_wElnet(
alpha = c(0, 0.001, 0.008, 0.027, 0.064, 0.125, 0.216, 0.343, 0.512, 0.729, 1),
n.cores = NULL,
blas.threads = 1,
data = NULL,
col.y = NULL,
col.x = NULL,
cluster = NULL,
strata = NULL,
weights = NULL,
design = NULL,
family = c("gaussian", "binomial"),
lambda = NULL,
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,
...
)
alpha |
A numeric vector of elastic net mixing parameters to evaluate
in parallel, one per core. Default is the standard 11-point
grid |
n.cores |
Integer number of CPU cores to use. Defaults to
|
blas.threads |
Integer number of threads each worker's BLAS library is
allowed to use. Defaults to |
data |
A data frame with information about the response variable and covariates,
as well as sampling weights, strata, and cluster indicators. Passed to
|
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. If |
nlambda |
An integer. The number of lambda grid values to generate when
|
lambda.min.ratio |
The smallest value for |
method |
A string indicating a method of replicate weights. Choose one of:
|
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
the |
train.prob |
A numeric between 0 and 1 setting the proportion of clusters (for
|
method.split |
A string indicating which replicate weights method to use under
the |
print.rw |
A logical value. If |
standardize |
A logical value passed to |
offset |
An optional offset vector passed to |
... |
Any further arguments accepted by |
An object of class par.w.elnet, a list with:
results: a named list of w.elnet objects (the output of wElnet()), one per alpha.
summary: a data frame with columns alpha, lambda.min, and min.error,
one row per alpha, sorted in the order alpha was supplied.
best: the single w.elnet object with the lowest min.error across all alphas.
best.alpha: the alpha value corresponding to best.
wElnet() for the single-alpha model fit that this function parallelizes.
library(MLSurvey)
data(nhanes2013_sbc)
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.par <- par_wElnet(alpha = alpha,
data = nhanes2013_sbc,
col.y = "HBP", col.x = 2:61,
family = "binomial",
cluster = "SDMVPSU", strata = "SDMVSTRA", weights = "WTSAF2YR",
method = "dCV", k = 10, R = 20)
en.par$summary # error per alpha
en.par$best.alpha # winning alpha
en.par$best # winning w.elnet object (same structure as wElnet() output)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.