0

正規分布する母集団からのサンプルであるという仮説をテストしたい 30 個のサンプルのベクトルがあります。

> N.concentration
  [1] 0.164 0.045 0.069 0.100 0.050 0.080 0.043 0.036 0.057 0.154 0.133 0.193
  [13] 0.129 0.121 0.081 0.178 0.041 0.040 0.116 0.078 0.104 0.095 0.116 0.038
  [25] 0.141 0.100 0.104 0.078 0.121 0.104

を使用して周波数ベクトルを作成しましたhist

> N.hist <- hist(N.concentration, breaks=10)
> N.freq <- N.hist$count
  [1] 3 5 4 4 5 4 2 2 1

正規分布へchisq.testの適合性をチェックするために使用していますが、関数には引数 p = chisq.test のドキュメントで定義されているx と同じ長さの確率のベクトルが必要です。それにベクトルを生成しようとしていますが、正直なところ、何を生成すればよいか正確にはわかりません。私はしようとしていますN.freq

> d <- length(N.freq$count)%/%2
> p <- dnorm(c(-d:d))
> p
  [1] 0.0001338302 0.0044318484 0.0539909665 0.2419707245 0.3989422804
  [6] 0.2419707245 0.0539909665 0.0044318484 0.0001338302
> chisq.test(N.freq, p = p)
   Error in chisq.test(p1$count, p = p) : 
   probabilities must sum to 1.

使用することを考えましrescale.p=TRUEたが、これが有効なテストを生成するかどうかはわかりません。


編集: rescale.p を使用すると、警告メッセージが表示されました

> chisq.test(N.freq, p=p, rescale.p=TRUE)

Chi-squared test for given probabilities

data:  N.freq
X-squared = 2697.7, df = 8, p-value < 2.2e-16

Warning message:
In chisq.test(N.freq, p = p, rescale.p = TRUE) :
Chi-squared approximation may be incorrect
4

2 に答える 2

3

先ほど言ったように、正規性をテストするには、帰無仮説の正規分布の平均と標準誤差を知る必要があります。与えられた値がないため、30 個のデータから推定する必要があります。

x <- c(0.164, 0.045, 0.069, 0.1, 0.05, 0.08, 0.043, 0.036, 0.057, 
0.154, 0.133, 0.193, 0.129, 0.121, 0.081, 0.178, 0.041, 0.04, 
0.116, 0.078, 0.104, 0.095, 0.116, 0.038, 0.141, 0.1, 0.104, 
0.078, 0.121, 0.104)

mu <- mean(x)
sig <- sd(x)

ここで、あなたが行ったことと同様に、データをビン化する必要があります。

h <- hist(x, breaks = 10)
#List of 6
# $ breaks  : num [1:10] 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
# $ counts  : int [1:9] 3 5 4 4 5 4 2 2 1
# $ density : num [1:9] 5 8.33 6.67 6.67 8.33 ...
# $ mids    : num [1:9] 0.03 0.05 0.07 0.09 0.11 0.13 0.15 0.17 0.19
# $ xname   : chr "x"
# $ equidist: logi TRUE
# - attr(*, "class")= chr "histogram"

帰無仮説の下で真の確率を取得するには、各ビン セル、つまりブレーク間の確率が必要です。

p <- diff(pnorm(h$breaks, mu, sig))
#[1] 0.05675523 0.10254734 0.15053351 0.17953337 0.17396679 0.13696059 0.08760419
#[8] 0.04552387 0.01921839

私は、データが 30 個しかないカイ 2 乗検定を信用しない傾向があります。しかし、次のように使用できますchisq.test

chisq.test(h$counts, p = p, rescale.p = TRUE)
#
#   Chi-squared test for given probabilities
#
#data:  h$counts
#X-squared = 3.1476, df = 8, p-value = 0.9248
#
#Warning message:
#In chisq.test(h$counts, p, rescale.p = TRUE) :
#  Chi-squared approximation may be incorrect

多くの場合、警告メッセージを気にする必要はありません。それを取り除きたい場合は、次のように設定しsimulate.p.value = TRUEます。

chisq.test(h$counts, p = p, rescale.p = TRUE, simulate.p.value = TRUE)
#
#   Chi-squared test for given probabilities with simulated p-value (based
#   on 2000 replicates)
#
#data:  h$counts
#X-squared = 3.1476, df = NA, p-value = 0.942
于 2016-11-20T19:43:26.233 に答える