【问题标题】:R - Chi Squared Independence Test - How To?R - 卡方独立性检验 - 如何?
【发布时间】:2021-03-14 04:23:48
【问题描述】:

使用 R - 进行 Pearsons 卡方独立性测试 - 我如何获得“预期”表。

鉴于: 观察到

airline late not_late total
ABC 43 200 243
DEF 70 262 332
total 113 462 575

期望的输出: 预期

airline late not_late total
ABC 47.75 195.25 243
DEF 65.25 266.75 332
total 113 462 575

“预期”数字的计算方式如下......

单元格(ABC,late)=(113 x 243)/575 = 47.75

单元格(ABC,late)=(113 x 332)/575 = 65.25 等等

【问题讨论】:

    标签: r


    【解决方案1】:

    提取total 行和列,并使用outer 将它们相乘,然后除以数据框中的最后一个值。

    df[-1] <- outer(df$total, unlist(df[3, -1]))/df[3, 4]
    df
    
    #  airline      late not_late total
    #1     ABC  47.75478 195.2452   243
    #2     DEF  65.24522 266.7548   332
    #3   total 113.00000 462.0000   575
    

    数据

    df <- structure(list(airline = c("ABC", "DEF", "total"), late = c(43L, 
    70L, 113L), not_late = c(200L, 262L, 462L), total = c(243L, 332L, 
    575L)), class = "data.frame", row.names = c(NA, -3L))
    

    【讨论】:

      猜你喜欢
      • 2020-10-12
      • 1970-01-01
      • 2013-11-02
      • 1970-01-01
      • 2020-10-03
      • 1970-01-01
      • 1970-01-01
      • 2021-05-17
      • 1970-01-01
      相关资源
      最近更新 更多