如何比较两个相同规模的组中的案例数量?

How to compare the amount of cases in two same-sized groups?

这很可能是一个非常简单的问题,但我还是会问这个问题,因为我还没有找到答案。我如何比较两组中“病例”(例如流感)的数量,即找出两组病例数量之间的差异是否具有统计学意义?我可以应用某种 t 检验吗?或者做这样的比较有意义吗?

我最好在 R 中进行比较。

一个非常简单的数据示例:

group1 <- 1000 # size of group 1
group2 <- 1000 # size of group 2

group1_cases <- 550 # the amount of cases in group 1
group2_cases <- 70 # the amount of cases in group 2

我想 chisq.test 就是您要找的。

group1 <- 1000 # size of group 1
group2 <- 1000 # size of group 2

group1_cases <- 550 # the amount of cases in group 1
group2_cases <- 70 # the amount of cases in group 2

group1_noncases <- 1000 - group1_cases
group2_noncases <- 1000 - group2_cases


M <- as.table(rbind(c(group1_cases, group1_noncases),
                    c(group2_cases, group2_noncases)))

dimnames(M) <- list(groups = c("1", "2"),
                    cases = c("yes","no"))

res <- chisq.test(M)

# The Null, that the two groups are equal, has to be rejected:

res
#> 
#>  Pearson's Chi-squared test with Yates' continuity correction
#> 
#> data:  M
#> X-squared = 536.33, df = 1, p-value < 2.2e-16

# if both groups were equal then this would be the expected values:

res$expected
#>       cases
#> groups yes  no
#>      1 310 690
#>      2 310 690

reprex package (v0.3.0)

于 2021-04-28 创建

据统计,t.test 不是正确的方法。然而,人们将它用于此类测试,并且在大多数情况下 p 值非常相似。

# t test
dat <- data.frame(groups = c(rep("1", 1000), rep("2", 1000)),
       values = c(rep(1, group1_cases),
                  rep(0, group1_noncases),
                  rep(1, group2_cases),
                  rep(0, group2_noncases)))

t.test(dat$values ~ dat$groups)

#> 
#>  Welch Two Sample t-test
#> 
#> data:  dat$values by dat$groups
#> t = 27.135, df = 1490.5, p-value < 2.2e-16
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>  0.4453013 0.5146987
#> sample estimates:
#> mean in group 1 mean in group 2 
#>            0.55            0.07

reprex package (v0.3.0)

于 2021-04-28 创建