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

标签 r statistics logistic-regression anova model-fitting

我正在使用 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)

我得到的输出:

      Resid. Df Resid. Dev Df   Deviance
1       674     102.89              
2       673     102.89  1 0.00090001

^看不到p值!!

最佳答案

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

    # Generate some sample data
    x1 <- 1:100;
    x2 <- gl(2, 50, 100);
    set.seed(2017);
    y <- 0.5 * x1 + 4 * as.numeric(x2) + rnorm(100);
    
  2. 我们现在适合两种模型:

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

    # Fit two models
    fit1 <- glm(y ~ x1 + x2);
    fit2 <- glm(y ~ x1);
    
  3. 执行 ANOVA 分析。

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

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

  4. 最后,看看this link 。它提供了有关如何执行和解释方差分析输出的更多详细信息。

关于r - 比较逻辑模型时的方差分析函数没有偏差的 p 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49103318/

相关文章:

r - 使用 data.table 按与另一行的距离选择行

r - 将列表中的所有 SpatialPolygonsDataFrame 对象聚合到一个 SpatialPolygonsDataFrame

用于查找错误输入数据的 R 包

java - 根据回归方程的参数估计值计算概率

php - PHP中特定计数的非重复组合

r - R 中插补后的逻辑回归

r - 无法在 Windows 7 中安装 R 包

go - 如何使用 go 内部包中的统计函数 (MannWhitneyUTest)

python - ValueError : shapes (2, 100) 和 (2,1) 未对齐 : 100 (dim 1) ! = 2(暗淡 0)

python - NumPy 日志函数抛出 int 属性错误