Predicted values for a provided matrix of predictors X
# S3 method for LASSO
coef(object, ..., i=NULL)# S3 method for LASSO
fitted(object, ...)
Method coef
returns a matrix that contains, for each value of lambda (in columns), the predicted values corresponding to each row of the matrix X
.
Method fitted
returns fitted values
Xβ
An object of the class 'LASSO' returned either by the function 'LARS' or 'solveEN'
Other arguments: X
(numeric matrix) scores for as many predictors there are in ncol(object$beta)
(in columns) for a desired number n
of observations (in rows)
(integer vector) Index columns of matrix 'Gamma' to be considered
Marco Lopez-Cruz (maraloc@gmail.com) and Gustavo de los Campos
require(SFSI)
data(wheatHTP)
y = as.vector(Y[,"E1"]) # Response variable
X = scale(X_E1) # Predictors
# Training and testing sets
tst = which(Y$trial %in% 1:10)
trn = seq_along(y)[-tst]
# Calculate covariances in training set
XtX = var(X[trn,])
Xty = cov(X[trn,],y[trn])
# Run the penalized regression
fm = solveEN(XtX,Xty,alpha=0.5)
# Regression coefficients
B = coef(fm)
# Predicted values
yHat1 = fitted(fm, X=X[trn,]) # training data
yHat2 = fitted(fm, X=X[tst,]) # testing data
# Penalization vs correlation
plot(-log(fm$lambda[-1]),cor(y[trn],yHat1[,-1]), main="training")
plot(-log(fm$lambda[-1]),cor(y[tst],yHat2[,-1]), main="testing")
Run the code above in your browser using DataLab