|
a |
|
b/6-lasso.R |
|
|
1 |
rm(list=ls()) |
|
|
2 |
library(tibble) |
|
|
3 |
library(dplyr) |
|
|
4 |
library(glmnet) |
|
|
5 |
library(lars) |
|
|
6 |
library(VennDiagram) |
|
|
7 |
library(sigFeature) |
|
|
8 |
library(e1071) |
|
|
9 |
library(caret) |
|
|
10 |
library(randomForest) |
|
|
11 |
library(ltm) |
|
|
12 |
#UMN_DMP_new:dmp lasso |
|
|
13 |
{ |
|
|
14 |
setwd("E:\\workplace\\mywork\\methy\\dbgap\\chf\\data_chf_contr\\early_chf\\c1_UMN_JHU\\train_UMN_tset_JHU/1123_dataSummary") |
|
|
15 |
load("UMN_DMP_new.Rdata") |
|
|
16 |
X <- as.matrix(UMN_DMP_new[,!colnames(UMN_DMP_new) %in% c("chf","cvd")]) #chf |
|
|
17 |
y <- as.character(UMN_DMP_new$chf) |
|
|
18 |
set.seed(2) |
|
|
19 |
fitCV <- cv.glmnet(X, y, family = "binomial", type.measure = "auc", nfolds = 10) |
|
|
20 |
#lambda.min |
|
|
21 |
myCoefs <- coef(fitCV, s = "lambda.min") |
|
|
22 |
lasso_fea <- myCoefs@Dimnames[[1]][which(myCoefs[,1] != 0 )] |
|
|
23 |
lasso_fea <- data.frame(lasso_fea) |
|
|
24 |
lasso_fea$x <- myCoefs@x |
|
|
25 |
lasso_fea <- lasso_fea[-1,] |
|
|
26 |
length(lasso_fea[,1])#103 |
|
|
27 |
|
|
|
28 |
#lambda.1se |
|
|
29 |
myCoefs2 <- coef(fitCV, s="lambda.1se") |
|
|
30 |
#lambda.1se |
|
|
31 |
lasso_fea2 <- myCoefs2@Dimnames[[1]][which(myCoefs2[,1] != 0 )] |
|
|
32 |
lasso_fea2 <- data.frame(lasso_fea2) |
|
|
33 |
lasso_fea2$x <- myCoefs2@x |
|
|
34 |
lasso_fea2 <- lasso_fea2[-1,] |
|
|
35 |
length(lasso_fea2[,1])#91 |
|
|
36 |
|
|
|
37 |
set.seed(2) |
|
|
38 |
cv_fit <- cv.glmnet(X, y, nfold=10, alpha = 1, family = "binomial", type.measure = "class") |
|
|
39 |
myCoefs3 <- coef(cv_fit, s="lambda.min") |
|
|
40 |
#lambda.min |
|
|
41 |
lasso_fea3 <- myCoefs3@Dimnames[[1]][which(myCoefs3[,1] != 0 )] |
|
|
42 |
lasso_fea3 <- data.frame(lasso_fea3) |
|
|
43 |
lasso_fea3$x <- myCoefs3@x |
|
|
44 |
lasso_fea3 <- lasso_fea3[-1,] |
|
|
45 |
length(lasso_fea3[,1])#104 |
|
|
46 |
|
|
|
47 |
#2 |
|
|
48 |
myCoefs4 <- coef(cv_fit, s="lambda.1se") |
|
|
49 |
#lambda.1se |
|
|
50 |
lasso_fea4 <- myCoefs4@Dimnames[[1]][which(myCoefs4[,1] != 0 )] |
|
|
51 |
lasso_fea4 <- data.frame(lasso_fea4) |
|
|
52 |
lasso_fea4$x <- myCoefs4@x |
|
|
53 |
lasso_fea4 <- lasso_fea4[-1,] |
|
|
54 |
length(lasso_fea4[,1])#92 |
|
|
55 |
|
|
|
56 |
require("VennDiagram") |
|
|
57 |
#VENN.LIST=list(lasso2_lambda1se=lasso_fea4$lasso_fea4,lasso2_lambdamin=lasso_fea3$lasso_fea3,lasso1_lambda1se=lasso_fea2$lasso_fea2,lasso1_lambdamin=lasso_fea$lasso_fea) |
|
|
58 |
VENN.LIST=list(B_lambda1se=lasso_fea4$lasso_fea4,B_lambdamin=lasso_fea3$lasso_fea3,A_lambda1se=lasso_fea2$lasso_fea2,A_lambdamin=lasso_fea$lasso_fea) |
|
|
59 |
venn.plot <- venn.diagram(VENN.LIST , NULL, |
|
|
60 |
fill=c("darkmagenta", "darkblue","red","black"), |
|
|
61 |
alpha=c(0.5,0.5,0.5,0.5), cex = 2, |
|
|
62 |
cat.fontface="plain", cat.cex = 1.5, |
|
|
63 |
main="Overlap of measure in 1se and min ") |
|
|
64 |
grid.draw(venn.plot) |
|
|
65 |
venn4=intersect(intersect(intersect(lasso_fea$lasso_fea,lasso_fea3$lasso_fea3),lasso_fea4$lasso_fea4),lasso_fea2$lasso_fea2) |
|
|
66 |
venn3=union(union(union(lasso_fea$lasso_fea,lasso_fea3$lasso_fea3),lasso_fea4$lasso_fea4),lasso_fea2$lasso_fea2) |
|
|
67 |
setwd("E:\\workplace\\mywork\\methy\\dbgap\\chf\\data_chf_contr\\early_chf\\c1_UMN_JHU\\train_UMN_tset_JHU/1123_dataSummary") |
|
|
68 |
write.csv(venn4,'lasso_dmp_little.csv', row.names = F) |
|
|
69 |
write.csv(venn3,'lasso_dmp_large.csv', row.names = F) |
|
|
70 |
{ |
|
|
71 |
library(UpSetR) |
|
|
72 |
B_lambda1se=lasso_fea4$lasso_fea4 |
|
|
73 |
B_lambdamin=lasso_fea3$lasso_fea3 |
|
|
74 |
A_lambda1se=lasso_fea2$lasso_fea2 |
|
|
75 |
A_lambdamin=lasso_fea$lasso_fea |
|
|
76 |
input <- fromList(list(A_lambdamin=lasso_fea$lasso_fea, |
|
|
77 |
A_lambda1se=lasso_fea2$lasso_fea2, |
|
|
78 |
B_lambdamin=lasso_fea3$lasso_fea3, |
|
|
79 |
B_lambda1se=lasso_fea4$lasso_fea4)) |
|
|
80 |
upset(input, order.by = "freq",nsets = 7,point.size = 3) |
|
|
81 |
} |
|
|
82 |
} |