比较逻辑模型时的方差分析函数没有偏差的 p 值

Oma*_*789 2 statistics r model-fitting anova logistic-regression

我正在使用 R 中 MASS 库中的活检数据集。我正处于创建逻辑回归模型的初始阶段,以了解哪些变量对罹患恶性肿瘤的概率有影响。我删除了所有缺失数据的行(大约 16 个观察值)。所有变量本身都很重要,因此我从包含所有变量的最完整模型开始,第三个变量(V3 - 细胞大小的均匀性)是这个最完整模型中最不重要的变量。

我创建了另一个模型,删除了 V3。然后我想使用 anova() 函数来查看两个模型的拟合是否存在显着差异。但是,我从方差分析测试中没有得到 p 值。这是否意味着 p 值接近 1?我的模型设置中是否有错误?

感谢所有输入!

#post removal of rows with missing data from biopsy in library(MASS)     
relevel(biopsy$class, ref = "malignant")
#assigns value of interst to malignant instead of benign. 
fullest.model = glm(biopsy$class~biopsy[,2]+biopsy[,3]+biopsy[,4]+biopsy[,5]+
                  biopsy[,6]+biopsy[,7]+biopsy[,8]+biopsy[,9]+biopsy[,10]
                ,family = binomial(link = "logit"))
model1 = glm(biopsy$class~biopsy[,2]+biopsy[,4]+biopsy[,5]+
           biopsy[,6]+biopsy[,7]+biopsy[,8]+biopsy[,9]+biopsy[,10]
         ,family = binomial(link = "logit"))
anova(model1, fullest.model)
Run Code Online (Sandbox Code Playgroud)

我得到的输出:

      Resid. Df Resid. Dev Df   Deviance
1       674     102.89              
2       673     102.89  1 0.00090001
Run Code Online (Sandbox Code Playgroud)

^看不到p值!

Mau*_*ers 5

    \n
  1. 我们生成一些样本数据,假设 GLM y = 0.5 * x1 + 4 * x2

    \n\n
    # Generate some sample data\nx1 <- 1:100;\nx2 <- gl(2, 50, 100);\nset.seed(2017);\ny <- 0.5 * x1 + 4 * as.numeric(x2) + rnorm(100);\n
    Run Code Online (Sandbox Code Playgroud)
  2. \n
  3. 我们现在拟合两个模型:

    \n\n
      \n
    • fit1估计模型的系数y = beta0 + beta1 * x1
    • \n
    • fit2估计模型 的系数y = beta0 + beta1 * x1 + beta2 * x2
    • \n
    \n\n

    \n\n
    # Fit two models\nfit1 <- glm(y ~ x1 + x2);\nfit2 <- glm(y ~ x1);\n
    Run Code Online (Sandbox Code Playgroud)
  4. \n
  5. 执行方差分析。

    \n\n
    # Default ANOVA (note this does not perform any hypothesis test)\nanova(fit1, fit2);\n#Analysis of Deviance Table\n#\n#Model 1: y ~ x1 + x2\n#Model 2: y ~ x1\n#  Resid. Df Resid. Dev Df Deviance\n#1        97     112.11\n#2        98     213.39 -1  -101.28\n\n# ANOVA with likelihood ratio test\nanova(fit1, fit2, test = "Chisq");\n#Analysis of Deviance Table\n#\n#Model 1: y ~ x1 + x2\n#Model 2: y ~ x1\n#  Resid. Df Resid. Dev Df Deviance  Pr(>Chi)\n#1        97     112.11\n#2        98     213.39 -1  -101.28 < 2.2e-16 ***\n#---\n#Signif. codes:  0 \xe2\x80\x98***\xe2\x80\x99 0.001 \xe2\x80\x98**\xe2\x80\x99 0.01 \xe2\x80\x98*\xe2\x80\x99 0.05 \xe2\x80\x98.\xe2\x80\x99 0.1 \xe2\x80\x98 \xe2\x80\x99 1\n
    Run Code Online (Sandbox Code Playgroud)\n\n

    请注意,第一个方差分析比较不执行任何假设检验。它只是计算两个模型之间偏差的变化。第二个方差分析通过计算观察卡方分布检验统计量(即偏差的变化)为极端或更极端的概率来anova(..., test = "Chisq")执行似然比检验(与 相同)。后一个数量对应于假设检验的 p 值。anova(..., test = "LRT")

  6. \n
  7. 最后,看看这个链接。它提供了有关如何执行和解释方差分析输出的更多详细信息。

  8. \n
\n