# Play with sample size and model structure # I.e, change ns, the model coefficients, the noise error # Run several times to see what happens across simulations ns<-100 xx<-mvrnorm(ns,Sigma=as.matrix(cbind(c(1,.9),c(.9,1))),mu=rep(0,2)) xx<-cbind(xx,mvrnorm(ns,Sigma=as.matrix(cbind(c(1,.9),c(.9,1))),mu=rep(0,2))) xx<-cbind(xx,mvrnorm(ns,Sigma=diag(rep(1,100)),mu=rep(0,100))) # 104 variables y<--1*xx[,1]+1*xx[,3]+1*xx[,4]+xx[,5]+rnorm(ns)*1 df<-as.data.frame(cbind(xx,y)) names(df)<-c(as.character(seq(1,104)),"y") #### library(glmnet) gg<-glmnet(x=xx,y=y) plot(gg,xvar="lambda") cv.gg<-cv.glmnet(x=xx,y=y) plot(cv.gg) names(cv.gg) coef(cv.gg,s="lambda.1se") coef(cv.gg,s="lambda.min") #### adaptive lasso gamma<-1 ggl<-glmnet(x=xx,y=y,lambda=cv.gg$lambda.min) ggr<-glmnet(x=xx,y=y,lambda=cv.gg$lambda.min,alpha=0) xx2<-xx%*%diag(abs(coef(ggr)[-1])^gamma) gg2<-glmnet(x=xx2,y=y,lambda=cv.gg$lambda.min) cc<-coef(gg2)[-1]/coef(ggr)[-1] coef(ggl)[2:10] coef(gg2)[2:10] # try different gamma ######## library(hdi) ll<-lasso.proj(x=xx,y=y) ll$pval ll$pval.corr # are the pvalues identifying the true model? ll<-ridge.proj(x=xx,y=y) ll$pval ll$pval.corr cc<-ll$clusterGroupTest() plot(cc) cc$pval cc$clusters