2標本t検定

Pythonで学ぶアンケートデータ分析

EbunOluwa Andrew

Data Scientist

協調性の比較

握手する人々

group_a.agreeableness.mean()
4.011701199563795
group_b.agreeableness.mean()
4.03669574700109
Pythonで学ぶアンケートデータ分析

2標本t検定とは

  • 2つの独立群の平均に有意差があるか検定
  • 差が偶然かどうかを判断

AとBのラベル付きボトル2本

Pythonで学ぶアンケートデータ分析

2標本t検定の前提

  • 独立
  • 正規分布
    • Shapiro–Wilk検定
    • stats.shapiro()
    • p値 > 0.05 → 正規とみなす
  • 等分散
    • Levene検定
    • stats.levene()
    • p値 > 0.05 → 等分散とみなす

木製の数字ブロック

Pythonで学ぶアンケートデータ分析

調査結果

group_a

| userid | agreeableness |
|--------|---------------|
|    895 |          4.78 |
|    a06 |          3.40 |
|    e94 |          3.66 |
|    ee6 |          5.41 |
|    521 |          4.58 |
|    f4c |          3.24 |
...

1 = 低協調性

group_b

| userid | agreeableness |
|--------|---------------|
|    b7e | 4.43          |
|    030 | 2.92          |
|    f91 | 4.01          |
|    36f | 2.20          |
|    875 | 3.83          |
|    750 | 4.95          |
...

7 = 高協調性

Pythonで学ぶアンケートデータ分析

独立したグループ

2つのグループ

Pythonで学ぶアンケートデータ分析

正規分布のグループ

from scipy.stats import shapiro
import scipy.stats as stats

norm_A = stats.shapiro(
  group_a.agreeableness)

ShapiroResult(
statistic=0.997467577457428,
pvalue=0.16834689676761627)
from scipy.stats import shapiro
import scipy.stats as stats

norm_B = stats.shapiro(
  group_b.agreeableness)

ShapiroResult(
statistic=0.9987381100654602,
pvalue=0.7757995128631592)
Pythonで学ぶアンケートデータ分析

等分散

import scipy.stats as stats

var_test = stats.levene(group_a.agreeableness, group_b.agreeableness)
LeveneResult(statistic=0.40492634057696597, pvalue=0.5246354858484796)
Pythonで学ぶアンケートデータ分析

前提の確認

  • 独立したグループ
    • 個体の重複なし
  • 正規分布
  • 等分散
    • 2群の分散に有意差なし

Apple Pencil—UnsplashのDose Mediaによる写真

Pythonで学ぶアンケートデータ分析

2標本t検定(statsmodels)

from scipy import stats

stats.ttest_ind(group_a.agreeableness, group_b.agreeableness)
Pythonで学ぶアンケートデータ分析

2標本t検定(statsmodels)

Ttest_indResult(statistic=0.7746406648066304, pvalue=0.4386519848366188)
Pythonで学ぶアンケートデータ分析

追加分析

group_a_mean = 4.011701199563795
group_b_mean = 4.03669574700109

カリフォルニアの住宅

Pythonで学ぶアンケートデータ分析

練習に進みましょう!

Pythonで学ぶアンケートデータ分析

Preparing Video For Download...