使用ridge和套索回归时出现以下错误。
storage.mode(y)中的错误<-“ double”:无效,无法更改 一个因子的存储方式
我的数据集如下:
> as_data_frame(blca.only)
# A tibble: 315 x 435
Tags TCGA.BL.A5ZZ.01 TCGA.XF.AAN1.01 TCGA.DK.A2I4.01 TCGA.XF.A9T4.01
<fct> <dbl> <dbl> <dbl> <dbl>
1 ENSG~ 2001. 2170. 0 0
2 ENSG~ 0 0 64.4 0
3 ENSG~ 68078. 93147. 108379. 78136.
4 ENSG~ 0 0 0 0
5 ENSG~ 160562. 176357. 153682. 204135.
6 ENSG~ 217109. 399909. 215158. 253031.
7 ENSG~ 0 0 0 0
8 ENSG~ 1583. 1236. 1982. 4618.
9 ENSG~ 3535627. 7037139. 2725637. 3036243.
10 ENSG~ 1843. 3997. 1282. 1607.
# ... with 305 more rows, and 430 more variables: TCGA.DK.AA6Q.01 <dbl>,
# TCGA.XF.A8HB.01 <dbl>, TCGA.2F.A9KR.01 <dbl>, TCGA.FD.A3N6.01 <dbl>,
# TCGA.GV.A3QK.01 <dbl>, TCGA.ZF.A9RE.01 <dbl>, TCGA.FD.A43S.01 <dbl>,
# TCGA.K4.A5RI.11 <dbl>, TCGA.ZF.AA4U.01 <dbl>, TCGA.GV.A3QF.01 <dbl>,
# TCGA.UY.A9PE.01 <dbl>, TCGA.FD.A3B4.01 <dbl>, TCGA.GC.A3YS.01 <dbl>,
# TCGA.G2.A2EF.01 <dbl>, TCGA.BT.A42C.01 <dbl>, TCGA.FD.A62O.01 <dbl>,
# TCGA.BL.A13J.01 <dbl>, TCGA.E5.A4U1.01 <dbl>, TCGA.E7.A6MD.01 <dbl>,
# TCGA.CF.A47Y.01 <dbl>, TCGA.5N.A9KI.01 <dbl>, TCGA.DK.A3IT.01 <dbl>,
# TCGA.DK.AA77.01 <dbl>, TCGA.ZF.AA4R.01 <dbl>, TCGA.GU.A763.01 <dbl>,
# TCGA.DK.A3IL.01 <dbl>, TCGA.FD.A6TC.01 <dbl>, TCGA.FD.A3SP.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dbl>, TCGA.2F.A9KT.01 <dbl>,
# TCGA.XF.A9SL.01 <dbl>, TCGA.DK.AA75.01 <dbl>, TCGA.CF.A9FL.01 <dbl>,
# TCGA.DK.A6B1.01 <dbl>, TCGA.K4.A3WV.11 <dbl>,
# TCGA.BL.A13I.01_Rep85 <dbl>, TCGA.GV.A3QH.01 <dbl>,
# TCGA.XF.A9SM.01 <dbl>, TCGA.ZF.AA5P.01 <dbl>, TCGA.DK.A6B0.01 <dbl>,
# TCGA.G2.A2ES.01 <dbl>, TCGA.CF.A1HS.01 <dbl>, TCGA.FJ.A3Z7.01 <dbl>,
# TCGA.HQ.A2OF.01 <dbl>, TCGA.C4.A0F6.01 <dbl>, TCGA.FD.A5C1.01 <dbl>,
# TCGA.ZF.A9R9.01 <dbl>, TCGA.GU.A42P.01 <dbl>, TCGA.FD.A43U.01 <dbl>,
# TCGA.S5.A6DX.01 <dbl>, TCGA.GD.A3OP.11 <dbl>, TCGA.K4.A4AC.01 <dbl>,
# TCGA.GD.A2C5.01 <dbl>, TCGA.4Z.AA84.01 <dbl>, ..
我尝试过:
> lasso.1 <- glmnet(x = as.matrix(blca.only[,-1]), y = factor(blca.only$Tags), alpha = 1)
Error in storage.mode(y) <- "double" :
invalid to change the storage mode of a factor
> Y <- factor(blca.only$Tags)
> lasso.1 <- glmnet(x = as.matrix(blca.only[,-1]), y = blca.only$Tags, alpha = 1)
Error in storage.mode(y) <- "double" :
invalid to change the storage mode of a factor
> Y <- factor(blca.only$Tags)
> lasso.1 <- glmnet(x = as.matrix(blca.only[,-1]), y = Y, alpha = 1)
Error in storage.mode(y) <- "double" :
invalid to change the storage mode of a factor
我的数据类型如下:
> typeof(blca.only)
[1] "list"
我不知道如何解决这个问题。先感谢您!希望你能帮助我解决这个问题。
答案 0 :(得分:0)
在您的情况下,我假设您要进行逻辑回归。因此,您必须指定family
参数。试试这个:
lasso.1 <- glmnet(x = as.matrix(blca.only[,-1]), y = factor(blca.only$Tags), alpha = 1,
family = "binomial")
另请参阅this question。