############################################################ ### plot Ridge and Lasso thresholding ############################################################ dpl=TRUE ST = function(x,lam) { r = abs(x)-lam r = ifelse(r>0,r,0) sx = ifelse(x>0,1,-1) return(sx*r) } if(dpl) pdf(file="RLsimp.pdf",height=10,width=12) yv = seq(from=-3,to=3,length.out=100) lam=.5 plot(yv,yv,xlab="y",ylab="estimate",type="l",cex.axis=1.5,lty=2,cex.lab=1.5) lines(yv,yv/(1+lam),col="red",lwd=2) lines(yv,ST(yv,lam),col="blue",lwd=2) abline(h=0,lty=3) abline(v=0,lty=3) legend("topleft",legend=c("Lasso","Ridge"),col=c("blue","red"),lty=c(1,1), lwd=c(2,2)) title(main="lambda = .5") if(dpl) dev.off() ################################################## if(dpl) rm(list=ls())