cv.plasso {plasso} | R Documentation |
Cross-Validated Lasso and Post-Lasso
Description
cv.plasso
uses the glmnet
package to estimate the coefficient paths and cross-validates least squares Lasso AND Post-Lasso.
Usage
cv.plasso(x, y, w = NULL, kf = 10, parallel = FALSE, ...)
Arguments
x |
Matrix of covariates (number of observations times number of covariates matrix) |
y |
Vector of outcomes |
w |
Vector of weights |
kf |
Number of folds in k-fold cross-validation |
parallel |
Set as TRUE for parallelized cross-validation. Default is FALSE. |
... |
Pass |
Value
cv.plasso object (using a list structure) including the base glmnet
object and cross-validation results (incl. optimal Lambda values) for both Lasso and Post-Lasso model.
call |
the call that produced this |
lasso_full |
base |
kf |
number of folds in k-fold cross-validation |
cv_MSE_lasso |
cross-validated MSEs of Lasso model (for every iteration of k-fold cross-validation) |
cv_MSE_plasso |
cross-validated MSEs of Post-Lasso model (for every iteration of k-fold cross-validation) |
mean_MSE_lasso |
averaged cross-validated MSEs of Lasso model |
mean_MSE_plasso |
averaged cross-validated MSEs of Post-Lasso model |
ind_min_l |
index of MSE optimal lambda value for Lasso model |
ind_min_pl |
index of MSE optimal lambda value for Post-Lasso model |
lambda_min_l |
MSE optimal lambda value for Lasso model |
lambda_min_pl |
MSE optimal lambda value for Post-Lasso model |
names_l |
Names of active variables for MSE optimal Lasso model |
names_pl |
Names of active variables for MSE optimal Post-Lasso model |
coef_min_l |
Coefficients for MSE optimal Lasso model |
coef_min_pl |
Coefficients for MSE optimal Post-Lasso model |
x |
Input matrix of covariates |
y |
Matrix of outcomes |
w |
Matrix of weights |
Examples
# load toeplitz data
data(toeplitz)
# extract target and features from data
y = as.matrix(toeplitz[,1])
X = toeplitz[,-1]
# fit cv.plasso to the data
p.cv = plasso::cv.plasso(X,y)
# get basic summary statistics
print(summary(p.cv, default=FALSE))
# plot cross-validated MSE curves and number of active coefficients
plot(p.cv, legend_pos="bottomleft")
# get coefficients at MSE optimal lambda value for both Lasso and Post-Lasso model
coef(p.cv)
# get coefficients at MSE optimal lambda value according to 1-standard-error rule
coef(p.cv, se_rule=-1)
# predict fitted values along whole lambda sequence
pred = predict(p.cv, s="all")
head(pred$plasso)