![](/img/trans.png)
[英]predict.glmnet() gives same predictions for type = "link" and "response" using family = "binomial"
[英]Using glm to predict continuous variables between 0 and 1 family=binomial(link='logit') gives error
我正在嘗試使用glm使用以下代碼來估計0到1之間的連續變量的邏輯回歸,但是卻出現了錯誤:
> glm(y ~ x, data=test_data, family=binomial(link = 'logit'))
Error in eval(family$initialize) : y values must be 0 <= y <= 1
但是,當我對test_data進行匯總時,df的y值完全在0到1之間...
> summary(test_data)
y x
Min. :0.000000 Min. :0.0000
1st Qu.:0.001510 1st Qu.:0.0000
Median :0.003664 Median :1.0000
Mean :0.025847 Mean :0.5386
3rd Qu.:0.009054 3rd Qu.:1.0000
Max. :1.000000 Max. :1.0000
誰能幫助我了解這里的問題? 如果我檢查變量的類型,它們都是數字:
> class(test_data$y)
[1] "numeric"
> class(test_data$x)
[1] "numeric"
建議您嘗試:
which(as.numeric(test_data$x) < 0 | as.numeric(test_data$x) > 1)
which(as.numeric(test_data$y) < 0 | as.numeric(test_data$y) > 1)
我在這里發現了問題-深入研究數據后,只有少量行具有非常小的y負值(可能由於舍入誤差),例如:
> test_data[276,]
# A tibble: 1 x 2
y x
<dbl> <dbl>
1 -1.47e-17 0
但是,這些超出范圍的值不會在摘要中顯示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.