chiSquareTest
语法
chiSquareTest(X, [Y])
参数
X 是一个数值向量、矩阵或表。
如果X是一个向量,那么Y是一个与X长度相同的向量;如果X是矩阵或表,那么无需指定Y。
详情
如果X是一个向量,进行Chi-square Goodness-of-fit检验X是否与Y的概率分布一致;如果X是矩阵或表,对X进行Pearson’s Chi-squared检验。返回的结果是一个字典,包含以下key:
pValue: p值
df: 自由度
chiSquaredValue: chi-square统计量
method: 如果X为向量,method为字符串”Chi-square goodness of fit test”;如果X为矩阵或表,method为字符串”Pearson’s Chi-squared test”。
例子
例1. X是一个向量。
$ x=rand(10.0,50)
$ y=rand(10.0,50)
$ chiSquareTest(x,y);
pValue->0
df->49
chiSquaredValue->947.388015
method->Chi-square goodness of fit test
例2. X是一个矩阵。
$ x = matrix([762, 484], [327, 239], [468, 477])
$ x.rename!(`female`male, `Democrat`Independent`Republican)
$ x;
Democrat |
Independent |
Republican |
|
---|---|---|---|
female |
762 |
327 |
468 |
male |
484 |
239 |
477 |
$ chiSquareTest(x);
pValue->2.953589E-7
df->2
chiSquaredValue->30.070149
method->Pearson's Chi-squared test