Description Usage Arguments Value Examples
View source: R/final.selection.R
Returns the index of final selected variables in the final chosen model.
1 | final.selection(cv.fit, pihat, p, cov.num = 0)
|
cv.fit |
An object of either class "cv.glmnet" from glmnet::cv.glmnet() or class "cv.ncvreg" from ncvreg::cv.ncvreg(), which is a list generated by a cross-validation fit. |
pihat |
eatimated proprtion from HCTR::est.prop(). |
p |
Total number of variables, except for covariates. |
cov.num |
Number of covariates in model, default is 0. Covariate matrix, W, is assumed on the left side of variable matrix, X. The column index of covariates are before those of variables. |
A sequence of index of final selected variables in the final chosen model.
1 2 3 4 5 6 7 8 9 10 11 12 | set.seed(10)
X <- matrix(rnorm(20000), nrow = 100)
beta <- rep(0, 200)
beta[1:100] <- 5
Y <- MASS::mvrnorm(n = 1, mu = X%*%beta, Sigma = diag(100))
fit <- glmnet::cv.glmnet(x = X, y = Y)
pihat <- 0.01
result <- est.lambda(cv.fit = fit, pihat = pihat, p = ncol(X))
lambda.seq <- seq(from = result$lambda.min, to = result$lambda.max, length.out = 100)
# Note: The lambda sequences in glmnet and ncvreg are diffrent.
fit2 <- glmnet::cv.glmnet(x = X, y = Y, lambda = lambda.seq)
result2 <- final.selection(cv.fit = fit2, pihat = 0.01, p = ncol(X))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.