install.packages(“glmnet”)
library(glmnet)
library(survival)
setwd(“C:\Users\TD\Desktop”)
inputfile=“id0.05exp.txt”
lncRNA<-read.table(inputfile,header=T,sep="\t",row.names = 1,check.names = F,stringsAsFactors = F)
set.seed(123456)
v1<-as.matrix(lncRNA[,c(3:ncol(lncRNA))])
v2 <- as.matrix(Surv(lncRNA
S
u
r
v
i
v
a
l
m
o
n
t
h
s
,
l
n
c
R
N
A
Survival_months,lncRNA
Survivalmonths,lncRNASurvival_status))
myfit2 <- cv.glmnet(v1, v2, family=“cox”)
#pdf(“min.pdf”) #将图片写入到pdf中
plot(myfit2)
abline(v=log(c(myfit2
l
a
m
b
d
a
.
m
i
n
,
m
y
f
i
t
2
lambda.min,myfit2
lambda.min,myfit2lambda.1se)),lty=“dashed”)
#dev.off() # 关闭图片,图片保存到pdf中
myfit2
l
a
m
b
d
a
.
m
i
n
m
y
f
i
t
<
−
g
l
m
n
e
t
(
v
1
,
v
2
,
f
a
m
i
l
y
=
"
c
o
x
"
)
c
o
e
<
−
c
o
e
f
(
m
y
f
i
t
,
s
=
m
y
f
i
t
2
lambda.min myfit <- glmnet(v1, v2, family = "cox") coe <- coef(myfit, s = myfit2
lambda.minmyfit<−glmnet(v1,v2,family="cox")coe<−coef(myfit,s=myfit2lambda.min)
act_index <- which(coe != 0)
act_coe <- coe[act_index]
row.names(coe)[act_index]
act_index
coe
myfit2
names(row.names(coe)[act_index])
#pdf(“lambda.pdf”) # 图片保存到pdf中
plot(myfit, xvar = “lambda”, label = TRUE)
#dev.off() #关闭图片保存
参考学习来源:https://site.douban.com/182577/widget/notes/10567212/note/289294468/