提取带有“哪个”的非零glmnet系数时出错

问题描述 投票:0回答:1

我用glmnet拟合了一个考克斯模型:

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 (coef (fitL)! = 0) 

[base ::中的错误,其中(x,arr.ind,useNames,...):“参数”必须为逻辑类型

我也使用了extract.coef包中建议的coefplothere功能。我有此错误:

> library (coefplot)
> coefplot :: extract.coef (fitL)

UseMethod中的错误(通用=“ extract.coef”,object =模型):否适用于“ c”类对象的“ extract.coef”方法('coxnet','glmnet')“

r glmnet which coefficients cox
1个回答
0
投票

[使用predict代替参数type="nonzero"

© www.soinside.com 2019 - 2024. All rights reserved.