Skip to content

Commit f75c373

Browse files
fixed extreme value handling in t test
1 parent a4d3a5f commit f75c373

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

diffxpy/pkg_constants.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
DE_TREAT_ZEROVAR_TT_AS_SIG = True
2-
31
BATCHGLM_OPTIM_GD = False
42
BATCHGLM_OPTIM_ADAM = False
53
BATCHGLM_OPTIM_ADAGRAD = False

diffxpy/testing/det.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,10 @@ def __init__(
15611561
np.logical_and(mean_x0 == mean_x1, self._mean > 0),
15621562
np.logical_not(self._var_geq_zero)
15631563
))[0]] = 1.0
1564+
# Depening on user choice via is_sig_zerovar:
1565+
# Set p-value to 0 if LFC was non-zero and variances are zero,
1566+
# this causes division by zero in the test statistic. This
1567+
# is a highly significant result if one believes the variance estimate.
15641568
if is_sig_zerovar:
15651569
pval[np.where(np.logical_and(
15661570
mean_x0 != mean_x1,
@@ -1573,28 +1577,6 @@ def __init__(
15731577
self._logfc = mean_x1 - mean_x0
15741578
else:
15751579
self._logfc = np.log(mean_x1) - np.log(mean_x0)
1576-
# Return 0 if LFC was non-zero and variances are zero,
1577-
# this causes division by zero in the test statistic. This
1578-
# is a highly significant result if one believes the variance estimate.
1579-
# This is the default which can be changed and can be changed
1580-
# via DIFFXPY_TREAT_ZEROVAR_TT_AS_SIG.
1581-
pval[np.where(np.logical_and(np.logical_and(
1582-
np.logical_not(self._var_geq_zero),
1583-
self._ave_nonzero),
1584-
np.abs(self._logfc) < np.nextafter(0, 1)
1585-
))] = 0
1586-
if pkg_constants.DE_TREAT_ZEROVAR_TT_AS_SIG:
1587-
pval[np.where(np.logical_and(np.logical_and(
1588-
np.logical_not(self._var_geq_zero),
1589-
self._ave_nonzero),
1590-
np.abs(self._logfc) >= np.nextafter(0, 1)
1591-
))] = 1
1592-
else:
1593-
pval[np.where(np.logical_and(np.logical_and(
1594-
np.logical_not(self._var_geq_zero),
1595-
self._ave_nonzero),
1596-
np.abs(self._logfc) >= np.nextafter(0, 1)
1597-
))] = 0
15981580

15991581
@property
16001582
def gene_ids(self) -> np.ndarray:
@@ -1695,6 +1677,10 @@ def __init__(
16951677
np.logical_and(mean_x0 == mean_x1, self._mean > 0),
16961678
np.logical_not(self._var_geq_zero)
16971679
))[0]] = 1.0
1680+
# Depening on user choice via is_sig_zerovar:
1681+
# Set p-value to 0 if LFC was non-zero and variances are zero,
1682+
# this causes division by zero in the test statistic. This
1683+
# is a highly significant result if one believes the variance estimate.
16981684
if is_sig_zerovar:
16991685
pval[np.where(np.logical_and(
17001686
mean_x0 != mean_x1,

diffxpy/unit_test/test_extreme_values.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def test_t_test_zero_variance(self):
1919
logging.getLogger("diffxpy").setLevel(logging.WARNING)
2020

2121
np.random.seed(1)
22-
de.pkg_constants.DE_TREAT_ZEROVAR_TT_AS_SIG = True
2322
sim = Simulator(num_observations=1000, num_features=10)
2423
sim.generate_sample_description(num_batches=0, num_conditions=0)
2524
sim.generate()
@@ -51,7 +50,6 @@ def test_rank_test_zero_variance(self):
5150
logging.getLogger("diffxpy").setLevel(logging.WARNING)
5251

5352
np.random.seed(1)
54-
de.pkg_constants.DE_TREAT_ZEROVAR_TT_AS_SIG = True
5553
sim = Simulator(num_observations=1000, num_features=10)
5654
sim.generate_sample_description(num_batches=0, num_conditions=0)
5755
sim.generate()

0 commit comments

Comments
 (0)