-
-
Save raicos/c0973b6600ba57d84ea443fe163b0df3 to your computer and use it in GitHub Desktop.
アドベントカレンダーQiita記事 統計
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# シードを固定 記事の公開日が12月21日なので | |
set.seed(1221) | |
# Aクラスの点数 平均点が500点くらいになる小規模クラス | |
group_A <- as.integer(rnorm(n = 16, mean = 500, sd = 100)) | |
# Bクラスの点数 平均点が500点くらいになる大規模クラス | |
group_B <- as.integer(rnorm(n = 41, mean = 500, sd = 100)) | |
# 各クラスのデータ出力 | |
group_A | |
group_B | |
mean(group_A) | |
mean(group_B) | |
# ===== 等分散仮説の検定 ===== # | |
# 統計量Fの算出 | |
(f <- var(group_A) / var(group_B)) | |
# 棄却域の算出 | |
qf(1 - 0.025, 15, 40) | |
qf(1 - 0.975, 15, 40) | |
# 別解 | |
var.test(group_A, group_B) | |
# ===== 等平均仮説の検定 ===== # | |
# 統計量Tの算出 | |
n_a <- length(group_A) | |
n_b <- length(group_B) | |
s_a <- var(group_A) * (n_a - 1) / n_a | |
s_b <- var(group_B) * (n_b - 1) / n_b | |
u2 <- (n_a * s_a + n_b * s_b) / ((n_a - 1) + (n_b - 1)) | |
(t <- (mean(group_A) - mean(group_B)) / (sqrt(u2 * ((1 / n_a) + (1 / n_b))))) | |
# 棄却域の算出 | |
qt(1 - 0.025, 55) | |
# 別解 | |
t.test(group_A, group_B, var.equal = T) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment