我用glmnet安装了一个 cox 模型,例如:
fitL <- glmnet(
X,
Y,
family = "cox",
alpha = 1,
lambda = cvL$lambda.min, #cvL obteined with cv.glmnet
standardize = FALSE,
thresh = thresh
)
我获得了:
str(coef(fitL) != 0)
Formal class 'lgCMatrix' [package "Matrix"] with 6 slots
..@ i : int [1:24] 0 76 81 96 125 149 213 266 277 415 ...
..@ p : int [1:2] 0 24
..@ Dim : int [1:2] 1000 1
..@ Dimnames:List of 2
.. ..$ : chr [1:1000] "001" "002" "003" "004" ...
.. ..$ : chr "s0"
..@ x : logi [1:24] TRUE TRUE TRUE TRUE TRUE TRUE ...
..@ factors : list()
我想提取非零系数(即选定的变量),我使用了“which”,我遇到了这个错误:
> which (coef (fitL)! = 0)
base :: which (x, arr.ind, useNames, ...) 中的错误:“which”参数必须是逻辑类型
我还使用了这里提出的包extract.coef
的功能。我有这个错误:coefplot
> library (coefplot)
> coefplot :: extract.coef (fitL)
UseMethod 中的错误(通用 =“extract.coef”,对象 = 模型):没有适用于“c('coxnet','glmnet')”类对象的“extract.coef”方法