为什么在R中的glm功能可能的情况下不能仅将1个指令传递给glmnet? [英] Why can't pass only 1 coulmn to glmnet when it is possible in glm function in R?

查看:83
本文介绍了为什么在R中的glm功能可能的情况下不能仅将1个指令传递给glmnet?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么从glmnet包中的glmnet函数中不能仅将一个解释变量传递给glmnet函数中的模型? 代码和错误如下:

Why there is no possibility to pass only 1 explanatory variable to model in glmnet function from glmnet package when it is possible in glm function from base? Code and error are below:

> modelX<-glm( ifelse(train$cliks <1,0,1)~(sparseYY[,40]), family="binomial")
> summary(modelX)

Call:
glm(formula = ifelse(train$cliks < 1, 0, 1) ~ (sparseYY[, 40]), 
    family = "binomial")

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-0.2076  -0.2076  -0.2076  -0.2076   2.8641  

Coefficients:
               Estimate Std. Error  z value Pr(>|z|)    
(Intercept)    -3.82627    0.00823 -464.896   <2e-16 ***
sparseYY[, 40] -0.25844    0.15962   -1.619    0.105    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 146326  on 709677  degrees of freedom
Residual deviance: 146323  on 709676  degrees of freedom
AIC: 146327

Number of Fisher Scoring iterations: 6

> modelY<-glmnet( y =ifelse(train$cliks <1,0,1), x =(sparseYY[,40]), family="binomial"  )
Błąd wif (is.null(np) | (np[2] <= 1)) stop("x should be a matrix with 2 or more columns")

推荐答案

这是我从软件包维护者(Trevor Hastie)那里得到的一个答案:

Here is an answer I got to this question from the maintainer of the package (Trevor Hastie):

glmnet旨在从(大型)集合中选择变量. 允许1个变量会创建很多边缘案例编程,而我对此并不感兴趣. 抱歉!

glmnet is designed to select variables from a (large) collection. Allowing for 1 variable would have created a lot of edge case programming, and I was not interested in doing that. Sorry!

这篇关于为什么在R中的glm功能可能的情况下不能仅将1个指令传递给glmnet?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆