Learn R Programming

CDLasso (version 1.1)

cv.logit.reg: k-fold Cross Validation

Description

k-fold Cross Validation to find optimal lambda for Cyclic Coordinate Descent for logistic regression

Usage

cv.logit.reg(x, y, k, lam.vec)

Arguments

x
p x n design matrix - Note that the rows of X correspond to predictors and the columns to cases.
y
Outcome of length n. Outcome must be 0 and 1.
k
Number of folds for k-fold cross validation
lam.vec
Vector of penalization parameters

Value

k
The value of K used for the K-fold cross validation.
lam.vec
The values of lambda tested.
lam.opt
The determined lambda value among lam.vec that returns the smallest prediction error. This value is the optimal lambda value for use in logit.reg.
error.cv
The prediction error matrix returned by cross validation method.
num.pred
The number of selected predictors when using the corresponding lambda value.

Details

K-fold cross validation to select optimal lambda for use in cyclic coordinate descent for logistic regression logit.reg. The optimal value is considered the lambda value that retuns the lowest testing error over the cross validation. If more than one lambda value give the minumum testing error, the largest lambda is selected. Plot of the cross validation can be viewed through plot.cv.logit.reg

References

Wu, T.T., Chen, Y.F., Hastie, T., Sobel E. and Lange, K. (2009). Genome-wide association analysis by lasso penalized logistic regression. Bioinformatics, Volume 25, No 6, 714-721.

See Also

logit.reg

plot.cv.logit.reg

Examples

Run this code
set.seed(1001)
n=250;p=50
beta=c(1,1,1,1,1,rep(0,p-5))
x=matrix(rnorm(n*p),p,n)
xb = t(x) %*% beta
logity=exp(xb)/(1+exp(xb))
y=rbinom(n=length(logity),prob=logity,size=1)

rownames(x)<-1:nrow(x)
colnames(x)<-1:ncol(x)
lam.vec = (0:15)*2

#K-fold cross validation
cv <- cv.logit.reg(x,y,5,lam.vec)
plot(cv)
cv

#Lasso penalized logistic regression using optimal lambda
out<-logit.reg(x,y,cv$lam.opt)

#Re-estimate parameters without penalization
out2<-logit.reg(x[out$selected,],y,0)
out2

Run the code above in your browser using DataLab