【发布时间】:2020-01-27 13:40:21
【问题描述】:
我用 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' 参数必须是逻辑类型
我还使用了coefplot 建议的here 包的extract.coef 函数。我有这个错误:
> library (coefplot)
> coefplot :: extract.coef (fitL)
UseMethod 中的错误(通用 =“extract.coef”,对象 = 模型):不 适用于“c”类对象的“extract.coef”方法 ('coxnet', 'glmnet')"
【问题讨论】:
标签: r glmnet coefficients cox