Description Usage Arguments Value Examples
View source: R/mmscaHyperCubeSelection.R
A function that performs model selection for the regularizers of mmsca(). This function tunes a grid of the tuning parameters determine by the min and max of their corresponding sequences and a step size the provided by stepsize
argument. It picks out the best combination, and zooms in on that combination, by making a new smaller grid around the previous best combination. This process continues until the average range of the sequences is less than stopWhenRange
. The new sequences are determined by taking the minimum value to be: best value - range, and maximum value by: best value + range, and a pre-specified step size in stepsize
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | mmscaHyperCubeSelection(
X,
ncomp,
ridgeSeq,
lassoSeq,
grouplassoSeq,
elitistlassoSeq,
stepsize,
logscale = FALSE,
stopWhenRange = 0.05,
groups,
nrFolds = NULL,
nStart,
itr = 1e+06,
printProgress = TRUE,
coorDes = TRUE,
coorDesItr = 1,
tol = 1e-07,
method = "BIC"
)
|
X |
A data matrix of class |
ridgeSeq |
A range of values for the ridge penalty that need to be examined. Specify a zero if the tuning parameter is not wanted. |
lassoSeq |
A range of values for the lasso penalty that need to be examined. Specify a zero if the tuning parameter is not wanted. |
grouplassoSeq |
A range of values for the group lasso penalty that need to be examined. Specify a zero if the tuning parameter is not wanted. |
elitistlassoSeq |
A range of values for the elitist lasso penalty that need to be examined. Specify a zero if the tuning parameter is not wanted. |
stepsize |
The sequences of ridgeSeq, lassoSeq, grouplassoSeq, and elitistlassoSeq are constructed by |
logscale |
determines whether the sequences are on the log-scale or not. By default it is set to |
stopWhenRange |
A numeric value with default 0.05. If the average range of the tuning sequences is less than this value the algorithm stops. |
groups |
A vector specifying which columns of X belong to what block. Example: |
nStart |
The number of random starts the analysis should perform. The first start will be a warm start, W will be started with the first Q right singular vectors of X. You can not give custom starting values. |
itr |
The maximum number of iterations of |
printProgress |
A boolean with default TRUE. If set to |
coorDes |
A boolean with the default |
coorDesItr |
An integer specifying the maximum number of iterations for the coordinate descent algorithm, the default is set to 1. You do not have to run this algorithm until convergence before alternating back to the estimation of the loadings. The tolerance for this algorithm is hardcoded and set to |
tol |
A numeric value specifying the tolerance of mmsca(), it determine when the algorithm is converged (|current loss - previous loss| < tol), by default it is set to |
method |
A string indicating which model selection method should be used. "BIC" enables the Bayesian information criterion, "IS" enables the index of sparseness. "CV" enables cross-validation (CV) with the EigenVector method, "CV1stdError" enables CV with the one standard error rule, this will pick the combination of tuning parameters that leads to the most sparse model, still within one standard error of the best model, if "CV" or "CV1stdError" is used, the number of folds |
nrFold |
An integer that specify the number of folds that Cross-validation should use if tuningmethod == "CV", the number of folds needs to be lower then |
A list containing:
ridge
A vector with ncomp
elements all equal to the chosen ridge value
lasso
A vector with ncomp
elements all equal to the chosen lasso value
grouplasso
A vector with ncomp
elements all equal to the chosen group lasso value
elitistlasso
A vector with ncomp
elements all equal to the chosen elitist lasso value
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 37 38 39 40 41 42 43 44 45 46 |
# Example select the lasso and ridge parameter for mmsca()
# create sample data
ncomp <- 3
J <- 30
comdis <- matrix(1, J, ncomp)
comdis <- sparsify(comdis, 0.5) #set 50 percent of the 1's to zero
variances <- makeVariance(varianceOfComps = c(100, 80, 90), J = J, error = 0.05) #create realistic eigenvalues
dat <- makeDat(n = 100, comdis = comdis, variances = variances)
X <- dat$X
#Note: can take some time
results <- mmscaHyperCubeSelection(X,
ncomp = 3,
ridgeSeq = 0:3,
lassoSeq = 0:10,
grouplassoSeq = 0,
elitistlassoSeq = 0,
stepsize = 5,
logscale = FALSE,
groups = ncol(X),
nStart = 1,
itr = 100000,
printProgress = TRUE,
coorDes = FALSE,
coorDesItr = 1,
method = "CV1stdError",
tol = 10e-5,
nrFolds = 10)
#fit the model with the selected hyper parameters
fit <- mmsca(X = X,
ncomp = ncomp,
ridge = results$ridge,
lasso = results$lasso,
grouplasso = results$grouplasso,
elitistlasso = results$elitistlasso,
groups = ncol(X),
constraints = matrix(1, J, ncomp),
itr = 1000000,
Wstart = matrix(0, J, ncomp))
#inspect the results
fit$W
dat$P[, 1:ncomp]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.