R返回值大于1的逻辑回归

时间:2019-07-02 14:44:19

标签: r regression logistic-regression glm

我已经使用glm在R中进行了logistic回归,根据性别(Gen),吸烟状况(Smoke1993),高血压(HT1993),高胆固醇预测1993年的个体在2004年(Arth2004)患有关节炎的可能性(HC1993)和BMI(BMI1993)在1993年的状态。我的样本大小为n = 7896。除BMI(连续的数字)外,所有变量都是false和true的二进制变量,0和1。对于性别,男性= 1,女性= 0。

当我在R中运行回归时,我得到了很好的p值,但是当我实际使用回归进行预测时,对于非常标准的人,我得到的值常常大于一个。对于较大的代码块,我深表歉意,但我认为更多信息可能会有所帮助。

library(ResourceSelection)
library(MASS)
data=read.csv(file.choose())
data$Arth2004 = as.factor(data$Arth2004)
data$Gen = as.factor(data$Gen)
data$Smoke1993 = as.factor(data$Smoke1993)
data$HT1993 = as.factor(data$HT1993)
data$HC1993 = as.factor(data$HC1993)
data$BMI1993 = as.numeric(data$BMI1993)

logistic <- glm(Arth2004 ~ Gen + Smoke1993 + BMI1993 + HC1993 + HT1993, data=data, family="binomial")

summary(logistic)

hoslem.test(logistic$y, fitted(logistic))

confint(logistic)

min(data$BMI1993)
median(data$BMI1993)
max(data$BMI1993)

e=2.71828

输出如下:

Call:
glm(formula = Arth2004 ~ Gen + Smoke1993 + BMI1993 + HC1993 + 
    HT1993, family = "binomial", data = data)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-2.0362  -1.0513  -0.7831   1.1844   1.8807  

Coefficients:
             Estimate Std. Error z value Pr(>|z|)    
(Intercept) -2.346104   0.158043 -14.845  < 2e-16 ***
Gen1        -0.748286   0.048398 -15.461  < 2e-16 ***
Smoke19931  -0.059342   0.064606  -0.919    0.358    
BMI1993      0.084056   0.006005  13.997  < 2e-16 ***
HC19931      0.388217   0.047820   8.118 4.72e-16 ***
HT19931      0.341375   0.058423   5.843 5.12e-09 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for binomial family taken to be 1)

    Null deviance: 10890  on 7895  degrees of freedom
Residual deviance: 10309  on 7890  degrees of freedom
AIC: 10321

Number of Fisher Scoring iterations: 4

    Hosmer and Lemeshow goodness of fit (GOF) test

data:  logistic$y, fitted(logistic)
X-squared = 18.293, df = 8, p-value = 0.01913

Waiting for profiling to be done...
                  2.5 %      97.5 %
(Intercept) -2.65715966 -2.03756775
Gen1        -0.84336906 -0.65364134
Smoke19931  -0.18619647  0.06709748
BMI1993      0.07233866  0.09588198
HC19931      0.29454661  0.48200673
HT19931      0.22690608  0.45595006

[1] 18
[1] 26
[1] 43

一名非吸烟女性,体重指数中位数(26),高血压和高胆固醇血症会导致以下情况:

e^(26*0.084056+1*0.388217+1*0.341375-0*0.748286-0*0.059342-2.346104)

[1] 1.7664

我认为该问题与BMI有某种联系,因为这是唯一的数字变量。有谁知道为什么这种回归产生的概率大于1?

1 个答案:

答案 0 :(得分:1)

默认情况下,family = "binomial"使用logit链接功能(请参见?family)。因此,您寻找的概率为1.7664 / (1+1.7664)