setwd(tempdir())
library(SFSI)
data(wheatHTP)
y = as.vector(Y[,"YLD"]) # Response variable
X = scale(WL) # Predictors
# Training and testing sets
tst = sample(seq_along(y),ceiling(0.3*length(y)))
trn = seq_along(y)[-tst]
# Calculate covariances in training set
XtX = var(X[trn,])
Xty = cov(y[trn],X[trn,])
# Run the penalized regression
fm = lars2(XtX,Xty)
fm = lars2(XtX,Xty,method="LAR-LASSO")
# Predicted values
yHat1 = fitted(fm, X=X[trn,]) # training data
yHat2 = fitted(fm, X=X[tst,]) # testing data
# Penalization vs correlation
par(mfrow=c(1,2))
plot(-log(fm$lambda),cor(y[trn],yHat1)[1,], main="training")
plot(-log(fm$lambda),cor(y[tst],yHat2)[1,], main="testing")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.