@ 弹性/ 统计
TypeScript和JavaScript的纯统计函数.
安装
npm install @elastic/statistics
使用量
测试
镜像 scipy.stats.ttest_rel。 。 。 .
当每个差异都是一样的时,统计是无限的NaN 如果差异为零)和
p 值为 1, scipy 返回 0 (NaN) (中文(简体) ).
import { pairedT } from '@elastic/statistics';
const { statistic, pValue } = pairedT([0.9, 0.85, 0.7, 0.95, 0.8], [0.8, 0.75, 0.72, 0.88, 0.7]);
// statistic and pValue are null when fewer than two pairs are given
Wilcoxon 签名排名测试
镜像 scipy.stats.wilcoxon· ;
p值与浮点精度相匹配.
import { wilcoxonSignedRank } from '@elastic/statistics';
const target = [0.9, 0.85, 0.7, 0.95, 0.8, 0.6, 0.75];
const baseline = [0.8, 0.75, 0.72, 0.88, 0.7, 0.6, 0.7];
const { statistic, pValue, zStatistic } = wilcoxonSignedRank(target, baseline);
// { statistic: 1, pValue: 0.0625, zStatistic: null }
// Is target stochastically greater than baseline? Use the normal approximation with continuity correction.
wilcoxonSignedRank(target, baseline, {
alternative: 'greater',
method: 'asymptotic',
correction: true,
});
| 选项 | 数值 | 默认 | 页:1 |
|---|---|---|---|
alternative | 'two-sided', (中文(简体) ), 'less', (中文(简体) ), 'greater' | 'two-sided' | 关于差异的假设 target - baseline。 。 。 . |
zeroMethod | 'wilcox', (中文(简体) ), 'pratt', (中文(简体) ), 'zsplit' | 'wilcox' | 丢弃零分之差,排出他们的分级但降出他们的分级,或者将他们的分级分成两笔. |
method | 'auto', (中文(简体) ), 'exact', (中文(简体) ), 'asymptotic' | 'auto' | 'auto' 使用精确分布到50对,没有带或零,对最多13对进行详尽的穿透试验,以及上面的正常近似. |
correction | boolean | false | 正常近似值的持续修正. |
statistic 的正和负级金额中 'two-sided'和正数
否则,军衔总数. zStatistic 当使用正常近似时设置。 三个都是 null
当试验不能计算的时候(没有对子, NaN 在样本中,或者没有为正常状态留下差异
近似值,例如每个相差为零;函数从未为这种输入投出.
差异用浮点计算,所以对接时可以得到不同的分级
因圆相取( 二0.825 - 0.775 !== 0.5 - 0.45) (中文(简体) ). 当确切的领带重要时,第一回合得分.
曼-惠特尼U测试
两个独立样本的非参数测试。 镜像
scipy.stats.mannwhitneyu· ;
p值与浮点精度相匹配.
import { mannWhitney } from '@elastic/statistics';
const target = [0.9, 0.85, 0.7, 0.95, 0.8];
const baseline = [0.8, 0.75, 0.72, 0.6];
const { statistic, pValue, zStatistic } = mannWhitney(target, baseline);
// { statistic: 16.5, pValue: 0.1399825237583975, zStatistic: 1.475856111043418 }
mannWhitney(target, baseline, { alternative: 'greater', method: 'asymptotic' });
// { statistic: 16.5, pValue: 0.06999126187919875, zStatistic: 1.475856111043418 }
| 选项 | 数值 | 默认 | 页:1 |
|---|---|---|---|
alternative | 'two-sided', (中文(简体) ), 'less', (中文(简体) ), 'greater' | 'two-sided' | 是否隐藏分布 target 不同之处,是比 baseline对. |
method | 'auto', (中文(简体) ), 'exact', (中文(简体) ), 'asymptotic' | 'auto' | 'auto' 使用一个样本最多有8个值且没有关系时的精确分布,通常的近似. |
continuity | boolean | true | 正常近似值的持续修正. |
statistic 是 U 统计 target· ; baseline这是 target.length * baseline.length - statistic。 。 。 .
zStatistic 当使用正常近似时设置。 三个都是 null 当测试时
无法计算(一个空样本, NaN 在样本中,或者在正常近似下捆绑的每个值.
麦克尼马尔测试
二进制结果true编号 :false 或者说 1编号 :0)在相同的例子上得分. 只有不和谐的人
双数 : b (第一个样本成功,第二个失败)和 c (倒转). 输入要么是
两个对齐的数组或一个 2x2 表格 [[a, b], [c, d]] 在统计模型布局中( 第一组)
样本成功/失败,列:第二个样本成功/失败.
import {
mcnemar,
mcnemarExact,
mcnemarMidP,
mcnemarStratified,
pairedTable,
} from '@elastic/statistics';
const target = [1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1];
const baseline = [1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0];
mcnemar(target, baseline);
// { statistic: 0, pValue: 0.0625, method: 'mid-p' }
pairedTable(target, baseline);
// [[5, 4], [0, 3]]
mcnemarExact([
[5, 4],
[0, 3],
]);
// { statistic: 0, pValue: 0.125, method: 'exact' }
mcnemar(
[
[5, 4],
[0, 3],
],
{ method: 'asymptotic' },
);
// { statistic: 2.25, pValue: 0.13361440253771584, method: 'asymptotic' }
// Categorical labels: one-vs-rest McNemar per class, in order of first appearance.
mcnemarStratified(
['cat', 'dog', 'dog', 'bird', 'cat', 'cat'],
['cat', 'cat', 'dog', 'bird', 'dog', 'bird'],
);
// [
// { label: 'cat', statistic: 1, pValue: 0.625, method: 'mid-p' },
// { label: 'dog', statistic: 1, pValue: 1, method: 'mid-p' },
// { label: 'bird', statistic: 0, pValue: 0.5, method: 'mid-p' },
// ]
| 选项 | 数值 | 默认 | 页:1 |
|---|---|---|---|
method | 'mid-p', (中文(简体) ), 'exact', (中文(简体) ), 'asymptotic' | 'mid-p' | 精确条件测试的中p变体(Fagerland, Lydersen & Laake, 2013),精确条件测试,或chi-平方相近. |
correction | boolean | true | 不对称统计持续更正1. |
'exact' 财务报告和审定财务报表 'asymptotic' 镜像
statsmodels.stats.contingency_tables.mcnemar。 。 。 .
statistic 实值 min(b, c) 页:1 'mid-p' 财务报告和审定财务报表 'exact',和chi
'asymptotic'· ; method 报告所使用的变体。 无相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相相
统计 0和p-值 1(统计模型的不对称变体在那里没有定义). mcnemarExact 财务报告和审定财务报表
mcnemarMidP 强制一个变体. mcnemarStratified 使用对齐的绝对标签并运行
在一vs-rest设置中,每类测试相同;其p-值不作多相比较调整.
费舍尔的测试
2x2表的独立性精确测试,按列(如成功)给出为行(如组) /
失败)。 镜像
scipy.stats.fisher_exact, (中文(简体) ),
包括它的双面p-值(表格的总概率最多与观察到的概率相同).
import { fisherExact } from '@elastic/statistics';
fisherExact([
[8, 2],
[1, 5],
]);
// { statistic: 20, pValue: 0.03496503496503496 }
fisherExact(
[
[8, 2],
[1, 5],
],
{ alternative: 'greater' },
);
// { statistic: 20, pValue: 0.024475524475524472 }
statistic 样本概率比 (a * d) / (b * c) 页:1 [[a, b], [c, d]]数字 : Infinity
何时 b 或者说 c 为零, null 当一行或一列为空时(p值为 1). 职能
抛出不是2x2的表格,或持有负数或非整数.
千平天下的独立考验
皮尔逊对一个RxC表的基平测试作为行给出. 镜像
scipy.stats.chi2_contingency· ;
p值与浮点精度相匹配.
import { chiSquared } from '@elastic/statistics';
chiSquared([
[10, 10, 20],
[20, 20, 20],
]);
// { statistic: 2.7777777777777777, pValue: 0.2493522087772962, dof: 2,
// expected: [[12, 12, 16], [18, 18, 24]], minimumExpected: 12 }
// Yates' continuity correction is applied to 2x2 tables unless disabled.
chiSquared([
[12, 3],
[17, 16],
]).pValue; // 0.12063113097759684
chiSquared(
[
[12, 3],
[17, 16],
],
{ correction: false },
).pValue; // 0.061412253987091166
statistic 财务报告和审定财务报表 pValue 为: null 当一行或一列的预期数为零时(小数上升)
(d) 将第1款改为第1款; dof, (中文(简体) ), expected 财务报告和审定财务报表 minimumExpected 总是被报告。 大约是
通常认为适当 minimumExpected 至少为 5; 使用 fisherExact 2x2 个表格
ê娩 该函数用于空或挂起的表格和负数.
Shapiro- Wilk 常态测试
测试样本,一般是配对差异是否正常分布. 镜像
scipy.stats.shapiro。 。 。 .
import { shapiroWilk } from '@elastic/statistics';
shapiroWilk([0.12, -0.05, 0.08, 0.02, -0.11, 0.07, 0.01, 0.15, -0.03, 0.04]);
// { statistic: 0.9875422022224214, pValue: 0.992829252967651 }
shapiroWilk([0.01, 0.02, 0.02, 0.03, 0.05, 0.09, 0.2, 0.4, 0.9, 2.5]);
// { statistic: 0.6044891945571944, pValue: 0.00006255986205030777 }
statistic 是 W, 单位 (0, 1];1附近的值与常态一致。 测试至少需要
3 个值, 和 scipy 一样, 给出任何大小的精确 W , 但大约 5 000 以上的 p 值
数值。 两个领域都是 null 不到三个数值, NaN 在样本中,或恒定样本。 W 统计匹配为
浮点精度; p 值通过 log(1 - W) 并匹配到大约 1e- 10 相对
w非常接近1时精确.
脚本
npm ci
npm run build
npm test
npm run lint
汇兑政策
此软件包随后 语义版本数字 :
- 补丁 ——错误修正,不会改变公共 API
- 次要 - 新功能或不可破损的添加
- 少校 ——打破导出类型或函数签名的更改
直至 1.0.0,则 0.x 系列可能引入小版本的分解更改.
许可证
弹性许可证2.0. 在公布一揽子计划时,可重新讨论这个问题.