グラブス検定による極値のテスト

Rで学ぶ異常検知入門

Alastair Rushworth

Data Scientist

視覚的な評価は常に信頼できるとは限りません!

boxplot(temperature, ylab = "Celsius")

外れ値を示すボックスプロット

Rで学ぶ異常検知入門

グラブス検定

  • 点が外れ値かどうかを判断する統計的検定
  • データが正規分布に従うことを前提とする
  • 正規性の仮定を事前に確認する必要がある
Rで学ぶ異常検知入門

ヒストグラムで正規性を確認する

hist(temperature, breaks = 6)

データ分布を示すヒストグラム

左右対称でベル型ですか?

Rで学ぶ異常検知入門

グラブス検定を実行する

grubbs.test() 関数を使用します:

grubbs.test(temperature)
    Grubbs test for one outlier
data:  temp
G = 3.07610, U = 0.41065, p-value = 0.001796
alternative hypothesis: highest value 30 is an outlier
Rで学ぶ異常検知入門

p値を解釈する

grubbs.test(temperature)
    Grubbs test for one outlier

data:  temperature
G = 3.07610, U = 0.41065, p-value = 0.001796
alternative hypothesis: highest value 30 is an outlier

  p-value

  • 0 に近い - 外れ値の証拠が_強い_
  • 1 に近い - 外れ値の証拠が_弱い_
Rで学ぶ異常検知入門

外れ値の行インデックスを取得する

最大値の位置

which.max(weights)
5

最小値の位置

which.min(temperature)
12
Rで学ぶ異常検知入門

練習しましょう!

Rで学ぶ異常検知入門

Preparing Video For Download...