Description Usage Arguments Value Examples
Runs cross-validation of LARS regression
1 2 | lars.cross.validation(x, y, nfolds = 10, folds = NULL, verbose = FALSE,
...)
|
x |
A matrix of numeric predictors |
y |
A factor or logical of responses |
nfolds |
number of cross-validation folds (nfolds==-1 means leave-one-out) |
folds |
optional, if not |
verbose |
Use verbose output |
... |
additional parameters for lars |
:
y |
Observed values |
predicted |
CV predicted values |
fractions |
Vector of LASSO fractions used across folds |
best.fraction |
Best LASSO fraction used |
MSE |
Mean squared error |
RMSE |
Root mean squared error |
nfolds |
Number of folds used (or -1 for leave-one-out) |
params |
List of additional parameters, if any |
coefficients |
Feature-by-fold matrix of coefficients of features across folds |
final.model |
Final lars model trained on whole data set |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # generate fake data: 50 samples, 20 variables
x <- matrix(rnorm(2000),100)
rownames(x) <- sprintf('Sample%02d',1:100)
colnames(x) <- sprintf('Feature%02d',1:20)
# generate fake response variable, function of columns 1-5 plus noise
y <- rowSums(sweep(x[,1:5],2,runif(5),'*')) + rnorm(100,sd=.5)
names(y) <- rownames(x)
# 10-fold cross validation with predictions
res.lars <- lars.cross.validation(x,y)
# plot predictions
plot(res.lars$y, res.lars$predicted, xlab="Observed", ylab="Predicted (hold-out)")
# correlation
cat('Pearson correlation of predictions with truth?\n')
print(cor.test(res.lars$y, res.lars$predicted))
# plot fraction of times each variable was included in a fold
sorted.importances <- sort(rowMeans(res.lars$coefficients > 0), decreasing=TRUE)
# bar plot of top ten variables
par(mar=c(4.5,6,2,1),las=2) # larger margin on left, perpendicular axis labels
barplot(rev(sorted.importances[1:10]),horiz=TRUE, xlab='Frequency of selection')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.