lsa.linear<-function(x,y){ # adaptive lasso for linear reg, tuning parameter by bic # calls software from Wang and Leng (2007, JASA). ok<-complete.cases(x,y) x<-x[ok,] # get rid of na's y<-y[ok] # since regsubsets can't handle na's m<-ncol(x) n<-nrow(x) as.matrix(x)->x lm(y~x)->out lsa(out)->out.lsa coeff<-out.lsa$beta.bic coeff2<-coeff[2:(m+1)] # get rid of intercept pred<-x%*%coeff2+coeff[1] st<-sum(coeff2 !=0) # number nonzero mse<-sum((y-pred)^2)/(n-st-1) if(st>0) x.ind<-as.vector(which(coeff2 !=0)) else x.ind<-0 return(list(fit=pred,st=st,mse=mse,x.ind=x.ind,coeff=coeff2,intercept=coeff[1])) }