我是统计主题的新手,所以我想这可能是显而易见的,我在这里失踪了。
基本上我想检查一些double
整数值数组(直方图)是否符合Normal distribution(指定了均值和标准差)并具有一定的显着性水平,基于Statistical tests来自Apache Commons Math。
我已经理解的是common way是计算p-value然后决定是否为真假设。
我的第一个"婴儿"步骤是使用One-Way ANOVA测试检查两个阵列是否来自同一分布(第二部分取自文档中的示例):
double samples1[] = new double[100];
double samples2[] = new double[100];
Random rand = new Random();
for (int i = 0; i < 100000; i++) {
int index1 = (int) (rand.nextGaussian()*5 + 50);
int index2 = (int) (rand.nextGaussian()*5 + 50);
try {
samples1[index1-1]++;
}
catch (ArrayIndexOutOfBoundsException e) {}
try {
samples2[index2-1]++;
}
catch (ArrayIndexOutOfBoundsException e) {}
}
List classes = new ArrayList<>();
classes.add(samples1);
classes.add(samples2);
double pvalue = TestUtils.oneWayAnovaPValue(classes);
boolean fail = TestUtils.oneWayAnovaTest(classes, 0.05);
System.out.println(pvalue);
System.out.println(fail);
结果是:
1.0
false
假设显着性水平为0.05,我可以推断出假设为真(即两个数组来自同一分布)p > 0.05
。
现在让我们进行Kolmogorov-Smirnov测试。文档中的示例代码显示了如何针对某个NormalDistribution
对象检查单个数组(这是我的目标)。但是它也允许检查两个数组。在这两种情况下我都无法得到正确的结果。例如,让我们将上面的例子改编成K-S:
double samples1[] = new double[100];
double samples2[] = new double[100];
Random rand = new Random();
for (int i = 0; i < 100000; i++) {
int index1 = (int) (rand.nextGaussian()*5 + 50);
int index2 = (int) (rand.nextGaussian()*5 + 50);
try {
samples1[index1-1]++;
}
catch (ArrayIndexOutOfBoundsException e) {}
try {
samples2[index2-1]++;
}
catch (ArrayIndexOutOfBoundsException e) {}
}
double pvalue = TestUtils.kolmogorovSmirnovTest(samples1, samples2);
boolean fail = pvalue < 0.05;
System.out.println(pvalue);
System.out.println(fail);
结果是:
7.475142727031425E-11
true
我的问题是为什么现在基本上相同数据的p值如此之小?这是否意味着此测试不适合此类数据?
我应该:
NormalDistribution
的参考数组(即具有指定的均值和标准偏差),然后使用单向ANOVA测试(或其他)将其与我的数组进行比较NormalDistribution
对象