ecotyper.rcompat.stats¶
R base/stats numerics reproduced to the last bit where practical.
R accumulates sum/mean/colMeans in long double; on Apple
silicon (the reference platform) that is the same as double so a plain
sequential loop reproduces R exactly. cov/cor/var follow
src/library/stats/src/cov.c (two-pass means, FMA-contracted cross
products as compiled by clang on arm64).
Functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Per-row average ranks and tie sums of |
|
|
|
|
|
p-values of |
|
|
|
|
|
|
|
|
Exceptions
Raised where R's t.test() stops (caught by EcoTyper's tryCatch). |
- ecotyper.rcompat.stats.row_means(X)[source]¶
rowMeans(X)(column-by-column accumulation; same per-row order).- Return type:
- ecotyper.rcompat.stats.cor_matrix(X)[source]¶
cor(X): Pearson correlation between the columns ofX.- Return type:
- ecotyper.rcompat.stats.cor_vectors(x, y)[source]¶
cor(x, y)for two numeric vectors (cov_na_2 path).- Return type:
- ecotyper.rcompat.stats.fast_cor(X)[source]¶
HiClimR::fastCor(X): correlation between the columns ofXviacrossprodof centred, unit-norm columns (BLAS; ULP-level differences).- Return type:
- ecotyper.rcompat.stats.log2p1(X)[source]¶
log2(X + 1)with libm’s log2 (as R calls it), not numpy’s SIMD log2.- Return type:
- ecotyper.rcompat.stats.col_normalize(X, na_rm=False)[source]¶
apply(X, 2, function(x) x / sum(x[, na.rm = TRUE])).
- ecotyper.rcompat.stats.which_max(x)[source]¶
which.max(x)→ 0-based index of the first maximum ignoring NaN; -1 if none.- Return type:
- ecotyper.rcompat.stats.quantile7(x, probs, na_rm=False)[source]¶
quantile(x, probs, type = 7, names = FALSE).- Parameters:
na_rm (bool)
- ecotyper.rcompat.stats.r_median(x)[source]¶
median(x)(mean(sort(x, partial = half + 0:1)[half + 0:1])).- Return type:
- ecotyper.rcompat.stats.rank_average(x)[source]¶
rank(x, ties.method = "average")(no NAs).- Return type:
- ecotyper.rcompat.stats.p_adjust_bh(p)[source]¶
p.adjust(p, "BH")(NAs kept; n = number of non-NA p-values).- Return type:
- ecotyper.rcompat.stats.pnorm(x, lower_tail=True)[source]¶
pnorm(x, lower.tail)(standard normal, R’s algorithm).- Parameters:
lower_tail (bool)
- ecotyper.rcompat.stats.pt(t, df, lower_tail=True)[source]¶
pt(t, df)following R’s formulation (pbeta via scipy).
- exception ecotyper.rcompat.stats.TTestError[source]¶
Bases:
ValueErrorRaised where R’s t.test() stops (caught by EcoTyper’s tryCatch).
- ecotyper.rcompat.stats.welch_t_test_p(x, y)[source]¶
t.test(x, y)$p.value(Welch, two-sided); raises TTestError where R errors.- Return type:
- ecotyper.rcompat.stats.phyper_upper(q, m, n, k)[source]¶
1 - phyper(q, m, n, k)as computed by EcoTyper.
- ecotyper.rcompat.stats.row_ranks(X)[source]¶
Per-row average ranks and tie sums of
Xforrow_wilcoxon_from_ranks().- Parameters:
X (ndarray)
- ecotyper.rcompat.stats.row_wilcoxon_from_ranks(ranks, ties, in_x, correct=True)[source]¶
row_wilcoxon_twosample(X[:, in_x], X[:, ~in_x])fromrow_ranks()ofX: identical results (the ranks of a row do not depend on how its columns are split, and the rank sum runs over the x columns in their original order), without re-rankingXfor every split.
- ecotyper.rcompat.stats.row_wilcoxon_twosample(x, y, correct=True)[source]¶
p-values of
matrixTests::row_wilcoxon_twosample(x, y)(two-sided).Exact p-values (
pwilcox) are used when both groups have < 50 observations and the row has no ties, as in matrixTests; otherwise the normal approximation with continuity and tie correction.