UPDATE: 2024-03-27 23:07:31.978447

はじめに

ここでは、比率の差の検定とχ二乗検定の書き換えについてのメモを残しておく。関数の使い方をすぐ忘れてしまうので。

メモ

# Group A 
# 7/100
numerator_a <- 7
denominator_a <- 100

# Group B
# 15/100
numerator_b <- 15
denominator_b <- 100

x <- c(numerator_a, numerator_b)
n <- c(denominator_a, denominator_b)
mat <- cbind(x = x, y = n-x)

list(
  numerator = x,
  denominator = n,
  matrix = mat
)
## $numerator
## [1]  7 15
## 
## $denominator
## [1] 100 100
## 
## $matrix
##       x  y
## [1,]  7 93
## [2,] 15 85
# 母比率の差の検定
prop.test(
  x = x, 
  n = n, 
  alternative = 'two.sided', 
  correct = FALSE
  )
## 
##  2-sample test for equality of proportions without continuity correction
## 
## data:  x out of n
## X-squared = 3.2686, df = 1, p-value = 0.07062
## alternative hypothesis: two.sided
## 95 percent confidence interval:
##  -0.166015404  0.006015404
## sample estimates:
## prop 1 prop 2 
##   0.07   0.15
# カイ二乗検定
chisq.test(
  x = mat,
  correct = FALSE
  )
## 
##  Pearson's Chi-squared test
## 
## data:  mat
## X-squared = 3.2686, df = 1, p-value = 0.07062