R中逻辑回归模型的P值

机器算法验证 r 回归 物流 p 值
2022-04-02 16:05:32

如果我在 R 中创建一个线性模型,我会得到整个模型的 p 值。当我创建逻辑回归模型时,我没有。为什么是这样?

线性回归

x<-rnorm(100)
y<-x+rnorm(100)
summary(lm(y~x))

 Call: lm(formula = y ~ x)

 Residuals:
      Min       1Q   Median       3Q      Max 
 -2.46237 -0.52810 -0.04574  0.48878  2.81002 

 Coefficients:
             Estimate Std. Error t value Pr(>|t|)     (Intercept) -0.02318    0.09394  -0.247    0.806     x            1.10130    0.09421  11.690   <2e-16***
 --- Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

 Residual standard error: 0.9374 on 98 degrees of freedom Multiple
 R-squared:  0.5824,    Adjusted R-squared:  0.5781  F-statistic: 136.7 on
 1 and 98 DF,  p-value: < 2.2e-16

逻辑回归

x<-rnorm(100)
y<-factor(c(rep("ONE",50),rep("TWO",50)))
summary(glm(y~x,family = "binomial"))

 Call: glm(formula = y ~ x, family = "binomial")

 Deviance Residuals: 
      Min        1Q    Median        3Q       Max  
 -1.20658  -1.18093  -0.00499   1.17444   1.21414  

 Coefficients:
               Estimate Std. Error z value Pr(>|z|) (Intercept)  3.857e-05  .000e-01   0.000    1.000 x           -3.924e-02  2.055e-01  -0.191    0.849

 (Dispersion parameter for binomial family taken to be 1)

    Null deviance: 138.63  on 99  degrees of freedom Residual deviance: 138.59  on 98  degrees of freedom AIC: 142.59

 Number of Fisher Scoring iterations: 3
1个回答

这是一种方法:

x <- rnorm(100)
y <- factor(c(rep("ONE",50),rep("TWO",50)))
fmod <- glm(y~x,family = "binomial") ##"full" mod
nmod <- glm(y~1, family = 'binomial') ##"null" mod
anova(nmod, fmod, test = 'Chisq')

此测试的此输出将给出将完整模型与空模型进行比较的 p 值。

偏差表分析

型号 1:y ~ 1

模型 2:y ~ x

渣油。Df残渣。Dev Df Deviance Pr(>Chi)

99     138.63                     
98     137.28  1   1.3454   **0.2461**